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