2 * Copyright(C) NXP Semiconductors, 2012
\r
3 * All rights reserved.
\r
5 * Software that is described herein is for illustrative purposes only
\r
6 * which provides customers with programming information regarding the
\r
7 * LPC products. This software is supplied "AS IS" without any warranties of
\r
8 * any kind, and NXP Semiconductors and its licensor disclaim any and
\r
9 * all warranties, express or implied, including all implied warranties of
\r
10 * merchantability, fitness for a particular purpose and non-infringement of
\r
11 * intellectual property rights. NXP Semiconductors assumes no responsibility
\r
12 * or liability for the use of the software, conveys no license or rights under any
\r
13 * patent, copyright, mask work right, or any other intellectual property rights in
\r
14 * or to any products. NXP Semiconductors reserves the right to make changes
\r
15 * in the software without notification. NXP Semiconductors also makes no
\r
16 * representation or warranty that such application will be suitable for the
\r
17 * specified use without further testing or modification.
\r
19 * Permission to use, copy, modify, and distribute this software and its
\r
20 * documentation is hereby granted, under NXP Semiconductors' and its
\r
21 * licensor's relevant copyrights in the software, without fee, provided that it
\r
22 * is used in conjunction with NXP Semiconductors microcontrollers. This
\r
23 * copyright, permission, and disclaimer notice must appear in all copies of
\r
29 /** @defgroup BOARD_NGX_XPLORER_18304330_SYSINIT LPC1830 and LPC4330 NGX Xplorer board System Init code
\r
30 * @ingroup BOARD_NGX_XPLORER_18304330
\r
31 * The System initialization code is called prior to the application and
\r
32 * initializes the board for run-time operation. Board initialization
\r
33 * for the NGX Xplorer boards includes clock setup and default pin muxing
\r
36 * With the exception of stack space, no RW memory is used for this call.
\r
38 * LPC1830 and LPC4330 NGX Xplorer setup<BR>
\r
40 * All base clocks enabled by default (Save power by disabling un-needed clocks)<BR>
\r
41 * CPU PLL set to maximum clock frequency (as defined by MAX_CLOCK_FREQ value)<BR>
\r
42 * SPIFI FLASH clock setup for fastest speed<BR>
\r
43 * CGU Dividers A, C, D and E are used for the LCD, USB, and SPIFI.
\r
45 * Sets up various pin mux functions for the board (Ethernet, LEDs, etc.)<BR>
\r
47 * There is no memory setup for this board.
\r
52 /* SCR pin definitions for pin muxing */
\r
54 uint8_t pingrp; /* Pin group */
\r
55 uint8_t pinnum; /* Pin number */
\r
56 uint16_t modefunc; /* Pin mode and function for SCU */
\r
59 /* Structure for initial base clock states */
\r
60 struct CLK_BASE_STATES {
\r
61 CHIP_CGU_BASE_CLK_T clk; /* Base clock */
\r
62 CHIP_CGU_CLKIN_T clkin; /* Base clock source, see UM for allowable souorces per base clock */
\r
63 bool autoblock_enab;/* Set to true to enable autoblocking on frequency change */
\r
64 bool powerdn; /* Set to true if the base clock is initially powered down */
\r
67 /* Initial base clock states are mostly on */
\r
68 STATIC const struct CLK_BASE_STATES InitClkStates[] = {
\r
69 {CLK_BASE_SAFE, CLKIN_IRC, true, false},
\r
70 {CLK_BASE_APB1, CLKIN_MAINPLL, true, false},
\r
71 {CLK_BASE_APB3, CLKIN_MAINPLL, true, false},
\r
72 {CLK_BASE_USB0, CLKIN_USBPLL, true, true},
\r
73 #if defined(CHIP_LPC43XX)
\r
74 {CLK_BASE_PERIPH, CLKIN_MAINPLL, true, false},
\r
75 {CLK_BASE_SPI, CLKIN_MAINPLL, true, false},
\r
76 {CLK_BASE_VADC, CLKIN_MAINPLL, true, true},
\r
78 {CLK_BASE_PHY_TX, CLKIN_ENET_TX, true, false},
\r
79 #if defined(USE_RMII)
\r
80 {CLK_BASE_PHY_RX, CLKIN_ENET_TX, true, false},
\r
82 {CLK_BASE_PHY_RX, CLKIN_ENET_RX, true, false},
\r
84 {CLK_BASE_SDIO, CLKIN_MAINPLL, true, false},
\r
85 {CLK_BASE_SSP0, CLKIN_MAINPLL, true, false},
\r
86 {CLK_BASE_SSP1, CLKIN_MAINPLL, true, false},
\r
87 {CLK_BASE_UART0, CLKIN_MAINPLL, true, false},
\r
88 {CLK_BASE_UART1, CLKIN_MAINPLL, true, false},
\r
89 {CLK_BASE_UART2, CLKIN_MAINPLL, true, false},
\r
90 {CLK_BASE_UART3, CLKIN_MAINPLL, true, false},
\r
91 {CLK_BASE_OUT, CLKINPUT_PD, true, false},
\r
92 {CLK_BASE_APLL, CLKINPUT_PD, true, false},
\r
93 {CLK_BASE_CGU_OUT0, CLKINPUT_PD, true, false},
\r
94 {CLK_BASE_CGU_OUT1, CLKINPUT_PD, true, false},
\r
96 /* Clocks derived from dividers */
\r
97 {CLK_BASE_LCD, CLKIN_IDIVC, true, false},
\r
98 {CLK_BASE_USB1, CLKIN_IDIVD, true, true}
\r
101 /* SPIFI high speed pin mode setup */
\r
102 STATIC const PINMUX_GRP_T spifipinmuxing[] = {
\r
103 {0x3, 3, (SCU_PINIO_FAST | SCU_MODE_FUNC3)}, /* SPIFI CLK */
\r
104 {0x3, 4, (SCU_PINIO_FAST | SCU_MODE_FUNC3)}, /* SPIFI D3 */
\r
105 {0x3, 5, (SCU_PINIO_FAST | SCU_MODE_FUNC3)}, /* SPIFI D2 */
\r
106 {0x3, 6, (SCU_PINIO_FAST | SCU_MODE_FUNC3)}, /* SPIFI D1 */
\r
107 {0x3, 7, (SCU_PINIO_FAST | SCU_MODE_FUNC3)}, /* SPIFI D0 */
\r
108 {0x3, 8, (SCU_PINIO_FAST | SCU_MODE_FUNC3)} /* SPIFI CS/SSEL */
\r
111 /* USB PLL pre-initialized setup values for 480MHz output rate */
\r
112 static const CGU_USBAUDIO_PLL_SETUP_T usbPLLSetup = {
\r
113 0x0000601D, /* Default control with main osc input, PLL disabled */
\r
114 0x06167FFA, /* M-divider value for 480MHz output from 12MHz input */
\r
115 0x00000000, /* N-divider value */
\r
116 0x00000000 /* Not applicable for USB PLL */
\r
119 /* Audio PLL pre-initialized setup values for FIXME output rate */
\r
120 // static const CGU_USBAUDIO_PLL_SETUP_T audioPLLSetup = {
\r
121 // 0x0000601D, /* Default control with main osc input, PLL disabled */
\r
122 // 0x06167FFA, /* M-divider value for FIXME output from 12MHz input */
\r
123 // 0x00000000, /* N-divider value */
\r
124 // 0x00000000 /* FIXME */
\r
127 /* Setup system clocking */
\r
128 STATIC void SystemSetupClocking(void)
\r
132 /* Switch main system clocking to crystal */
\r
133 Chip_Clock_EnableCrystal();
\r
134 Chip_Clock_SetBaseClock(CLK_BASE_MX, CLKIN_CRYSTAL, true, false);
\r
136 /* Setup PLL for 100MHz and switch main system clocking */
\r
137 Chip_Clock_SetupMainPLLHz(CLKIN_CRYSTAL, CRYSTAL_MAIN_FREQ_IN, 100 * 1000000, 100 * 1000000);
\r
138 Chip_Clock_SetBaseClock(CLK_BASE_MX, CLKIN_MAINPLL, true, false);
\r
140 /* Setup PLL for maximum clock */
\r
141 Chip_Clock_SetupMainPLLHz(CLKIN_CRYSTAL, CRYSTAL_MAIN_FREQ_IN, MAX_CLOCK_FREQ, MAX_CLOCK_FREQ);
\r
143 /* Setup system base clocks and initial states. This won't enable and
\r
144 disable individual clocks, but sets up the base clock sources for
\r
145 each individual peripheral clock. */
\r
146 for (i = 0; i < (sizeof(InitClkStates) / sizeof(InitClkStates[0])); i++) {
\r
147 Chip_Clock_SetBaseClock(InitClkStates[i].clk, InitClkStates[i].clkin,
\r
148 InitClkStates[i].autoblock_enab, InitClkStates[i].powerdn);
\r
151 /* Reset and enable 32Khz oscillator */
\r
152 LPC_CREG->CREG0 &= ~((1 << 3) | (1 << 2));
\r
153 LPC_CREG->CREG0 |= (1 << 1) | (1 << 0);
\r
155 /* SPIFI pin setup is done prior to setting up system clocking */
\r
156 for (i = 0; i < (sizeof(spifipinmuxing) / sizeof(spifipinmuxing[0])); i++) {
\r
157 Chip_SCU_PinMuxSet(spifipinmuxing[i].pingrp, spifipinmuxing[i].pinnum,
\r
158 spifipinmuxing[i].modefunc);
\r
161 /* Setup a divider E for main PLL clock switch SPIFI clock to that divider.
\r
162 Divide rate is based on CPU speed and speed of SPI FLASH part. */
\r
163 #if (MAX_CLOCK_FREQ > 180000000)
\r
164 Chip_Clock_SetDivider(CLK_IDIV_E, CLKIN_MAINPLL, 5);
\r
166 Chip_Clock_SetDivider(CLK_IDIV_E, CLKIN_MAINPLL, 4);
\r
168 Chip_Clock_SetBaseClock(CLK_BASE_SPIFI, CLKIN_IDIVE, true, false);
\r
170 /* Attach main PLL clock to divider C with a divider of 2 */
\r
171 Chip_Clock_SetDivider(CLK_IDIV_C, CLKIN_MAINPLL, 2);
\r
173 /* Setup default USB PLL state for a 480MHz output and attach */
\r
174 Chip_Clock_SetupPLL(CLKIN_CRYSTAL, CGU_USB_PLL, &usbPLLSetup);
\r
176 /* USB1 needs a 60MHz clock. To get it, a divider of 4 and then 2 are
\r
177 chained to make a divide by 8 function. Connect the output of
\r
178 divider D to the USB1 base clock. */
\r
179 Chip_Clock_SetDivider(CLK_IDIV_A, CLKIN_USBPLL, 4);
\r
180 Chip_Clock_SetDivider(CLK_IDIV_D, CLKIN_IDIVA, 2);
\r
181 Chip_Clock_SetBaseClock(CLK_BASE_USB1, CLKIN_IDIVD, true, true);
\r
183 /* Setup default audio PLL state for a FIXME output */
\r
184 // Chip_Clock_SetupPLL(CGU_AUDIO_PLL, &audioPLLSetup); // FIXME
\r
187 STATIC const PINMUX_GRP_T pinmuxing[] = {
\r
188 /* RMII pin group */
\r
190 (SCU_MODE_HIGHSPEEDSLEW_EN | SCU_MODE_MODE_PULLUP | SCU_MODE_INBUFF_EN | SCU_MODE_ZIF_DIS | SCU_MODE_FUNC3)},
\r
192 (SCU_MODE_HIGHSPEEDSLEW_EN | SCU_MODE_MODE_PULLUP | SCU_MODE_INBUFF_EN | SCU_MODE_ZIF_DIS | SCU_MODE_FUNC2)},
\r
194 (SCU_MODE_HIGHSPEEDSLEW_EN | SCU_MODE_MODE_PULLUP | SCU_MODE_INBUFF_EN | SCU_MODE_ZIF_DIS | SCU_MODE_FUNC7)},
\r
195 {0x0, 1, (SCU_MODE_HIGHSPEEDSLEW_EN | SCU_MODE_MODE_PULLUP | SCU_MODE_ZIF_DIS | SCU_MODE_FUNC6)},
\r
197 (SCU_MODE_HIGHSPEEDSLEW_EN | SCU_MODE_MODE_PULLUP | SCU_MODE_INBUFF_EN | SCU_MODE_ZIF_DIS | SCU_MODE_FUNC0)},
\r
198 {0x1, 18, (SCU_MODE_HIGHSPEEDSLEW_EN | SCU_MODE_MODE_PULLUP | SCU_MODE_ZIF_DIS | SCU_MODE_FUNC3)},
\r
199 {0x1, 20, (SCU_MODE_HIGHSPEEDSLEW_EN | SCU_MODE_MODE_PULLUP | SCU_MODE_ZIF_DIS | SCU_MODE_FUNC3)},
\r
201 (SCU_MODE_HIGHSPEEDSLEW_EN | SCU_MODE_MODE_PULLUP | SCU_MODE_INBUFF_EN | SCU_MODE_ZIF_DIS | SCU_MODE_FUNC3)},
\r
202 {0x2, 0, (SCU_MODE_HIGHSPEEDSLEW_EN | SCU_MODE_MODE_PULLUP | SCU_MODE_ZIF_DIS | SCU_MODE_FUNC7)},
\r
204 {0x2, 11, (SCU_MODE_MODE_REPEATER | SCU_MODE_FUNC0)},
\r
205 {0x2, 12, (SCU_MODE_MODE_REPEATER | SCU_MODE_FUNC0)},
\r
207 {0x3, 0, (SCU_PINIO_FAST | SCU_MODE_FUNC2)},
\r
208 {0x6, 0, (SCU_PINIO_FAST | SCU_MODE_FUNC4)},
\r
209 {0x7, 2, (SCU_PINIO_FAST | SCU_MODE_FUNC2)},
\r
210 {0x6, 2, (SCU_PINIO_FAST | SCU_MODE_FUNC3)},
\r
211 {0x7, 1, (SCU_PINIO_FAST | SCU_MODE_FUNC2)},
\r
212 {0x6, 1, (SCU_PINIO_FAST | SCU_MODE_FUNC3)},
\r
215 /* Sets up system pin muxing */
\r
216 STATIC void SystemSetupMuxing(void)
\r
220 /* Setup system level pin muxing */
\r
221 for (i = 0; i < (sizeof(pinmuxing) / sizeof(pinmuxing[0])); i++) {
\r
222 Chip_SCU_PinMuxSet(pinmuxing[i].pingrp, pinmuxing[i].pinnum,
\r
223 pinmuxing[i].modefunc);
\r
227 /* Nothing to do for the Xplorer board */
\r
228 STATIC void SystemSetupMemory(void)
\r
234 * @brief Setup the system
\r
236 * SystemInit() is called prior to the application and sets up system
\r
237 * clocking, memory, and any resources needed prior to the application
\r
240 void SystemInit(void)
\r
242 #if defined(CORE_M3) || defined(CORE_M4)
\r
243 unsigned int *pSCB_VTOR = (unsigned int *) 0xE000ED08;
\r
245 #if defined(__IAR_SYSTEMS_ICC__)
\r
246 extern void *__vector_table;
\r
248 *pSCB_VTOR = (unsigned int) &__vector_table;
\r
249 #elif defined(__CODE_RED)
\r
250 extern void *g_pfnVectors;
\r
252 *pSCB_VTOR = (unsigned int) &g_pfnVectors;
\r
253 #elif defined(__ARMCC_VERSION)
\r
254 extern void *__Vectors;
\r
256 *pSCB_VTOR = (unsigned int) &__Vectors;
\r
259 #if defined(__FPU_PRESENT) && __FPU_PRESENT == 1
\r
263 /* Setup system clocking and memory. This is done early to allow the
\r
264 application and tools to clear memory and use scatter loading to
\r
265 external memory. */
\r
266 SystemSetupClocking();
\r
267 SystemSetupMuxing();
\r
268 SystemSetupMemory();
\r