summaryrefslogtreecommitdiff
path: root/nuttx/configs/stm3240g-eval/src/up_boot.c
blob: cd184a3680086e4e5f4040cf5f6a55670c013076 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
/************************************************************************************
 * configs/stm3240g-eval/src/up_boot.c
 *
 *   Copyright (C) 2011-2013 Gregory Nutt. All rights reserved.
 *   Author: Gregory Nutt <gnutt@nuttx.org>
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 * 3. Neither the name NuttX nor the names of its contributors may be
 *    used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 *
 ************************************************************************************/

/************************************************************************************
 * Included Files
 ************************************************************************************/

#include <nuttx/config.h>

#include <debug.h>

#include "stm3240g-internal.h"

/************************************************************************************
 * Pre-processor Definitions
 ************************************************************************************/
/* Configuration ********************************************************************/
/* Should we initialize the NX server?  This is done for NxWidgets (CONFIG_NXWIDGETS=y)
 * if nx_start() is available (CONFIG_NX_NXSTART=y) and if the NxWidget::CNxServer
 * class expects the RTOS to do the NX initialization (CONFIG_NXWIDGET_SERVERINIT=n).
 * This combination of settings is normally only used in the kernel build mode
 * (CONFIG_NUTTX_KERNEL) when NxWidgets is unable to initialize NX from user-space.
 */

#undef HAVE_NXSTART

#if !defined(CONFIG_NX_MULTIUSER)
#  undef CONFIG_NX_START
#endif

#if defined(CONFIG_NXWIDGETS)
#  if defined(CONFIG_NX_NXSTART)
#    if !defined(CONFIG_NXWIDGET_SERVERINIT)
#      define HAVE_NXSTART
#      include <nuttx/nx/nx.h>
#    endif
#  else
#    if !defined(CONFIG_NXWIDGET_SERVERINIT) && defined(CONFIG_NUTTX_KERNEL)
#      error CONFIG_NX_NXSTART=y is needed
#    endif
#  endif
#endif

/* Should we initialize the touchscreen for the NxWM (CONFIG_NXWM=y)?  This
 * is done if we have a touchscreen (CONFIG_INPUT_STMPE811=y), NxWM uses the
 * touchscreen (CONFIG_NXWM_TOUCHSCREEN=y), and if we were asked to
 * initialize the touchscreen for NxWM (NXWM_TOUCHSCREEN_DEVINIT=n). This
 * combination of settings is normally only used in the kernel build mode
 * (CONFIG_NUTTX_KERNEL) when NxWidgets is unable to initialize NX from
 * user-space.
 */

#undef HAVE_TCINIT

#if defined(CONFIG_NXWM_TOUCHSCREEN)
#  if !defined(CONFIG_NXWM_TOUCHSCREEN_DEVNO)
#    error CONFIG_NXWM_TOUCHSCREEN_DEVNO is not defined
#  elif defined(CONFIG_INPUT_STMPE811)
#    if !defined(CONFIG_NXWM_TOUCHSCREEN_DEVINIT)
#      define HAVE_TCINIT
#      include <nuttx/input/touchscreen.h>
#    endif
#  else
#    if !defined(CONFIG_NXWM_TOUCHSCREEN_DEVINIT) && defined(CONFIG_NUTTX_KERNEL)
#      error CONFIG_INPUT_STMPE811=y is needed
#    endif
#  endif
#endif

/* Check if we will need to support the initialization kernel thread */

#undef HAVE_INITTHREAD

#ifdef CONFIG_BOARD_INITIALIZE
#  if defined(CONFIG_NSH_LIBRARY) && !defined(CONFIG_NSH_ARCHINIT)
#    define HAVE_INITTHREAD 1
#  elif defined(HAVE_NXSTART)
#    define HAVE_INITTHREAD 1
#  elif defined(HAVE_TCINIT)
#    define HAVE_INITTHREAD 1
#  endif
#endif

#ifdef HAVE_INITTHREAD
#  include <stdlib.h>
#  include <assert.h>
#  include <nuttx/kthread.h>
#  ifndef CONFIG_STM3240G_BOARDINIT_PRIO
#    define CONFIG_STM3240G_BOARDINIT_PRIO 196
#  endif
#  ifndef CONFIG_STM3240G_BOARDINIT_STACK
#    define CONFIG_STM3240G_BOARDINIT_STACK 2048
#  endif
#endif

