1 /*
2 * Copyright (c) 2015, Freescale Semiconductor, Inc.
3 * Copyright 2016-2017,2019 ,2021 NXP
4 * All rights reserved.
5 *
6 * SPDX-License-Identifier: BSD-3-Clause
7 */
8
9 /***********************************************************************************************************************
10 * This file was generated by the MCUXpresso Config Tools. Any manual edits made to this file
11 * will be overwritten if the respective MCUXpresso Config Tools is used to update this file.
12 **********************************************************************************************************************/
13 /*
14 * How to set up clock using clock driver functions:
15 *
16 * 1. Setup clock sources.
17 *
18 * 2. Setup voltage for the fastest of the clock outputs
19 *
20 * 3. Set up wait states of the flash.
21 *
22 * 4. Set up all dividers.
23 *
24 * 5. Set up all selectors to provide selected clocks.
25 */
26
27 /* clang-format off */
28 /* TEXT BELOW IS USED AS SETTING FOR TOOLS *************************************
29 !!GlobalInfo
30 product: Clocks v7.0
31 processor: LPC54628J512
32 package_id: LPC54628J512ET180
33 mcu_data: ksdk2_0
34 processor_version: 9.0.0
35 board: LPCXpresso54628
36 * BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR TOOLS **********/
37 /* clang-format on */
38
39 #include "fsl_power.h"
40 #include "fsl_clock.h"
41 #include "clock_config.h"
42
43 /*******************************************************************************
44 * Definitions
45 ******************************************************************************/
46
47 /*******************************************************************************
48 * Variables
49 ******************************************************************************/
50 /* System clock frequency. */
51 extern uint32_t SystemCoreClock;
52
53 /*******************************************************************************
54 ************************ BOARD_InitBootClocks function ************************
55 ******************************************************************************/
BOARD_InitBootClocks(void)56 void BOARD_InitBootClocks(void)
57 {
58 BOARD_BootClockPLL220M();
59 }
60
61 /*******************************************************************************
62 ******************** Configuration BOARD_BootClockFRO12M **********************
63 ******************************************************************************/
64 /* clang-format off */
65 /* TEXT BELOW IS USED AS SETTING FOR TOOLS *************************************
66 !!Configuration
67 name: BOARD_BootClockFRO12M
68 outputs:
69 - {id: FRO12M_clock.outFreq, value: 12 MHz}
70 - {id: FROHF_clock.outFreq, value: 48 MHz}
71 - {id: MAIN_clock.outFreq, value: 12 MHz}
72 - {id: System_clock.outFreq, value: 12 MHz}
73 settings:
74 - {id: SYSCON.EMCCLKDIV.scale, value: '1', locked: true}
75 * BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR TOOLS **********/
76 /* clang-format on */
77
78 /*******************************************************************************
79 * Variables for BOARD_BootClockFRO12M configuration
80 ******************************************************************************/
81 /*******************************************************************************
82 * Code for BOARD_BootClockFRO12M configuration
83 ******************************************************************************/
BOARD_BootClockFRO12M(void)84 void BOARD_BootClockFRO12M(void)
85 {
86 /*!< Set up the clock sources */
87 /*!< Set up FRO */
88 POWER_DisablePD(kPDRUNCFG_PD_FRO_EN); /*!< Ensure FRO is on */
89 CLOCK_AttachClk(kFRO12M_to_MAIN_CLK); /*!< Switch to FRO 12MHz first to ensure we can change voltage without accidentally
90 being below the voltage for current speed */
91 /*!< Need to make sure ROM and OTP has power(PDRUNCFG0[17,29]= 0U)
92 before calling this API since this API is implemented in ROM code */
93 CLOCK_SetupFROClocking(12000000U); /*!< Set up FRO to the 12 MHz, just for sure */
94 POWER_SetVoltageForFreq(12000000U); /*!< Set voltage for the one of the fastest clock outputs: System clock output */
95 CLOCK_SetFLASHAccessCyclesForFreq(12000000U); /*!< Set FLASH wait states for core */
96
97
98 /*!< Set up dividers */
99 CLOCK_SetClkDiv(kCLOCK_DivAhbClk, 1U, false); /*!< Reset divider counter and set divider to value 1 */
100
101 /*!< Set up clock selectors - Attach clocks to the peripheries */
102 CLOCK_AttachClk(kFRO12M_to_MAIN_CLK); /*!< Switch MAIN_CLK to FRO12M */
103 /* Set SystemCoreClock variable. */
104 SystemCoreClock = BOARD_BOOTCLOCKFRO12M_CORE_CLOCK;
105 }
106
107 /*******************************************************************************
108 ******************* Configuration BOARD_BootClockFROHF48M *********************
109 ******************************************************************************/
110 /* clang-format off */
111 /* TEXT BELOW IS USED AS SETTING FOR TOOLS *************************************
112 !!Configuration
113 name: BOARD_BootClockFROHF48M
114 outputs:
115 - {id: FRO12M_clock.outFreq, value: 12 MHz}
116 - {id: FROHF_clock.outFreq, value: 48 MHz}
117 - {id: MAIN_clock.outFreq, value: 48 MHz}
118 - {id: System_clock.outFreq, value: 48 MHz}
119 settings:
120 - {id: SYSCON.MAINCLKSELA.sel, value: SYSCON.fro_hf}
121 * BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR TOOLS **********/
122 /* clang-format on */
123
124 /*******************************************************************************
125 * Variables for BOARD_BootClockFROHF48M configuration
126 ******************************************************************************/
127 /*******************************************************************************
128 * Code for BOARD_BootClockFROHF48M configuration
129 ******************************************************************************/
BOARD_BootClockFROHF48M(void)130 void BOARD_BootClockFROHF48M(void)
131 {
132 /*!< Set up the clock sources */
133 /*!< Set up FRO */
134 POWER_DisablePD(kPDRUNCFG_PD_FRO_EN); /*!< Ensure FRO is on */
135 CLOCK_AttachClk(kFRO12M_to_MAIN_CLK); /*!< Switch to FRO 12MHz first to ensure we can change voltage without accidentally
136 being below the voltage for current speed */
137 POWER_SetVoltageForFreq(48000000U); /*!< Set voltage for the one of the fastest clock outputs: System clock output */
138 CLOCK_SetFLASHAccessCyclesForFreq(48000000U); /*!< Set FLASH wait states for core */
139
140 /*!< Need to make sure ROM and OTP has power(PDRUNCFG0[17,29]= 0U)
141 before calling this API since this API is implemented in ROM code */
142 CLOCK_SetupFROClocking(48000000U); /*!< Set up high frequency FRO output to selected frequency */
143
144 /*!< Set up dividers */
145 CLOCK_SetClkDiv(kCLOCK_DivAhbClk, 1U, false); /*!< Reset divider counter and set divider to value 1 */
146
147 /*!< Set up clock selectors - Attach clocks to the peripheries */
148 CLOCK_AttachClk(kFRO_HF_to_MAIN_CLK); /*!< Switch MAIN_CLK to FRO_HF */
149 /* Set SystemCoreClock variable. */
150 SystemCoreClock = BOARD_BOOTCLOCKFROHF48M_CORE_CLOCK;
151 }
152
153 /*******************************************************************************
154 ******************* Configuration BOARD_BootClockFROHF96M *********************
155 ******************************************************************************/
156 /* clang-format off */
157 /* TEXT BELOW IS USED AS SETTING FOR TOOLS *************************************
158 !!Configuration
159 name: BOARD_BootClockFROHF96M
160 outputs:
161 - {id: FRO12M_clock.outFreq, value: 12 MHz}
162 - {id: FROHF_clock.outFreq, value: 96 MHz}
163 - {id: MAIN_clock.outFreq, value: 96 MHz}
164 - {id: System_clock.outFreq, value: 96 MHz}
165 settings:
166 - {id: SYSCON.MAINCLKSELA.sel, value: SYSCON.fro_hf}
167 sources:
168 - {id: SYSCON.fro_hf.outFreq, value: 96 MHz}
169 * BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR TOOLS **********/
170 /* clang-format on */
171
172 /*******************************************************************************
173 * Variables for BOARD_BootClockFROHF96M configuration
174 ******************************************************************************/
175 /*******************************************************************************
176 * Code for BOARD_BootClockFROHF96M configuration
177 ******************************************************************************/
BOARD_BootClockFROHF96M(void)178 void BOARD_BootClockFROHF96M(void)
179 {
180 /*!< Set up the clock sources */
181 /*!< Set up FRO */
182 POWER_DisablePD(kPDRUNCFG_PD_FRO_EN); /*!< Ensure FRO is on */
183 CLOCK_AttachClk(kFRO12M_to_MAIN_CLK); /*!< Switch to FRO 12MHz first to ensure we can change voltage without accidentally
184 being below the voltage for current speed */
185 POWER_SetVoltageForFreq(96000000U); /*!< Set voltage for the one of the fastest clock outputs: System clock output */
186 CLOCK_SetFLASHAccessCyclesForFreq(96000000U); /*!< Set FLASH wait states for core */
187
188 /*!< Need to make sure ROM and OTP has power(PDRUNCFG0[17,29]= 0U)
189 before calling this API since this API is implemented in ROM code */
190 CLOCK_SetupFROClocking(96000000U); /*!< Set up high frequency FRO output to selected frequency */
191
192 /*!< Set up dividers */
193 CLOCK_SetClkDiv(kCLOCK_DivAhbClk, 1U, false); /*!< Reset divider counter and set divider to value 1 */
194
195 /*!< Set up clock selectors - Attach clocks to the peripheries */
196 CLOCK_AttachClk(kFRO_HF_to_MAIN_CLK); /*!< Switch MAIN_CLK to FRO_HF */
197 /* Set SystemCoreClock variable. */
198 SystemCoreClock = BOARD_BOOTCLOCKFROHF96M_CORE_CLOCK;
199 }
200
201 /*******************************************************************************
202 ******************** Configuration BOARD_BootClockPLL180M *********************
203 ******************************************************************************/
204 /* clang-format off */
205 /* TEXT BELOW IS USED AS SETTING FOR TOOLS *************************************
206 !!Configuration
207 name: BOARD_BootClockPLL180M
208 outputs:
209 - {id: FRO12M_clock.outFreq, value: 12 MHz}
210 - {id: FROHF_clock.outFreq, value: 48 MHz}
211 - {id: MAIN_clock.outFreq, value: 180 MHz}
212 - {id: SYSPLL_clock.outFreq, value: 180 MHz}
213 - {id: System_clock.outFreq, value: 180 MHz}
214 settings:
215 - {id: SYSCON.MAINCLKSELB.sel, value: SYSCON.PLL_BYPASS}
216 - {id: SYSCON.M_MULT.scale, value: '30', locked: true}
217 - {id: SYSCON.N_DIV.scale, value: '1', locked: true}
218 - {id: SYSCON.PDEC.scale, value: '2', locked: true}
219 - {id: SYSCON_PDRUNCFG0_PDEN_SYS_PLL_CFG, value: Power_up}
220 sources:
221 - {id: SYSCON._clk_in.outFreq, value: 12 MHz, enabled: true}
222 * BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR TOOLS **********/
223 /* clang-format on */
224
225 /*******************************************************************************
226 * Variables for BOARD_BootClockPLL180M configuration
227 ******************************************************************************/
228 /*******************************************************************************
229 * Code for BOARD_BootClockPLL180M configuration
230 ******************************************************************************/
BOARD_BootClockPLL180M(void)231 void BOARD_BootClockPLL180M(void)
232 {
233 /*!< Set up the clock sources */
234 /*!< Set up FRO */
235 POWER_DisablePD(kPDRUNCFG_PD_FRO_EN); /*!< Ensure FRO is on */
236 CLOCK_AttachClk(kFRO12M_to_MAIN_CLK); /*!< Switch to FRO 12MHz first to ensure we can change voltage without accidentally
237 being below the voltage for current speed */
238 POWER_DisablePD(kPDRUNCFG_PD_SYS_OSC); /*!< Enable System Oscillator Power */
239 SYSCON->SYSOSCCTRL = ((SYSCON->SYSOSCCTRL & ~SYSCON_SYSOSCCTRL_FREQRANGE_MASK) | SYSCON_SYSOSCCTRL_FREQRANGE(0U)); /*!< Set system oscillator range */
240 POWER_SetVoltageForFreq(180000000U); /*!< Set voltage for the one of the fastest clock outputs: System clock output */
241 CLOCK_SetFLASHAccessCyclesForFreq(180000000U); /*!< Set FLASH wait states for core */
242
243 /*!< Set up SYS PLL */
244 const pll_setup_t pllSetup = {
245 .pllctrl = SYSCON_SYSPLLCTRL_SELI(32U) | SYSCON_SYSPLLCTRL_SELP(16U) | SYSCON_SYSPLLCTRL_SELR(0U),
246 .pllmdec = (SYSCON_SYSPLLMDEC_MDEC(8191U)),
247 .pllndec = (SYSCON_SYSPLLNDEC_NDEC(770U)),
248 .pllpdec = (SYSCON_SYSPLLPDEC_PDEC(98U)),
249 .pllRate = 180000000U,
250 .flags = PLL_SETUPFLAG_WAITLOCK | PLL_SETUPFLAG_POWERUP
251 };
252 CLOCK_AttachClk(kFRO12M_to_SYS_PLL); /*!< Set sys pll clock source*/
253 CLOCK_SetPLLFreq(&pllSetup); /*!< Configure PLL to the desired value */
254
255 /*!< Set up dividers */
256 CLOCK_SetClkDiv(kCLOCK_DivAhbClk, 1U, false); /*!< Reset divider counter and set divider to value 1 */
257
258 /*!< Set up clock selectors - Attach clocks to the peripheries */
259 CLOCK_AttachClk(kSYS_PLL_to_MAIN_CLK); /*!< Switch MAIN_CLK to SYS_PLL */
260 SYSCON->MAINCLKSELA = ((SYSCON->MAINCLKSELA & ~SYSCON_MAINCLKSELA_SEL_MASK) | SYSCON_MAINCLKSELA_SEL(0U)); /*!< Switch MAINCLKSELA to FRO12M even it is not used for MAINCLKSELB */
261 /* Set SystemCoreClock variable. */
262 SystemCoreClock = BOARD_BOOTCLOCKPLL180M_CORE_CLOCK;
263 }
264
265 /*******************************************************************************
266 ******************** Configuration BOARD_BootClockPLL220M *********************
267 ******************************************************************************/
268 /* clang-format off */
269 /* TEXT BELOW IS USED AS SETTING FOR TOOLS *************************************
270 !!Configuration
271 name: BOARD_BootClockPLL220M
272 called_from_default_init: true
273 outputs:
274 - {id: FRO12M_clock.outFreq, value: 12 MHz}
275 - {id: FROHF_clock.outFreq, value: 96 MHz}
276 - {id: MAIN_clock.outFreq, value: 220 MHz}
277 - {id: SYSPLL_clock.outFreq, value: 220 MHz}
278 - {id: System_clock.outFreq, value: 220 MHz}
279 - {id: USB0_clock.outFreq, value: 48 MHz}
280 settings:
281 - {id: SYSCON.MAINCLKSELB.sel, value: SYSCON.PLL_BYPASS}
282 - {id: SYSCON.M_MULT.scale, value: '110', locked: true}
283 - {id: SYSCON.N_DIV.scale, value: '3', locked: true}
284 - {id: SYSCON.PDEC.scale, value: '2', locked: true}
285 - {id: SYSCON.USB0CLKDIV.scale, value: '2'}
286 - {id: SYSCON.USB0CLKSEL.sel, value: SYSCON.fro_hf}
287 - {id: SYSCON_PDRUNCFG0_PDEN_SYS_PLL_CFG, value: Power_up}
288 sources:
289 - {id: SYSCON.fro_hf.outFreq, value: 96 MHz}
290 * BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR TOOLS **********/
291 /* clang-format on */
292
293 /*******************************************************************************
294 * Variables for BOARD_BootClockPLL220M configuration
295 ******************************************************************************/
296 /*******************************************************************************
297 * Code for BOARD_BootClockPLL220M configuration
298 ******************************************************************************/
BOARD_BootClockPLL220M(void)299 void BOARD_BootClockPLL220M(void)
300 {
301 /*!< Set up the clock sources */
302 /*!< Set up FRO */
303 POWER_DisablePD(kPDRUNCFG_PD_FRO_EN); /*!< Ensure FRO is on */
304 CLOCK_AttachClk(kFRO12M_to_MAIN_CLK); /*!< Switch to FRO 12MHz first to ensure we can change voltage without accidentally
305 being below the voltage for current speed */
306 POWER_SetVoltageForFreq(220000000U); /*!< Set voltage for the one of the fastest clock outputs: System clock output */
307 CLOCK_SetFLASHAccessCyclesForFreq(220000000U); /*!< Set FLASH wait states for core */
308
309 /*!< Set up SYS PLL */
310 const pll_setup_t pllSetup = {
311 .pllctrl = SYSCON_SYSPLLCTRL_SELI(34U) | SYSCON_SYSPLLCTRL_SELP(31U) | SYSCON_SYSPLLCTRL_SELR(0U),
312 .pllmdec = (SYSCON_SYSPLLMDEC_MDEC(13243U)),
313 .pllndec = (SYSCON_SYSPLLNDEC_NDEC(1U)),
314 .pllpdec = (SYSCON_SYSPLLPDEC_PDEC(98U)),
315 .pllRate = 220000000U,
316 .flags = PLL_SETUPFLAG_WAITLOCK | PLL_SETUPFLAG_POWERUP
317 };
318 CLOCK_AttachClk(kFRO12M_to_SYS_PLL); /*!< Set sys pll clock source*/
319 CLOCK_SetPLLFreq(&pllSetup); /*!< Configure PLL to the desired value */
320 /*!< Need to make sure ROM and OTP has power(PDRUNCFG0[17,29]= 0U)
321 before calling this API since this API is implemented in ROM code */
322 CLOCK_SetupFROClocking(96000000U); /*!< Set up high frequency FRO output to selected frequency */
323
324 /*!< Set up dividers */
325 CLOCK_SetClkDiv(kCLOCK_DivAhbClk, 1U, false); /*!< Reset divider counter and set divider to value 1 */
326 CLOCK_SetClkDiv(kCLOCK_DivUsb0Clk, 0U, true); /*!< Reset USB0CLKDIV divider counter and halt it */
327 CLOCK_SetClkDiv(kCLOCK_DivUsb0Clk, 2U, false); /*!< Set USB0CLKDIV divider to value 2 */
328
329 /*!< Set up clock selectors - Attach clocks to the peripheries */
330 CLOCK_AttachClk(kSYS_PLL_to_MAIN_CLK); /*!< Switch MAIN_CLK to SYS_PLL */
331 CLOCK_AttachClk(kFRO_HF_to_USB0_CLK); /*!< Switch USB0_CLK to FRO_HF */
332 SYSCON->MAINCLKSELA = ((SYSCON->MAINCLKSELA & ~SYSCON_MAINCLKSELA_SEL_MASK) | SYSCON_MAINCLKSELA_SEL(0U)); /*!< Switch MAINCLKSELA to FRO12M even it is not used for MAINCLKSELB */
333 /* Set SystemCoreClock variable. */
334 SystemCoreClock = BOARD_BOOTCLOCKPLL220M_CORE_CLOCK;
335 }
336
337