diff options
Diffstat (limited to 'lib/chibios-contrib/ext/mcux-sdk/boards/frdmk32l2a4s/clock_config.c')
-rw-r--r-- | lib/chibios-contrib/ext/mcux-sdk/boards/frdmk32l2a4s/clock_config.c | 510 |
1 files changed, 510 insertions, 0 deletions
diff --git a/lib/chibios-contrib/ext/mcux-sdk/boards/frdmk32l2a4s/clock_config.c b/lib/chibios-contrib/ext/mcux-sdk/boards/frdmk32l2a4s/clock_config.c new file mode 100644 index 000000000..499f71ad5 --- /dev/null +++ b/lib/chibios-contrib/ext/mcux-sdk/boards/frdmk32l2a4s/clock_config.c | |||
@@ -0,0 +1,510 @@ | |||
1 | /* | ||
2 | * Copyright 2019 NXP | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * SPDX-License-Identifier: BSD-3-Clause | ||
6 | */ | ||
7 | |||
8 | /* | ||
9 | * How to setup clock using clock driver functions: | ||
10 | * | ||
11 | * 1. Call CLOCK_InitXXX() to configure corresponding SCG clock source. | ||
12 | * Note: The clock could not be set when it is being used as system clock. | ||
13 | * In default out of reset, the CPU is clocked from FIRC(IRC48M), | ||
14 | * so before setting FIRC, change to use another avaliable clock source. | ||
15 | * | ||
16 | * 2. Call CLOCK_SetXtal0Freq() to set XTAL0 frequency based on board settings. | ||
17 | * | ||
18 | * 3. Call CLOCK_SetXxxModeSysClkConfig() to set SCG mode for Xxx run mode. | ||
19 | * Wait until the system clock source is changed to target source. | ||
20 | * | ||
21 | * 4. If power mode change is needed, call SMC_SetPowerModeProtection() to allow | ||
22 | * corresponding power mode and SMC_SetPowerModeXxx() to change to Xxx mode. | ||
23 | * Supported run mode and clock restrictions could be found in Reference Manual. | ||
24 | */ | ||
25 | |||
26 | /* clang-format off */ | ||
27 | /* TEXT BELOW IS USED AS SETTING FOR TOOLS ************************************* | ||
28 | !!GlobalInfo | ||
29 | product: Clocks v6.0 | ||
30 | processor: K32L2A41xxxxA | ||
31 | package_id: K32L2A41VLL1A | ||
32 | mcu_data: ksdk2_0 | ||
33 | processor_version: 0.0.1 | ||
34 | * BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR TOOLS **********/ | ||
35 | /* clang-format on */ | ||
36 | |||
37 | #include "fsl_smc.h" | ||
38 | #include "clock_config.h" | ||
39 | |||
40 | /******************************************************************************* | ||
41 | * Definitions | ||
42 | ******************************************************************************/ | ||
43 | #define SCG_CLKOUTCNFG_SIRC 2U /*!< SCG CLKOUT clock select: Slow IRC */ | ||
44 | #define SCG_SOSC_DISABLE 0U /*!< System OSC disabled */ | ||
45 | #define SCG_SPLL_DISABLE 0U /*!< System PLL disabled */ | ||
46 | #define SCG_SYS_OSC_CAP_0P 0U /*!< Oscillator 0pF capacitor load */ | ||
47 | |||
48 | /******************************************************************************* | ||
49 | * Variables | ||
50 | ******************************************************************************/ | ||
51 | /* System clock frequency. */ | ||
52 | extern uint32_t SystemCoreClock; | ||
53 | |||
54 | /******************************************************************************* | ||
55 | * Code | ||
56 | ******************************************************************************/ | ||
57 | /*FUNCTION********************************************************************** | ||
58 | * | ||
59 | * Function Name : CLOCK_CONFIG_SetScgOutSel | ||
60 | * Description : Set the SCG clock out select (CLKOUTSEL). | ||
61 | * Param setting : The selected clock source. | ||
62 | * | ||
63 | *END**************************************************************************/ | ||
64 | static void CLOCK_CONFIG_SetScgOutSel(uint8_t setting) | ||
65 | { | ||
66 | SCG->CLKOUTCNFG = SCG_CLKOUTCNFG_CLKOUTSEL(setting); | ||
67 | } | ||
68 | |||
69 | /*FUNCTION********************************************************************** | ||
70 | * | ||
71 | * Function Name : CLOCK_CONFIG_FircSafeConfig | ||
72 | * Description : This function is used to safely configure FIRC clock. | ||
73 | * In default out of reset, the CPU is clocked from FIRC(IRC48M). | ||
74 | * Before setting FIRC, change to use SIRC as system clock, | ||
75 | * then configure FIRC. After FIRC is set, change back to use FIRC | ||
76 | * in case SIRC need to be configured. | ||
77 | * Param fircConfig : FIRC configuration. | ||
78 | * | ||
79 | *END**************************************************************************/ | ||
80 | static void CLOCK_CONFIG_FircSafeConfig(const scg_firc_config_t *fircConfig) | ||
81 | { | ||
82 | scg_sys_clk_config_t curConfig; | ||
83 | const scg_sirc_config_t scgSircConfig = {.enableMode = kSCG_SircEnable, | ||
84 | .div1 = kSCG_AsyncClkDisable, | ||
85 | .div3 = kSCG_AsyncClkDivBy2, | ||
86 | .range = kSCG_SircRangeHigh}; | ||
87 | scg_sys_clk_config_t sysClkSafeConfigSource = { | ||
88 | .divSlow = kSCG_SysClkDivBy4, /* Slow clock divider */ | ||
89 | #if FSL_CLOCK_DRIVER_VERSION < MAKE_VERSION(2, 1, 1) | ||
90 | .reserved1 = 0, | ||
91 | .reserved2 = 0, | ||
92 | .reserved3 = 0, | ||
93 | #endif | ||
94 | .divCore = kSCG_SysClkDivBy1, /* Core clock divider */ | ||
95 | #if FSL_CLOCK_DRIVER_VERSION < MAKE_VERSION(2, 1, 1) | ||
96 | .reserved4 = 0, | ||
97 | #endif | ||
98 | .src = kSCG_SysClkSrcSirc, /* System clock source */ | ||
99 | #if FSL_CLOCK_DRIVER_VERSION < MAKE_VERSION(2, 1, 1) | ||
100 | .reserved5 = 0, | ||
101 | #endif | ||
102 | }; | ||
103 | /* Init Sirc. */ | ||
104 | CLOCK_InitSirc(&scgSircConfig); | ||
105 | /* Change to use SIRC as system clock source to prepare to change FIRCCFG register. */ | ||
106 | CLOCK_SetRunModeSysClkConfig(&sysClkSafeConfigSource); | ||
107 | /* Wait for clock source switch finished. */ | ||
108 | do | ||
109 | { | ||
110 | CLOCK_GetCurSysClkConfig(&curConfig); | ||
111 | } while (curConfig.src != sysClkSafeConfigSource.src); | ||
112 | |||
113 | /* Init Firc. */ | ||
114 | CLOCK_InitFirc(fircConfig); | ||
115 | /* Change back to use FIRC as system clock source in order to configure SIRC if needed. */ | ||
116 | sysClkSafeConfigSource.src = kSCG_SysClkSrcFirc; | ||
117 | CLOCK_SetRunModeSysClkConfig(&sysClkSafeConfigSource); | ||
118 | /* Wait for clock source switch finished. */ | ||
119 | do | ||
120 | { | ||
121 | CLOCK_GetCurSysClkConfig(&curConfig); | ||
122 | } while (curConfig.src != sysClkSafeConfigSource.src); | ||
123 | } | ||
124 | |||
125 | /******************************************************************************* | ||
126 | ************************ BOARD_InitBootClocks function ************************ | ||
127 | ******************************************************************************/ | ||
128 | void BOARD_InitBootClocks(void) | ||
129 | { | ||
130 | BOARD_BootClockRUN(); | ||
131 | } | ||
132 | |||
133 | /******************************************************************************* | ||
134 | ********************** Configuration BOARD_BootClockRUN *********************** | ||
135 | ******************************************************************************/ | ||
136 | /* clang-format off */ | ||
137 | /* TEXT BELOW IS USED AS SETTING FOR TOOLS ************************************* | ||
138 | !!Configuration | ||
139 | name: BOARD_BootClockRUN | ||
140 | called_from_default_init: true | ||
141 | outputs: | ||
142 | - {id: Core_clock.outFreq, value: 48 MHz} | ||
143 | - {id: FIRCDIV1_CLK.outFreq, value: 48 MHz} | ||
144 | - {id: FIRCDIV3_CLK.outFreq, value: 48 MHz} | ||
145 | - {id: LPO_clock.outFreq, value: 1 kHz} | ||
146 | - {id: OSC32KCLK.outFreq, value: 32.768 kHz} | ||
147 | - {id: SIRCDIV3_CLK.outFreq, value: 4 MHz} | ||
148 | - {id: SIRC_CLK.outFreq, value: 8 MHz} | ||
149 | - {id: SOSCDIV3_CLK.outFreq, value: 32.768 kHz} | ||
150 | - {id: SOSCER_CLK.outFreq, value: 32.768 kHz} | ||
151 | - {id: SOSC_CLK.outFreq, value: 32.768 kHz} | ||
152 | - {id: Slow_clock.outFreq, value: 24 MHz} | ||
153 | - {id: System_clock.outFreq, value: 48 MHz} | ||
154 | settings: | ||
155 | - {id: SCG.FIRCDIV1.scale, value: '1', locked: true} | ||
156 | - {id: SCG.FIRCDIV3.scale, value: '1', locked: true} | ||
157 | - {id: SCG.SIRCDIV3.scale, value: '2', locked: true} | ||
158 | - {id: SCG.SOSCDIV3.scale, value: '1', locked: true} | ||
159 | - {id: SCG_SOSCCFG_OSC_MODE_CFG, value: ModeOscLowPower} | ||
160 | - {id: SCG_SOSCCSR_SOSCEN_CFG, value: Enabled} | ||
161 | - {id: SCG_SOSCCSR_SOSCERCLKEN_CFG, value: Enabled} | ||
162 | sources: | ||
163 | - {id: SCG.SOSC.outFreq, value: 32.768 kHz, enabled: true} | ||
164 | * BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR TOOLS **********/ | ||
165 | /* clang-format on */ | ||
166 | |||
167 | /******************************************************************************* | ||
168 | * Variables for BOARD_BootClockRUN configuration | ||
169 | ******************************************************************************/ | ||
170 | const scg_sys_clk_config_t g_sysClkConfig_BOARD_BootClockRUN = { | ||
171 | .divSlow = kSCG_SysClkDivBy2, /* Slow Clock Divider: divided by 2 */ | ||
172 | #if FSL_CLOCK_DRIVER_VERSION < MAKE_VERSION(2, 1, 1) | ||
173 | .reserved1 = 0, | ||
174 | .reserved2 = 0, | ||
175 | .reserved3 = 0, | ||
176 | #endif | ||
177 | .divCore = kSCG_SysClkDivBy1, /* Core Clock Divider: divided by 1 */ | ||
178 | #if FSL_CLOCK_DRIVER_VERSION < MAKE_VERSION(2, 1, 1) | ||
179 | .reserved4 = 0, | ||
180 | #endif | ||
181 | .src = kSCG_SysClkSrcFirc, /* Fast IRC is selected as System Clock Source */ | ||
182 | #if FSL_CLOCK_DRIVER_VERSION < MAKE_VERSION(2, 1, 1) | ||
183 | .reserved5 = 0, | ||
184 | #endif | ||
185 | }; | ||
186 | const scg_sosc_config_t g_scgSysOscConfig_BOARD_BootClockRUN = { | ||
187 | .freq = 32768U, /* System Oscillator frequency: 32768Hz */ | ||
188 | .enableMode = kSCG_SysOscEnable | kSCG_SysOscEnableErClk, /* Enable System OSC clock, Enable OSCERCLK */ | ||
189 | .monitorMode = kSCG_SysOscMonitorDisable, /* Monitor disabled */ | ||
190 | .div1 = kSCG_AsyncClkDisable, /* System OSC Clock Divider 1: Clock output is disabled */ | ||
191 | .div3 = kSCG_AsyncClkDivBy1, /* System OSC Clock Divider 3: divided by 1 */ | ||
192 | .capLoad = SCG_SYS_OSC_CAP_0P, /* Oscillator capacity load: 0pF */ | ||
193 | .workMode = kSCG_SysOscModeOscLowPower, /* Oscillator low power */ | ||
194 | }; | ||
195 | const scg_sirc_config_t g_scgSircConfig_BOARD_BootClockRUN = { | ||
196 | .enableMode = kSCG_SircEnable | kSCG_SircEnableInLowPower, /* Enable SIRC clock, Enable SIRC in low power mode */ | ||
197 | .div1 = kSCG_AsyncClkDisable, /* Slow IRC Clock Divider 1: Clock output is disabled */ | ||
198 | .div3 = kSCG_AsyncClkDivBy2, /* Slow IRC Clock Divider 3: divided by 2 */ | ||
199 | .range = kSCG_SircRangeHigh, /* Slow IRC high range clock (8 MHz) */ | ||
200 | }; | ||
201 | const scg_firc_config_t g_scgFircConfig_BOARD_BootClockRUN = { | ||
202 | .enableMode = kSCG_FircEnable, /* Enable FIRC clock */ | ||
203 | .div1 = kSCG_AsyncClkDivBy1, /* Fast IRC Clock Divider 1: divided by 1 */ | ||
204 | .div3 = kSCG_AsyncClkDivBy1, /* Fast IRC Clock Divider 3: divided by 1 */ | ||
205 | .range = kSCG_FircRange48M, /* Fast IRC is trimmed to 48MHz */ | ||
206 | .trimConfig = NULL, /* Fast IRC Trim disabled */ | ||
207 | }; | ||
208 | const scg_spll_config_t g_scgSysPllConfig_BOARD_BootClockRUN = { | ||
209 | .enableMode = SCG_SPLL_DISABLE, /* System PLL disabled */ | ||
210 | .monitorMode = kSCG_SysPllMonitorDisable, /* Monitor disabled */ | ||
211 | .div1 = kSCG_AsyncClkDisable, /* System PLL Clock Divider 1: Clock output is disabled */ | ||
212 | .div3 = kSCG_AsyncClkDisable, /* System PLL Clock Divider 3: Clock output is disabled */ | ||
213 | .src = kSCG_SysPllSrcSysOsc, /* System PLL clock source is System OSC */ | ||
214 | .prediv = 0, /* Divided by 1 */ | ||
215 | .mult = 0, /* Multiply Factor is 16 */ | ||
216 | }; | ||
217 | /******************************************************************************* | ||
218 | * Code for BOARD_BootClockRUN configuration | ||
219 | ******************************************************************************/ | ||
220 | void BOARD_BootClockRUN(void) | ||
221 | { | ||
222 | scg_sys_clk_config_t curConfig; | ||
223 | |||
224 | /* Init SOSC according to board configuration. */ | ||
225 | CLOCK_InitSysOsc(&g_scgSysOscConfig_BOARD_BootClockRUN); | ||
226 | /* Set the XTAL0 frequency based on board settings. */ | ||
227 | CLOCK_SetXtal0Freq(g_scgSysOscConfig_BOARD_BootClockRUN.freq); | ||
228 | /* Init FIRC. */ | ||
229 | CLOCK_CONFIG_FircSafeConfig(&g_scgFircConfig_BOARD_BootClockRUN); | ||
230 | /* Init SIRC. */ | ||
231 | CLOCK_InitSirc(&g_scgSircConfig_BOARD_BootClockRUN); | ||
232 | /* Set SCG to FIRC mode. */ | ||
233 | CLOCK_SetRunModeSysClkConfig(&g_sysClkConfig_BOARD_BootClockRUN); | ||
234 | /* Wait for clock source switch finished. */ | ||
235 | do | ||
236 | { | ||
237 | CLOCK_GetCurSysClkConfig(&curConfig); | ||
238 | } while (curConfig.src != g_sysClkConfig_BOARD_BootClockRUN.src); | ||
239 | /* Set SystemCoreClock variable. */ | ||
240 | SystemCoreClock = BOARD_BOOTCLOCKRUN_CORE_CLOCK; | ||
241 | } | ||
242 | |||
243 | /******************************************************************************* | ||
244 | ********************* Configuration BOARD_BootClockHSRUN ********************** | ||
245 | ******************************************************************************/ | ||
246 | /* clang-format off */ | ||
247 | /* TEXT BELOW IS USED AS SETTING FOR TOOLS ************************************* | ||
248 | !!Configuration | ||
249 | name: BOARD_BootClockHSRUN | ||
250 | outputs: | ||
251 | - {id: CLKOUT.outFreq, value: 8 MHz} | ||
252 | - {id: Core_clock.outFreq, value: 96 MHz, locked: true, accuracy: '0.001'} | ||
253 | - {id: FIRCDIV1_CLK.outFreq, value: 48 MHz} | ||
254 | - {id: FIRCDIV3_CLK.outFreq, value: 48 MHz} | ||
255 | - {id: LPO_clock.outFreq, value: 1 kHz} | ||
256 | - {id: OSC32KCLK.outFreq, value: 32.768 kHz} | ||
257 | - {id: PLLDIV1_CLK.outFreq, value: 96 MHz} | ||
258 | - {id: PLLDIV3_CLK.outFreq, value: 96 MHz} | ||
259 | - {id: SIRCDIV1_CLK.outFreq, value: 8 MHz} | ||
260 | - {id: SIRCDIV3_CLK.outFreq, value: 8 MHz} | ||
261 | - {id: SIRC_CLK.outFreq, value: 8 MHz} | ||
262 | - {id: SOSCDIV1_CLK.outFreq, value: 32.768 kHz} | ||
263 | - {id: SOSCDIV3_CLK.outFreq, value: 32.768 kHz} | ||
264 | - {id: SOSCER_CLK.outFreq, value: 32.768 kHz} | ||
265 | - {id: SOSC_CLK.outFreq, value: 32.768 kHz} | ||
266 | - {id: Slow_clock.outFreq, value: 24 MHz, locked: true, accuracy: '0.001'} | ||
267 | - {id: System_clock.outFreq, value: 96 MHz} | ||
268 | settings: | ||
269 | - {id: SCGMode, value: SPLL} | ||
270 | - {id: powerMode, value: HSRUN} | ||
271 | - {id: CLKOUTConfig, value: 'yes'} | ||
272 | - {id: SCG.DIVSLOW.scale, value: '4'} | ||
273 | - {id: SCG.FIRCDIV1.scale, value: '1', locked: true} | ||
274 | - {id: SCG.FIRCDIV3.scale, value: '1', locked: true} | ||
275 | - {id: SCG.PREDIV.scale, value: '4'} | ||
276 | - {id: SCG.SCSSEL.sel, value: SCG.SPLL_DIV2_CLK} | ||
277 | - {id: SCG.SIRCDIV1.scale, value: '1', locked: true} | ||
278 | - {id: SCG.SIRCDIV3.scale, value: '1', locked: true} | ||
279 | - {id: SCG.SOSCDIV1.scale, value: '1', locked: true} | ||
280 | - {id: SCG.SOSCDIV3.scale, value: '1', locked: true} | ||
281 | - {id: SCG.SPLLDIV1.scale, value: '1', locked: true} | ||
282 | - {id: SCG.SPLLDIV3.scale, value: '1', locked: true} | ||
283 | - {id: SCG.SPLLSRCSEL.sel, value: SCG.FIRC} | ||
284 | - {id: 'SCG::RCCR[DIVCORE].bitField', value: Divide-by-9} | ||
285 | - {id: 'SCG::RCCR[DIVSLOW].bitField', value: Divide-by-4} | ||
286 | - {id: 'SCG::RCCR[SCS].bitField', value: System PLL (SPLL_CLK)} | ||
287 | - {id: SCG_SOSCCFG_OSC_MODE_CFG, value: ModeOscLowPower} | ||
288 | - {id: SCG_SOSCCSR_SOSCEN_CFG, value: Enabled} | ||
289 | - {id: SCG_SOSCCSR_SOSCERCLKEN_CFG, value: Enabled} | ||
290 | - {id: SCG_SPLLCSR_SPLLEN_CFG, value: Enabled} | ||
291 | sources: | ||
292 | - {id: SCG.SOSC.outFreq, value: 32.768 kHz, enabled: true} | ||
293 | * BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR TOOLS **********/ | ||
294 | /* clang-format on */ | ||
295 | |||
296 | /******************************************************************************* | ||
297 | * Variables for BOARD_BootClockHSRUN configuration | ||
298 | ******************************************************************************/ | ||
299 | /* System clock source and divider for run mode, it is used to prepare for switch to HSRUN modeļ¼to make sure HSRUN | ||
300 | * switch frequency range | ||
301 | * is not bigger than x2.*/ | ||
302 | const scg_sys_clk_config_t g_sysClkConfig_BOARD_BootClockRunToHSRUN = { | ||
303 | .divSlow = kSCG_SysClkDivBy4, /* Slow Clock Divider: divided by 4 */ | ||
304 | #if FSL_CLOCK_DRIVER_VERSION < MAKE_VERSION(2, 1, 1) | ||
305 | .reserved1 = 0, | ||
306 | .reserved2 = 0, | ||
307 | .reserved3 = 0, | ||
308 | #endif | ||
309 | .divCore = kSCG_SysClkDivBy2, /* Core Clock Divider: divided by 1 */ | ||
310 | #if FSL_CLOCK_DRIVER_VERSION < MAKE_VERSION(2, 1, 1) | ||
311 | .reserved4 = 0, | ||
312 | #endif | ||
313 | .src = kSCG_SysClkSrcSysPll, /* System PLL is selected as System Clock Source */ | ||
314 | #if FSL_CLOCK_DRIVER_VERSION < MAKE_VERSION(2, 1, 1) | ||
315 | .reserved5 = 0, | ||
316 | #endif | ||
317 | }; | ||
318 | |||
319 | const scg_sys_clk_config_t g_sysClkConfig_BOARD_BootClockHSRUN = { | ||
320 | .divSlow = kSCG_SysClkDivBy4, /* Slow Clock Divider: divided by 4 */ | ||
321 | #if FSL_CLOCK_DRIVER_VERSION < MAKE_VERSION(2, 1, 1) | ||
322 | .reserved1 = 0, | ||
323 | .reserved2 = 0, | ||
324 | .reserved3 = 0, | ||
325 | #endif | ||
326 | .divCore = kSCG_SysClkDivBy1, /* Core Clock Divider: divided by 1 */ | ||
327 | #if FSL_CLOCK_DRIVER_VERSION < MAKE_VERSION(2, 1, 1) | ||
328 | .reserved4 = 0, | ||
329 | #endif | ||
330 | .src = kSCG_SysClkSrcSysPll, /* System PLL is selected as System Clock Source */ | ||
331 | #if FSL_CLOCK_DRIVER_VERSION < MAKE_VERSION(2, 1, 1) | ||
332 | .reserved5 = 0, | ||
333 | #endif | ||
334 | }; | ||
335 | const scg_sosc_config_t g_scgSysOscConfig_BOARD_BootClockHSRUN = { | ||
336 | .freq = 32768U, /* System Oscillator frequency: 32768Hz */ | ||
337 | .enableMode = kSCG_SysOscEnable | kSCG_SysOscEnableErClk, /* Enable System OSC clock, Enable OSCERCLK */ | ||
338 | .monitorMode = kSCG_SysOscMonitorDisable, /* Monitor disabled */ | ||
339 | .div1 = kSCG_AsyncClkDivBy1, /* System OSC Clock Divider 1: divided by 1 */ | ||
340 | .div3 = kSCG_AsyncClkDivBy1, /* System OSC Clock Divider 3: divided by 1 */ | ||
341 | .capLoad = SCG_SYS_OSC_CAP_0P, /* Oscillator capacity load: 0pF */ | ||
342 | .workMode = kSCG_SysOscModeOscLowPower, /* Oscillator low power */ | ||
343 | }; | ||
344 | const scg_sirc_config_t g_scgSircConfig_BOARD_BootClockHSRUN = { | ||
345 | .enableMode = kSCG_SircEnable | kSCG_SircEnableInLowPower, /* Enable SIRC clock, Enable SIRC in low power mode */ | ||
346 | .div1 = kSCG_AsyncClkDivBy1, /* Slow IRC Clock Divider 1: divided by 1 */ | ||
347 | .div3 = kSCG_AsyncClkDivBy1, /* Slow IRC Clock Divider 3: divided by 1 */ | ||
348 | .range = kSCG_SircRangeHigh, /* Slow IRC high range clock (8 MHz) */ | ||
349 | }; | ||
350 | const scg_firc_config_t g_scgFircConfig_BOARD_BootClockHSRUN = { | ||
351 | .enableMode = kSCG_FircEnable, /* Enable FIRC clock */ | ||
352 | .div1 = kSCG_AsyncClkDivBy1, /* Fast IRC Clock Divider 1: divided by 1 */ | ||
353 | .div3 = kSCG_AsyncClkDivBy1, /* Fast IRC Clock Divider 3: divided by 1 */ | ||
354 | .range = kSCG_FircRange48M, /* Fast IRC is trimmed to 48MHz */ | ||
355 | .trimConfig = NULL, /* Fast IRC Trim disabled */ | ||
356 | }; | ||
357 | const scg_spll_config_t g_scgSysPllConfig_BOARD_BootClockHSRUN = { | ||
358 | .enableMode = kSCG_SysPllEnable, /* Enable SPLL clock */ | ||
359 | .monitorMode = kSCG_SysPllMonitorDisable, /* Monitor disabled */ | ||
360 | .div1 = kSCG_AsyncClkDivBy1, /* System PLL Clock Divider 1: divided by 1 */ | ||
361 | .div3 = kSCG_AsyncClkDivBy1, /* System PLL Clock Divider 3: divided by 1 */ | ||
362 | .src = kSCG_SysPllSrcFirc, /* System PLL clock source is Fast IRC */ | ||
363 | .prediv = 3, /* Divided by 4 */ | ||
364 | .mult = 0, /* Multiply Factor is 16 */ | ||
365 | }; | ||
366 | /******************************************************************************* | ||
367 | * Code for BOARD_BootClockHSRUN configuration | ||
368 | ******************************************************************************/ | ||
369 | void BOARD_BootClockHSRUN(void) | ||
370 | { | ||
371 | scg_sys_clk_config_t curConfig; | ||
372 | /* In HSRUN mode, the maximum allowable change in frequency of the system/bus/core/flash is | ||
373 | * restricted to x2, to follow this restriction, enter HSRUN mode should follow: | ||
374 | * 1.set the run mode to a safe configurations. | ||
375 | * 2.set the PLL or FLL output target frequency for HSRUN mode. | ||
376 | * 3.switch RUN mode configuration. | ||
377 | * 4.switch to HSRUN mode. | ||
378 | * 5.switch to HSRUN mode target requency value. | ||
379 | */ | ||
380 | /* Init SOSC according to board configuration. */ | ||
381 | CLOCK_InitSysOsc(&g_scgSysOscConfig_BOARD_BootClockHSRUN); | ||
382 | /* Set the XTAL0 frequency based on board settings. */ | ||
383 | CLOCK_SetXtal0Freq(g_scgSysOscConfig_BOARD_BootClockHSRUN.freq); | ||
384 | /* Init FIRC. */ | ||
385 | CLOCK_CONFIG_FircSafeConfig(&g_scgFircConfig_BOARD_BootClockHSRUN); | ||
386 | |||
387 | /* Init SysPll. */ | ||
388 | CLOCK_InitSysPll(&g_scgSysPllConfig_BOARD_BootClockHSRUN); | ||
389 | |||
390 | /* switch run mode core clock source and set run mode divider | ||
391 | to make sure core frequency not overflow */ | ||
392 | CLOCK_SetRunModeSysClkConfig(&g_sysClkConfig_BOARD_BootClockRunToHSRUN); | ||
393 | |||
394 | /* Set HSRUN power mode. */ | ||
395 | SMC_SetPowerModeProtection(SMC, kSMC_AllowPowerModeAll); | ||
396 | SMC_SetPowerModeHsrun(SMC); | ||
397 | while (SMC_GetPowerModeState(SMC) != kSMC_PowerStateHsrun) | ||
398 | { | ||
399 | } | ||
400 | |||
401 | /* Set SCG to SPLL mode. */ | ||
402 | CLOCK_SetHsrunModeSysClkConfig(&g_sysClkConfig_BOARD_BootClockHSRUN); | ||
403 | /* Wait for clock source switch finished. */ | ||
404 | do | ||
405 | { | ||
406 | CLOCK_GetCurSysClkConfig(&curConfig); | ||
407 | } while (curConfig.src != g_sysClkConfig_BOARD_BootClockHSRUN.src); | ||
408 | /* Init SIRC. */ | ||
409 | CLOCK_InitSirc(&g_scgSircConfig_BOARD_BootClockHSRUN); | ||
410 | /* Set SystemCoreClock variable. */ | ||
411 | SystemCoreClock = BOARD_BOOTCLOCKHSRUN_CORE_CLOCK; | ||
412 | /* Set SCG CLKOUT selection. */ | ||
413 | CLOCK_CONFIG_SetScgOutSel(SCG_CLKOUTCNFG_SIRC); | ||
414 | } | ||
415 | |||
416 | /******************************************************************************* | ||
417 | ********************* Configuration BOARD_BootClockVLPR *********************** | ||
418 | ******************************************************************************/ | ||
419 | /* clang-format off */ | ||
420 | /* TEXT BELOW IS USED AS SETTING FOR TOOLS ************************************* | ||
421 | !!Configuration | ||
422 | name: BOARD_BootClockVLPR | ||
423 | outputs: | ||
424 | - {id: Core_clock.outFreq, value: 8 MHz, locked: true, accuracy: '0.001'} | ||
425 | - {id: LPO_clock.outFreq, value: 1 kHz} | ||
426 | - {id: SIRC_CLK.outFreq, value: 8 MHz} | ||
427 | - {id: Slow_clock.outFreq, value: 1 MHz, locked: true, accuracy: '0.001'} | ||
428 | - {id: System_clock.outFreq, value: 8 MHz} | ||
429 | settings: | ||
430 | - {id: SCGMode, value: SIRC} | ||
431 | - {id: powerMode, value: VLPR} | ||
432 | - {id: SCG.DIVSLOW.scale, value: '8'} | ||
433 | - {id: SCG.SCSSEL.sel, value: SCG.SIRC} | ||
434 | - {id: 'SCG::RCCR[DIVSLOW].bitField', value: Divide-by-8} | ||
435 | - {id: 'SCG::RCCR[SCS].bitField', value: Slow IRC (SIRC_CLK)} | ||
436 | - {id: SCG_FIRCCSR_FIRCLPEN_CFG, value: Enabled} | ||
437 | sources: | ||
438 | - {id: SCG.SOSC.outFreq, value: 32.768 kHz, enabled: true} | ||
439 | * BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR TOOLS **********/ | ||
440 | /* clang-format on */ | ||
441 | |||
442 | /******************************************************************************* | ||
443 | * Variables for BOARD_BootClockVLPR configuration | ||
444 | ******************************************************************************/ | ||
445 | const scg_sys_clk_config_t g_sysClkConfig_BOARD_BootClockVLPR = { | ||
446 | .divSlow = kSCG_SysClkDivBy8, /* Slow Clock Divider: divided by 8 */ | ||
447 | #if FSL_CLOCK_DRIVER_VERSION < MAKE_VERSION(2, 1, 1) | ||
448 | .reserved1 = 0, | ||
449 | .reserved2 = 0, | ||
450 | .reserved3 = 0, | ||
451 | #endif | ||
452 | .divCore = kSCG_SysClkDivBy1, /* Core Clock Divider: divided by 1 */ | ||
453 | #if FSL_CLOCK_DRIVER_VERSION < MAKE_VERSION(2, 1, 1) | ||
454 | .reserved4 = 0, | ||
455 | #endif | ||
456 | .src = kSCG_SysClkSrcSirc, /* Slow IRC is selected as System Clock Source */ | ||
457 | #if FSL_CLOCK_DRIVER_VERSION < MAKE_VERSION(2, 1, 1) | ||
458 | .reserved5 = 0, | ||
459 | #endif | ||
460 | }; | ||
461 | const scg_sosc_config_t g_scgSysOscConfig_BOARD_BootClockVLPR = { | ||
462 | .freq = 0U, /* System Oscillator frequency: 0Hz */ | ||
463 | .enableMode = SCG_SOSC_DISABLE, /* System OSC disabled */ | ||
464 | .monitorMode = kSCG_SysOscMonitorDisable, /* Monitor disabled */ | ||
465 | .div1 = kSCG_AsyncClkDisable, /* System OSC Clock Divider 1: Clock output is disabled */ | ||
466 | .div3 = kSCG_AsyncClkDisable, /* System OSC Clock Divider 3: Clock output is disabled */ | ||
467 | .capLoad = SCG_SYS_OSC_CAP_0P, /* Oscillator capacity load: 0pF */ | ||
468 | .workMode = kSCG_SysOscModeExt, /* Use external clock */ | ||
469 | }; | ||
470 | const scg_sirc_config_t g_scgSircConfig_BOARD_BootClockVLPR = { | ||
471 | .enableMode = kSCG_SircEnable | kSCG_SircEnableInLowPower, /* Enable SIRC clock, Enable SIRC in low power mode */ | ||
472 | .div1 = kSCG_AsyncClkDisable, /* Slow IRC Clock Divider 1: Clock output is disabled */ | ||
473 | .div3 = kSCG_AsyncClkDisable, /* Slow IRC Clock Divider 3: Clock output is disabled */ | ||
474 | .range = kSCG_SircRangeHigh, /* Slow IRC high range clock (8 MHz) */ | ||
475 | }; | ||
476 | const scg_firc_config_t g_scgFircConfig_BOARD_BootClockVLPR = { | ||
477 | .enableMode = kSCG_FircEnable | kSCG_FircEnableInLowPower, /* Enable FIRC clock, Enable FIRC in low power mode */ | ||
478 | .div1 = kSCG_AsyncClkDisable, /* Fast IRC Clock Divider 1: Clock output is disabled */ | ||
479 | .div3 = kSCG_AsyncClkDisable, /* Fast IRC Clock Divider 3: Clock output is disabled */ | ||
480 | .range = kSCG_FircRange48M, /* Fast IRC is trimmed to 48MHz */ | ||
481 | .trimConfig = NULL, /* Fast IRC Trim disabled */ | ||
482 | }; | ||
483 | const scg_spll_config_t g_scgSysPllConfig_BOARD_BootClockVLPR = { | ||
484 | .enableMode = SCG_SPLL_DISABLE, /* System PLL disabled */ | ||
485 | .monitorMode = kSCG_SysPllMonitorDisable, /* Monitor disabled */ | ||
486 | .div1 = kSCG_AsyncClkDisable, /* System PLL Clock Divider 1: Clock output is disabled */ | ||
487 | .div3 = kSCG_AsyncClkDisable, /* System PLL Clock Divider 3: Clock output is disabled */ | ||
488 | .src = kSCG_SysPllSrcSysOsc, /* System PLL clock source is System OSC */ | ||
489 | .prediv = 0, /* Divided by 1 */ | ||
490 | .mult = 0, /* Multiply Factor is 16 */ | ||
491 | }; | ||
492 | /******************************************************************************* | ||
493 | * Code for BOARD_BootClockVLPR configuration | ||
494 | ******************************************************************************/ | ||
495 | void BOARD_BootClockVLPR(void) | ||
496 | { | ||
497 | /* Init FIRC. */ | ||
498 | CLOCK_CONFIG_FircSafeConfig(&g_scgFircConfig_BOARD_BootClockVLPR); | ||
499 | /* Init SIRC. */ | ||
500 | CLOCK_InitSirc(&g_scgSircConfig_BOARD_BootClockVLPR); | ||
501 | /* Allow SMC all power modes. */ | ||
502 | SMC_SetPowerModeProtection(SMC, kSMC_AllowPowerModeAll); | ||
503 | /* Set VLPR power mode. */ | ||
504 | SMC_SetPowerModeVlpr(SMC); | ||
505 | while (SMC_GetPowerModeState(SMC) != kSMC_PowerStateVlpr) | ||
506 | { | ||
507 | } | ||
508 | /* Set SystemCoreClock variable. */ | ||
509 | SystemCoreClock = BOARD_BOOTCLOCKVLPR_CORE_CLOCK; | ||
510 | } | ||