/************************************************************************************
 * Private Functions
 ************************************************************************************/

/************************************************************************************
 * Name: board_initthread
 *
 * Description:
 *   Board initialization kernel thread.  This thread exists to support
 *   initialization when CONFIG_BOARD_INITIALIZE is defined.  It is started by
 *   board_initialize() which runs on the IDLE thread.
 *
 *   This function thread exists because some initialization steps may require
 *   waiting for events.  Such waiting is not possible on the IDLE thread.
 *
 * Input Parameters:
 *   Standard task start-up parameters (none of which are used)
 *
 * Returned Value:
 *   Always returns EXIT_SUCCESS.
 *
 ************************************************************************************/

#ifdef HAVE_INITTHREAD
static int board_initthread(int argc, char *argv[])
{
  int ret;

  /* Perform NSH initialization here instead of from the NSH.  This
   * alternative NSH initialization is necessary when NSH is ran in user-space
   * but the initialization function must run in kernel space.
   */

#if defined(CONFIG_NSH_LIBRARY) && !defined(CONFIG_NSH_ARCHINIT)
  ret = nsh_archinitialize();
  if (ret < 0)
    {
      gdbg("ERROR: nsh_archinitialize failed: %d\n", ret);
    }
#endif

  /* Initialize the NX server */

#ifdef HAVE_NXSTART
  ret = nx_start();
  if (ret < 0)
    {
      gdbg("ERROR: nx_start failed: %d\n", ret);
    }
#endif

  /* Initialize the touchscreen */

#ifdef HAVE_TCINIT
  ret = arch_tcinitialize(CONFIG_NXWM_TOUCHSCREEN_DEVNO);
  if (ret < 0)
    {
      gdbg("ERROR: arch_tcinitialize failed: %d\n", ret);
    }
#endif

  return EXIT_SUCCESS;
}
#endif

/************************************************************************************
 * Public Functions
 ************************************************************************************/

/************************************************************************************
 * Name: stm32_boardinitialize
 *
 * Description:
 *   All STM32 architectures must provide the following entry point.  This entry point
 *   is called early in the initialization -- after all memory has been configured
 *   and mapped but before any devices have been initialized.
 *
 ************************************************************************************/

void stm32_boardinitialize(void)
{
  /* Configure SPI chip selects if 1) SPI is not disabled, and 2) the weak function
   * stm32_spiinitialize() has been brought into the link.
   */

#if defined(CONFIG_STM32_SPI1) || defined(CONFIG_STM32_SPI2) || defined(CONFIG_STM32_SPI3)
  if (stm32_spiinitialize)
    {
      stm32_spiinitialize();
    }
#endif

  /* If the FSMC is enabled, then enable SRAM access */

#ifdef CONFIG_STM32_FSMC
  stm32_selectsram();
#endif

  /* Initialize USB if the 1) OTG FS controller is in the configuration and 2)
   * disabled, and 3) the weak function stm32_usbinitialize() has been brought
   * the weak function stm32_usbinitialize() has been brought into the build.
   * Presumeably either CONFIG_USBDEV or CONFIG_USBHOST is also selected.
   */

#ifdef CONFIG_STM32_OTGFS
  if (stm32_usbinitialize)
    {
      stm32_usbinitialize();
    }
#endif

  /* Configure on-board LEDs if LED support has been selected. */

#ifdef CONFIG_ARCH_LEDS
  board_led_initialize();
#endif
}

/****************************************************************************
 * Name: board_initialize
 *
 * Description:
 *   If CONFIG_BOARD_INITIALIZE is selected, then an additional
 *   initialization call will be performed in the boot-up sequence to a
 *   function called board_initialize().  board_initialize() will be
 *   called immediately after up_intiialize() is called and just before the
 *   initial application is started.  This additional initialization phase
 *   may be used, for example, to initialize board-specific device drivers.
 *
 ****************************************************************************/

#ifdef CONFIG_BOARD_INITIALIZE
void board_initialize(void)
{
#ifdef HAVE_INITTHREAD
  pid_t server;

  /* Start the board initialization kernel thread */

  server = KERNEL_THREAD("Board Init", CONFIG_STM3240G_BOARDINIT_PRIO,
                         CONFIG_STM3240G_BOARDINIT_STACK, board_initthread,
                         NULL);
  ASSERT(server > 0);
#endif
}
#endif