1 /*
2 * Copyright 2017-2021 NXP
3 * All rights reserved.
4 *
5 * SPDX-License-Identifier: BSD-3-Clause
6 */
7
8 /***********************************************************************************************************************
9 * This file was generated by the MCUXpresso Config Tools. Any manual edits made to this file
10 * will be overwritten if the respective MCUXpresso Config Tools is used to update this file.
11 **********************************************************************************************************************/
12 /*
13 * How to set up clock using clock driver functions:
14 *
15 * 1. Setup clock sources.
16 *
17 * 2. Set up wait states of the flash.
18 *
19 * 3. Set up all dividers.
20 *
21 * 4. Set up all selectors to provide selected clocks.
22 */
23
24 /* clang-format off */
25 /* TEXT BELOW IS USED AS SETTING FOR TOOLS *************************************
26 !!GlobalInfo
27 product: Clocks v8.0
28 processor: LPC55S36
29 package_id: LPC55S36JBD100
30 mcu_data: ksdk2_0
31 processor_version: 0.10.0
32 board: LPCXpresso55S36
33 * BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR TOOLS **********/
34 /* clang-format on */
35
36 #include "fsl_power.h"
37 #include "fsl_clock.h"
38 #include "clock_config.h"
39
40 /*******************************************************************************
41 * Definitions
42 ******************************************************************************/
43
44 /*******************************************************************************
45 * Variables
46 ******************************************************************************/
47 /* System clock frequency. */
48 extern uint32_t SystemCoreClock;
49
50 /*******************************************************************************
51 ************************ BOARD_InitBootClocks function ************************
52 ******************************************************************************/
BOARD_InitBootClocks(void)53 void BOARD_InitBootClocks(void)
54 {
55 BOARD_BootClockPLL150M();
56 }
57
58 /*******************************************************************************
59 ******************** Configuration BOARD_BootClockFRO12M **********************
60 ******************************************************************************/
61 /* clang-format off */
62 /* TEXT BELOW IS USED AS SETTING FOR TOOLS *************************************
63 !!Configuration
64 name: BOARD_BootClockFRO12M
65 outputs:
66 - {id: FRO_12MHz_clock.outFreq, value: 12 MHz}
67 - {id: System_clock.outFreq, value: 12 MHz}
68 * BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR TOOLS **********/
69 /* clang-format on */
70
71 /*******************************************************************************
72 * Variables for BOARD_BootClockFRO12M configuration
73 ******************************************************************************/
74 /*******************************************************************************
75 * Code for BOARD_BootClockFRO12M configuration
76 ******************************************************************************/
BOARD_BootClockFRO12M(void)77 void BOARD_BootClockFRO12M(void)
78 {
79 #ifndef SDK_SECONDARY_CORE
80 /*!< Set up the clock sources */
81 /*!< Configure FRO192M */
82 POWER_PowerInit(); /*!< Power Management Controller initialization */
83 POWER_DisablePD(kPDRUNCFG_PD_FRO192M); /*!< Ensure FRO is on */
84 CLOCK_SetupFROClocking(12000000U); /*!< Set up FRO to the 12 MHz, just for sure */
85 CLOCK_AttachClk(kFRO12M_to_MAIN_CLK); /*!< Switch to FRO 12MHz first to ensure we can change the clock setting */
86
87 POWER_SetVoltageForFreq(12000000U); /*!< Set voltage for the one of the fastest clock outputs: System clock output */
88 CLOCK_SetFLASHAccessCyclesForFreq(12000000U); /*!< Set FLASH wait states for core */
89
90 /*!< Set up dividers */
91 CLOCK_SetClkDiv(kCLOCK_DivAhbClk, 1U, false); /*!< Set AHBCLKDIV divider to value 1 */
92
93 /*!< Set up clock selectors - Attach clocks to the peripheries */
94 CLOCK_AttachClk(kFRO12M_to_MAIN_CLK); /*!< Switch MAIN_CLK to FRO12M */
95
96 /*!< Set SystemCoreClock variable. */
97 SystemCoreClock = BOARD_BOOTCLOCKFRO12M_CORE_CLOCK;
98 #endif
99 }
100
101 /*******************************************************************************
102 ******************* Configuration BOARD_BootClockFROHF96M *********************
103 ******************************************************************************/
104 /* clang-format off */
105 /* TEXT BELOW IS USED AS SETTING FOR TOOLS *************************************
106 !!Configuration
107 name: BOARD_BootClockFROHF96M
108 outputs:
109 - {id: FRO_12MHz_clock.outFreq, value: 12 MHz}
110 - {id: System_clock.outFreq, value: 96 MHz}
111 settings:
112 - {id: ANALOG_CONTROL_FRO192M_CTRL_ENDI_FRO_96M_CFG, value: Enable}
113 - {id: SYSCON.MAINCLKSELA.sel, value: ANACTRL.fro_hf_clk}
114 sources:
115 - {id: ANACTRL.fro_hf.outFreq, value: 96 MHz}
116 * BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR TOOLS **********/
117 /* clang-format on */
118
119 /*******************************************************************************
120 * Variables for BOARD_BootClockFROHF96M configuration
121 ******************************************************************************/
122 /*******************************************************************************
123 * Code for BOARD_BootClockFROHF96M configuration
124 ******************************************************************************/
BOARD_BootClockFROHF96M(void)125 void BOARD_BootClockFROHF96M(void)
126 {
127 #ifndef SDK_SECONDARY_CORE
128 /*!< Set up the clock sources */
129 /*!< Configure FRO192M */
130 POWER_PowerInit(); /*!< Power Management Controller initialization */
131 POWER_DisablePD(kPDRUNCFG_PD_FRO192M); /*!< Ensure FRO is on */
132 CLOCK_SetupFROClocking(12000000U); /*!< Set up FRO to the 12 MHz, just for sure */
133 CLOCK_AttachClk(kFRO12M_to_MAIN_CLK); /*!< Switch to FRO 12MHz first to ensure we can change the clock setting */
134
135 CLOCK_SetupFROClocking(96000000U); /* Enable FRO HF(96MHz) output */
136
137 POWER_SetVoltageForFreq(96000000U); /*!< Set voltage for the one of the fastest clock outputs: System clock output */
138 CLOCK_SetFLASHAccessCyclesForFreq(96000000U); /*!< Set FLASH wait states for core */
139
140 /*!< Set up dividers */
141 CLOCK_SetClkDiv(kCLOCK_DivAhbClk, 1U, false); /*!< Set AHBCLKDIV divider to value 1 */
142
143 /*!< Set up clock selectors - Attach clocks to the peripheries */
144 CLOCK_AttachClk(kFRO_HF_to_MAIN_CLK); /*!< Switch MAIN_CLK to FRO_HF */
145
146 /*!< Set SystemCoreClock variable. */
147 SystemCoreClock = BOARD_BOOTCLOCKFROHF96M_CORE_CLOCK;
148 #endif
149 }
150
151 /*******************************************************************************
152 ******************** Configuration BOARD_BootClockPLL100M *********************
153 ******************************************************************************/
154 /* clang-format off */
155 /* TEXT BELOW IS USED AS SETTING FOR TOOLS *************************************
156 !!Configuration
157 name: BOARD_BootClockPLL100M
158 outputs:
159 - {id: FRO_12MHz_clock.outFreq, value: 12 MHz}
160 - {id: System_clock.outFreq, value: 100 MHz}
161 settings:
162 - {id: PLL0_Mode, value: Normal}
163 - {id: ANALOG_CONTROL_FRO192M_CTRL_ENDI_FRO_96M_CFG, value: Enable}
164 - {id: ENABLE_CLKIN_ENA, value: Enabled}
165 - {id: ENABLE_SYSTEM_CLK_OUT, value: Enabled}
166 - {id: SYSCON.MAINCLKSELB.sel, value: SYSCON.PLL0_BYPASS}
167 - {id: SYSCON.PLL0CLKSEL.sel, value: SYSCON.CLK_IN_EN}
168 - {id: SYSCON.PLL0M_MULT.scale, value: '100', locked: true}
169 - {id: SYSCON.PLL0N_DIV.scale, value: '4', locked: true}
170 - {id: SYSCON.PLL0_PDEC.scale, value: '4', locked: true}
171 sources:
172 - {id: ANACTRL.fro_hf.outFreq, value: 96 MHz}
173 - {id: SYSCON.XTAL.outFreq, value: 16 MHz, enabled: true}
174 * BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR TOOLS **********/
175 /* clang-format on */
176
177 /*******************************************************************************
178 * Variables for BOARD_BootClockPLL100M configuration
179 ******************************************************************************/
180 /*******************************************************************************
181 * Code for BOARD_BootClockPLL100M configuration
182 ******************************************************************************/
BOARD_BootClockPLL100M(void)183 void BOARD_BootClockPLL100M(void)
184 {
185 #ifndef SDK_SECONDARY_CORE
186 /*!< Set up the clock sources */
187 /*!< Configure FRO192M */
188 POWER_PowerInit(); /*!< Power Management Controller initialization */
189 POWER_DisablePD(kPDRUNCFG_PD_FRO192M); /*!< Ensure FRO is on */
190 CLOCK_SetupFROClocking(12000000U); /*!< Set up FRO to the 12 MHz, just for sure */
191 CLOCK_AttachClk(kFRO12M_to_MAIN_CLK); /*!< Switch to FRO 12MHz first to ensure we can change the clock setting */
192
193 CLOCK_SetupFROClocking(96000000U); /* Enable FRO HF(96MHz) output */
194
195 CLOCK_SetupExtClocking(16000000U); /* Enable XTALHF clock */
196 ANACTRL->XO32M_CTRL |= ANACTRL_XO32M_CTRL_ENABLE_SYSTEM_CLK_OUT_MASK; /* Enable High speed Crystal oscillator output to system */
197
198 POWER_SetVoltageForFreq(100000000U); /*!< Set voltage for the one of the fastest clock outputs: System clock output */
199 CLOCK_SetFLASHAccessCyclesForFreq(100000000U); /*!< Set FLASH wait states for core */
200
201 /*!< Set up PLL */
202 CLOCK_AttachClk(kEXT_CLK_to_PLL0); /*!< Switch PLL0CLKSEL to EXT_CLK */
203 POWER_DisablePD(kPDRUNCFG_PD_PLL0); /* Ensure PLL is on */
204 POWER_DisablePD(kPDRUNCFG_PD_PLL0_SSCG);
205 const pll_setup_t pll0Setup = {
206 .pllctrl = SYSCON_PLL0CTRL_CLKEN_MASK | SYSCON_PLL0CTRL_SELI(53U) | SYSCON_PLL0CTRL_SELP(26U),
207 .pllndec = SYSCON_PLL0NDEC_NDIV(4U),
208 .pllpdec = SYSCON_PLL0PDEC_PDIV(2U),
209 .pllsscg = {0x0U,(SYSCON_PLL0SSCG1_MDIV_EXT(100U) | SYSCON_PLL0SSCG1_SEL_EXT_MASK)},
210 .pllRate = 100000000U,
211 .flags = PLL_SETUPFLAG_WAITLOCK
212 };
213 CLOCK_SetPLL0Freq(&pll0Setup); /*!< Configure PLL0 to the desired values */
214
215 /*!< Set up dividers */
216 CLOCK_SetClkDiv(kCLOCK_DivAhbClk, 1U, false); /*!< Set AHBCLKDIV divider to value 1 */
217
218 /*!< Set up clock selectors - Attach clocks to the peripheries */
219 CLOCK_AttachClk(kPLL0_to_MAIN_CLK); /*!< Switch MAIN_CLK to PLL0 */
220
221 /*!< Set SystemCoreClock variable. */
222 SystemCoreClock = BOARD_BOOTCLOCKPLL100M_CORE_CLOCK;
223 #endif
224 }
225
226 /*******************************************************************************
227 ******************** Configuration BOARD_BootClockPLL150M *********************
228 ******************************************************************************/
229 /* clang-format off */
230 /* TEXT BELOW IS USED AS SETTING FOR TOOLS *************************************
231 !!Configuration
232 name: BOARD_BootClockPLL150M
233 called_from_default_init: true
234 outputs:
235 - {id: FRO_12MHz_clock.outFreq, value: 12 MHz}
236 - {id: System_clock.outFreq, value: 150 MHz}
237 settings:
238 - {id: PLL0_Mode, value: Normal}
239 - {id: ENABLE_CLKIN_ENA, value: Enabled}
240 - {id: ENABLE_SYSTEM_CLK_OUT, value: Enabled}
241 - {id: SYSCON.MAINCLKSELB.sel, value: SYSCON.PLL0_BYPASS}
242 - {id: SYSCON.PLL0CLKSEL.sel, value: SYSCON.CLK_IN_EN}
243 - {id: SYSCON.PLL0M_MULT.scale, value: '150', locked: true}
244 - {id: SYSCON.PLL0N_DIV.scale, value: '8', locked: true}
245 - {id: SYSCON.PLL0_PDEC.scale, value: '2', locked: true}
246 sources:
247 - {id: SYSCON.XTAL.outFreq, value: 16 MHz, enabled: true}
248 * BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR TOOLS **********/
249 /* clang-format on */
250
251 /*******************************************************************************
252 * Variables for BOARD_BootClockPLL150M configuration
253 ******************************************************************************/
254 /*******************************************************************************
255 * Code for BOARD_BootClockPLL150M configuration
256 ******************************************************************************/
BOARD_BootClockPLL150M(void)257 void BOARD_BootClockPLL150M(void)
258 {
259 #ifndef SDK_SECONDARY_CORE
260 /*!< Set up the clock sources */
261 /*!< Configure FRO192M */
262 POWER_PowerInit(); /*!< Power Management Controller initialization */
263 POWER_DisablePD(kPDRUNCFG_PD_FRO192M); /*!< Ensure FRO is on */
264 CLOCK_SetupFROClocking(12000000U); /*!< Set up FRO to the 12 MHz, just for sure */
265 CLOCK_AttachClk(kFRO12M_to_MAIN_CLK); /*!< Switch to FRO 12MHz first to ensure we can change the clock setting */
266
267 CLOCK_SetupExtClocking(16000000U); /* Enable XTALHF clock */
268 ANACTRL->XO32M_CTRL |= ANACTRL_XO32M_CTRL_ENABLE_SYSTEM_CLK_OUT_MASK; /* Enable High speed Crystal oscillator output to system */
269
270 POWER_SetVoltageForFreq(150000000U); /*!< Set voltage for the one of the fastest clock outputs: System clock output */
271 CLOCK_SetFLASHAccessCyclesForFreq(150000000U); /*!< Set FLASH wait states for core */
272
273 /*!< Set up PLL */
274 CLOCK_AttachClk(kEXT_CLK_to_PLL0); /*!< Switch PLL0CLKSEL to EXT_CLK */
275 POWER_DisablePD(kPDRUNCFG_PD_PLL0); /* Ensure PLL is on */
276 POWER_DisablePD(kPDRUNCFG_PD_PLL0_SSCG);
277 const pll_setup_t pll0Setup = {
278 .pllctrl = SYSCON_PLL0CTRL_CLKEN_MASK | SYSCON_PLL0CTRL_SELI(53U) | SYSCON_PLL0CTRL_SELP(31U),
279 .pllndec = SYSCON_PLL0NDEC_NDIV(8U),
280 .pllpdec = SYSCON_PLL0PDEC_PDIV(1U),
281 .pllsscg = {0x0U,(SYSCON_PLL0SSCG1_MDIV_EXT(150U) | SYSCON_PLL0SSCG1_SEL_EXT_MASK)},
282 .pllRate = 150000000U,
283 .flags = PLL_SETUPFLAG_WAITLOCK
284 };
285 CLOCK_SetPLL0Freq(&pll0Setup); /*!< Configure PLL0 to the desired values */
286
287 /*!< Set up dividers */
288 CLOCK_SetClkDiv(kCLOCK_DivAhbClk, 1U, false); /*!< Set AHBCLKDIV divider to value 1 */
289
290 /*!< Set up clock selectors - Attach clocks to the peripheries */
291 CLOCK_AttachClk(kPLL0_to_MAIN_CLK); /*!< Switch MAIN_CLK to PLL0 */
292
293 /*!< Set SystemCoreClock variable. */
294 SystemCoreClock = BOARD_BOOTCLOCKPLL150M_CORE_CLOCK;
295 #endif
296 }
297
298 /*******************************************************************************
299 ******************* Configuration BOARD_BootClockPLL1_150M ********************
300 ******************************************************************************/
301 /* clang-format off */
302 /* TEXT BELOW IS USED AS SETTING FOR TOOLS *************************************
303 !!Configuration
304 name: BOARD_BootClockPLL1_150M
305 outputs:
306 - {id: FRO_12MHz_clock.outFreq, value: 12 MHz}
307 - {id: System_clock.outFreq, value: 150 MHz}
308 settings:
309 - {id: PLL1_Mode, value: Normal}
310 - {id: ENABLE_CLKIN_ENA, value: Enabled}
311 - {id: ENABLE_SYSTEM_CLK_OUT, value: Enabled}
312 - {id: SYSCON.MAINCLKSELB.sel, value: SYSCON.PLL1_BYPASS}
313 - {id: SYSCON.PLL1CLKSEL.sel, value: SYSCON.CLK_IN_EN}
314 - {id: SYSCON.PLL1M_MULT.scale, value: '150', locked: true}
315 - {id: SYSCON.PLL1N_DIV.scale, value: '8', locked: true}
316 - {id: SYSCON.PLL1_PDEC.scale, value: '2', locked: true}
317 sources:
318 - {id: SYSCON.XTAL.outFreq, value: 16 MHz, enabled: true}
319 * BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR TOOLS **********/
320 /* clang-format on */
321
322 /*******************************************************************************
323 * Variables for BOARD_BootClockPLL1_150M configuration
324 ******************************************************************************/
325 /*******************************************************************************
326 * Code for BOARD_BootClockPLL1_150M configuration
327 ******************************************************************************/
BOARD_BootClockPLL1_150M(void)328 void BOARD_BootClockPLL1_150M(void)
329 {
330 #ifndef SDK_SECONDARY_CORE
331 /*!< Set up the clock sources */
332 /*!< Configure FRO192M */
333 POWER_PowerInit(); /*!< Power Management Controller initialization */
334 POWER_DisablePD(kPDRUNCFG_PD_FRO192M); /*!< Ensure FRO is on */
335 CLOCK_SetupFROClocking(12000000U); /*!< Set up FRO to the 12 MHz, just for sure */
336 CLOCK_AttachClk(kFRO12M_to_MAIN_CLK); /*!< Switch to FRO 12MHz first to ensure we can change the clock setting */
337
338 CLOCK_SetupExtClocking(16000000U); /* Enable XTALHF clock */
339 ANACTRL->XO32M_CTRL |= ANACTRL_XO32M_CTRL_ENABLE_SYSTEM_CLK_OUT_MASK; /* Enable High speed Crystal oscillator output to system */
340
341 POWER_SetVoltageForFreq(150000000U); /*!< Set voltage for the one of the fastest clock outputs: System clock output */
342 CLOCK_SetFLASHAccessCyclesForFreq(150000000U); /*!< Set FLASH wait states for core */
343
344 /*!< Set up PLL1 */
345 CLOCK_AttachClk(kEXT_CLK_to_PLL1); /*!< Switch PLL1CLKSEL to EXT_CLK */
346 POWER_DisablePD(kPDRUNCFG_PD_PLL1); /* Ensure PLL is on */
347 const pll_setup_t pll1Setup = {
348 .pllctrl = SYSCON_PLL1CTRL_CLKEN_MASK | SYSCON_PLL1CTRL_SELI(53U) | SYSCON_PLL1CTRL_SELP(31U),
349 .pllndec = SYSCON_PLL1NDEC_NDIV(8U),
350 .pllpdec = SYSCON_PLL1PDEC_PDIV(1U),
351 .pllmdec = SYSCON_PLL1MDEC_MDIV(150U),
352 .pllRate = 150000000U,
353 .flags = PLL_SETUPFLAG_WAITLOCK
354 };
355 CLOCK_SetPLL1Freq(&pll1Setup); /*!< Configure PLL1 to the desired values */
356
357 /*!< Set up dividers */
358 CLOCK_SetClkDiv(kCLOCK_DivAhbClk, 1U, false); /*!< Set AHBCLKDIV divider to value 1 */
359
360 /*!< Set up clock selectors - Attach clocks to the peripheries */
361 CLOCK_AttachClk(kPLL1_to_MAIN_CLK); /*!< Switch MAIN_CLK to PLL1 */
362
363 /*!< Set SystemCoreClock variable. */
364 SystemCoreClock = BOARD_BOOTCLOCKPLL1_150M_CORE_CLOCK;
365 #endif
366 }
367
368