| LPCOpen Platform v1.03 LPCOpen Platform for NXP LPC Microcontrollers

- Main Page
- Modules
- Data Structures
- Files
- Related Pages

- File List
- Globals

All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
sysinit_nxp_xpresso_11c24.c
Go to the documentation of this file.
1 /*
2 * @brief NXP XPRESSO 11C24 Sysinit file
3 *
4 * @note
5 * Copyright(C) NXP Semiconductors, 2012
6 * All rights reserved.
7 *
8 * @par
9 * Software that is described herein is for illustrative purposes only
10 * which provides customers with programming information regarding the
11 * LPC products. This software is supplied "AS IS" without any warranties of
12 * any kind, and NXP Semiconductors and its licensor disclaim any and
13 * all warranties, express or implied, including all implied warranties of
14 * merchantability, fitness for a particular purpose and non-infringement of
15 * intellectual property rights. NXP Semiconductors assumes no responsibility
16 * or liability for the use of the software, conveys no license or rights under any
17 * patent, copyright, mask work right, or any other intellectual property rights in
18 * or to any products. NXP Semiconductors reserves the right to make changes
19 * in the software without notification. NXP Semiconductors also makes no
20 * representation or warranty that such application will be suitable for the
21 * specified use without further testing or modification.
22 *
23 * @par
24 * Permission to use, copy, modify, and distribute this software and its
25 * documentation is hereby granted, under NXP Semiconductors' and its
26 * licensor's relevant copyrights in the software, without fee, provided that it
27 * is used in conjunction with NXP Semiconductors microcontrollers. This
28 * copyright, permission, and disclaimer notice must appear in all copies of
29 * this code.
30 */
31
32 #include "board.h"
33 #include "string.h"
34
50 /*****************************************************************************
51 * Private types/enumerations/variables
52 ****************************************************************************/
53
54 /* IOCON pin definitions for pin muxing */
55 typedef struct {
56 uint32_t pin:8; /* Pin number */
57 uint32_t modefunc:24; /* Function and mode */
58 } PINMUX_GRP_T;
59
60 /*****************************************************************************
61 * Public types/enumerations/variables
62 ****************************************************************************/
63
64 /* Pin muxing table, only items that need changing from their default pin
65 state are in this table. */
66 STATIC const PINMUX_GRP_T pinmuxing[] = {
67 {(uint32_t) IOCON_PIO0_1, (IOCON_FUNC1 | IOCON_MODE_INACT)}, /* PIO0_1 used for CLKOUT */
68 {(uint32_t) IOCON_PIO0_2, (IOCON_FUNC1 | IOCON_MODE_INACT)}, /* PIO0_2 used for SSEL */
69 {(uint32_t) IOCON_PIO0_4, (IOCON_FUNC1 | IOCON_SFI2C_EN)}, /* PIO0_4 used for SCL */
70 {(uint32_t) IOCON_PIO0_5, (IOCON_FUNC1 | IOCON_SFI2C_EN)}, /* PIO0_5 used for SDA */
71 {(uint32_t) IOCON_PIO0_8, (IOCON_FUNC1 | IOCON_MODE_INACT)}, /* PIO0_8 used for MISO */
72 {(uint32_t) IOCON_PIO0_9, (IOCON_FUNC1 | IOCON_MODE_INACT)}, /* PIO0_9 used for MOSI */
73 {(uint32_t) IOCON_PIO0_11, (IOCON_FUNC1 | IOCON_ADMODE_EN)}, /* PIO0_11 used for AD0 */
74 {(uint32_t) IOCON_PIO1_6, (IOCON_FUNC1 | IOCON_MODE_INACT)}, /* PIO1_6 used for RXD */
75 {(uint32_t) IOCON_PIO1_7, (IOCON_FUNC1 | IOCON_MODE_INACT)}, /* PIO1_7 used for TXD */
76 {(uint32_t) IOCON_PIO2_11, (IOCON_FUNC1 | IOCON_MODE_INACT)}, /* PIO0_6 used for SCK */
77 };
78
79 /*****************************************************************************
80 * Private functions
81 ****************************************************************************/
82
83 /* Setup system clocking */
84 STATIC void SystemSetupClocking(void)
85 {
86 int i;
87
88 /* Powerup main oscillator */
89 Chip_SYSCTL_PowerUp(SYSCTL_POWERDOWN_SYSOSC_PD);
90
91 /* Wait 200us for OSC to be stablized, no status
92 indication, dummy wait. */
93 for (i = 0; i < 0x100; i++) {}
94
95 /* Set system PLL input to main oscillator */
96 Chip_Clock_SetSystemPllSource(SYSCTL_PLLCLKSRC_MAINOSC);
97
98 /* Powerup system PLL */
99 Chip_SYSCTL_PowerUp(SYSCTL_POWERDOWN_SYSPLL_PD);
100
101 /* Setup PLL for main oscillator rate (FCLKIN = 12MHz) * 4 = 48MHz
102 MSEL = 3 (this is pre-decremented), PSEL = 1 (for P = 2)
103 FCLKOUT = FCLKIN * (MSEL + 1) = 12MHz * 4 = 48MHz
104 FCCO = FCLKOUT * 2 * P = 48MHz * 2 * 2 = 192MHz (within FCCO range) */
105 Chip_Clock_SetupSystemPLL(3, 1);
106
107 /* Wait for PLL to lock */
108 while (!Chip_Clock_IsSystemPLLLocked()) {}
109
110 /* Set system clock divider to 1 */
111 Chip_Clock_SetSysClockDiv(1);
112
113 /* Setup FLASH access to 3 clocks */
114 Chip_FMC_SetFLASHAccess(FLASHTIM_50MHZ_CPU);
115
116 /* Set main clock source to the system PLL. This will drive 48MHz
117 for the main clock and 48MHz for the system clock */
118 Chip_Clock_SetMainClockSource(SYSCTL_MAINCLKSRC_PLLOUT);
119
120 /* Enable IOCON clock */
121 Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_IOCON);
122 }
123
124 /* Sets up system pin muxing */
125 STATIC void SystemSetupMuxing(void)
126 {
127 int i;
128
129 for (i = 0; i < (sizeof(pinmuxing) / sizeof(PINMUX_GRP_T)); i++) {
130 Chip_IOCON_PinMuxSet(LPC_IOCON, (CHIP_IOCON_PIO_T) pinmuxing[i].pin,
131 pinmuxing[i].modefunc);
132 }
133 }
134
135 /*****************************************************************************
136 * Public functions
137 ****************************************************************************/
138
146 void SystemInit(void)
147 {
148 /* Booting from FLASH, so remap vector table to FLASH */
149 Chip_SYSCTL_Map(REMAP_USER_FLASH_MODE);
150
151 /* Setup system clocking and muxing */
152 SystemSetupClocking();
153 SystemSetupMuxing();
154 }