diff options
Diffstat (limited to 'lib/chibios-contrib/ext/mcux-sdk/boards/hvpkv11z75m/clock_config.c')
-rw-r--r-- | lib/chibios-contrib/ext/mcux-sdk/boards/hvpkv11z75m/clock_config.c | 259 |
1 files changed, 259 insertions, 0 deletions
diff --git a/lib/chibios-contrib/ext/mcux-sdk/boards/hvpkv11z75m/clock_config.c b/lib/chibios-contrib/ext/mcux-sdk/boards/hvpkv11z75m/clock_config.c new file mode 100644 index 000000000..9d0c2c500 --- /dev/null +++ b/lib/chibios-contrib/ext/mcux-sdk/boards/hvpkv11z75m/clock_config.c | |||
@@ -0,0 +1,259 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2015, Freescale Semiconductor, Inc. | ||
3 | * Copyright 2016-2017 NXP | ||
4 | * All rights reserved. | ||
5 | * | ||
6 | * SPDX-License-Identifier: BSD-3-Clause | ||
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 setup clock using clock driver functions: | ||
14 | * | ||
15 | * 1. CLOCK_SetSimSafeDivs, to make sure core clock, bus clock, flexbus clock | ||
16 | * and flash clock are in allowed range during clock mode switch. | ||
17 | * | ||
18 | * 2. Call CLOCK_Osc0Init to setup OSC clock, if it is used in target mode. | ||
19 | * | ||
20 | * 3. Set MCG configuration, MCG includes three parts: FLL clock, PLL clock and | ||
21 | * internal reference clock(MCGIRCLK). Follow the steps to setup: | ||
22 | * | ||
23 | * 1). Call CLOCK_BootToXxxMode to set MCG to target mode. | ||
24 | * | ||
25 | * 2). If target mode is FBI/BLPI/PBI mode, the MCGIRCLK has been configured | ||
26 | * correctly. For other modes, need to call CLOCK_SetInternalRefClkConfig | ||
27 | * explicitly to setup MCGIRCLK. | ||
28 | * | ||
29 | * 3). Don't need to configure FLL explicitly, because if target mode is FLL | ||
30 | * mode, then FLL has been configured by the function CLOCK_BootToXxxMode, | ||
31 | * if the target mode is not FLL mode, the FLL is disabled. | ||
32 | * | ||
33 | * 4). If target mode is PEE/PBE/PEI/PBI mode, then the related PLL has been | ||
34 | * setup by CLOCK_BootToXxxMode. In FBE/FBI/FEE/FBE mode, the PLL could | ||
35 | * be enabled independently, call CLOCK_EnablePll0 explicitly in this case. | ||
36 | * | ||
37 | * 4. Call CLOCK_SetSimConfig to set the clock configuration in SIM. | ||
38 | */ | ||
39 | |||
40 | /* clang-format off */ | ||
41 | /* TEXT BELOW IS USED AS SETTING FOR TOOLS ************************************* | ||
42 | !!GlobalInfo | ||
43 | product: Clocks v4.0 | ||
44 | processor: MKV11Z128xxx7 | ||
45 | package_id: MKV11Z128VLF7 | ||
46 | mcu_data: ksdk2_0 | ||
47 | processor_version: 0.0.4 | ||
48 | * BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR TOOLS **********/ | ||
49 | /* clang-format on */ | ||
50 | |||
51 | #include "fsl_smc.h" | ||
52 | #include "clock_config.h" | ||
53 | |||
54 | /******************************************************************************* | ||
55 | * Definitions | ||
56 | ******************************************************************************/ | ||
57 | #define OSC_CAP0P 0U /*!< Oscillator 0pF capacitor load */ | ||
58 | #define OSC_ER_CLK_DISABLE 0U /*!< Disable external reference clock */ | ||
59 | #define SIM_OSC32KSEL_LPO_CLK 3U /*!< OSC32KSEL select: LPO clock */ | ||
60 | |||
61 | /******************************************************************************* | ||
62 | * Variables | ||
63 | ******************************************************************************/ | ||
64 | /* System clock frequency. */ | ||
65 | extern uint32_t SystemCoreClock; | ||
66 | |||
67 | /******************************************************************************* | ||
68 | * Code | ||
69 | ******************************************************************************/ | ||
70 | /*FUNCTION********************************************************************** | ||
71 | * | ||
72 | * Function Name : CLOCK_CONFIG_FllStableDelay | ||
73 | * Description : This function is used to delay for FLL stable. | ||
74 | * | ||
75 | *END**************************************************************************/ | ||
76 | static void CLOCK_CONFIG_FllStableDelay(void) | ||
77 | { | ||
78 | uint32_t i = 30000U; | ||
79 | while (i--) | ||
80 | { | ||
81 | __NOP(); | ||
82 | } | ||
83 | } | ||
84 | |||
85 | /******************************************************************************* | ||
86 | ************************ BOARD_InitBootClocks function ************************ | ||
87 | ******************************************************************************/ | ||
88 | void BOARD_InitBootClocks(void) | ||
89 | { | ||
90 | BOARD_BootClockRUN(); | ||
91 | } | ||
92 | |||
93 | /******************************************************************************* | ||
94 | ********************** Configuration BOARD_BootClockRUN *********************** | ||
95 | ******************************************************************************/ | ||
96 | /* clang-format off */ | ||
97 | /* TEXT BELOW IS USED AS SETTING FOR TOOLS ************************************* | ||
98 | !!Configuration | ||
99 | name: BOARD_BootClockRUN | ||
100 | called_from_default_init: true | ||
101 | outputs: | ||
102 | - {id: Bus_clock.outFreq, value: 20.97152 MHz} | ||
103 | - {id: Core_clock.outFreq, value: 62.91456 MHz} | ||
104 | - {id: ERCLK32K.outFreq, value: 1 kHz} | ||
105 | - {id: LPO_clock.outFreq, value: 1 kHz} | ||
106 | - {id: MCGFLLCLK.outFreq, value: 62.91456 MHz} | ||
107 | - {id: MCGIRCLK.outFreq, value: 32.768 kHz} | ||
108 | - {id: System_clock.outFreq, value: 62.91456 MHz} | ||
109 | settings: | ||
110 | - {id: MCG.FCRDIV.scale, value: '1', locked: true} | ||
111 | - {id: MCG.FLL_mul.scale, value: '1920', locked: true} | ||
112 | - {id: MCG.FRDIV.scale, value: '256'} | ||
113 | - {id: MCG_C1_IRCLKEN_CFG, value: Enabled} | ||
114 | - {id: MCG_C2_OSC_MODE_CFG, value: ModeOscLowPower} | ||
115 | - {id: MCG_C2_RANGE0_CFG, value: Very_high} | ||
116 | - {id: MCG_C2_RANGE0_FRDIV_CFG, value: Very_high} | ||
117 | - {id: OSC_CR_ERCLKEN_CFG, value: Enabled} | ||
118 | - {id: SIM.CLKOUTSEL.sel, value: SIM.OUTDIV4} | ||
119 | - {id: SIM.FTMFFCLKSEL.sel, value: OSC.OSCERCLK} | ||
120 | - {id: SIM.OSC32KSEL.sel, value: PMC.LPOCLK} | ||
121 | - {id: SIM.OUTDIV1.scale, value: '1', locked: true} | ||
122 | - {id: SIM.OUTDIV4.scale, value: '3', locked: true} | ||
123 | - {id: SIM.OUTDIV5.scale, value: '1'} | ||
124 | sources: | ||
125 | - {id: OSC.OSC.outFreq, value: 10 MHz} | ||
126 | * BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR TOOLS **********/ | ||
127 | /* clang-format on */ | ||
128 | |||
129 | /******************************************************************************* | ||
130 | * Variables for BOARD_BootClockRUN configuration | ||
131 | ******************************************************************************/ | ||
132 | const mcg_config_t mcgConfig_BOARD_BootClockRUN = { | ||
133 | .mcgMode = kMCG_ModeFEI, /* FEI - FLL Engaged Internal */ | ||
134 | .irclkEnableMode = kMCG_IrclkEnable, /* MCGIRCLK enabled, MCGIRCLK disabled in STOP mode */ | ||
135 | .ircs = kMCG_IrcSlow, /* Slow internal reference clock selected */ | ||
136 | .fcrdiv = 0x0U, /* Fast IRC divider: divided by 1 */ | ||
137 | .frdiv = 0x3U, /* FLL reference clock divider: divided by 256 */ | ||
138 | .drs = kMCG_DrsMidHigh, /* Mid-High frequency range */ | ||
139 | .dmx32 = kMCG_Dmx32Default, /* DCO has a default range of 25% */ | ||
140 | }; | ||
141 | const sim_clock_config_t simConfig_BOARD_BootClockRUN = { | ||
142 | .er32kSrc = SIM_OSC32KSEL_LPO_CLK, /* OSC32KSEL select: LPO clock */ | ||
143 | .clkdiv1 = 0x20000U, /* SIM_CLKDIV1 - OUTDIV1: /1, OUTDIV4: /3, OUTDIV5: /1, disabled */ | ||
144 | }; | ||
145 | const osc_config_t oscConfig_BOARD_BootClockRUN = { | ||
146 | .freq = 0U, /* Oscillator frequency: 0Hz */ | ||
147 | .capLoad = (OSC_CAP0P), /* Oscillator capacity load: 0pF */ | ||
148 | .workMode = kOSC_ModeOscLowPower, /* Oscillator low power */ | ||
149 | .oscerConfig = { | ||
150 | .enableMode = | ||
151 | kOSC_ErClkEnable, /* Enable external reference clock, disable external reference clock in STOP mode */ | ||
152 | }}; | ||
153 | |||
154 | /******************************************************************************* | ||
155 | * Code for BOARD_BootClockRUN configuration | ||
156 | ******************************************************************************/ | ||
157 | void BOARD_BootClockRUN(void) | ||
158 | { | ||
159 | /* Set the system clock dividers in SIM to safe value. */ | ||
160 | CLOCK_SetSimSafeDivs(); | ||
161 | /* Set MCG to FEI mode. */ | ||
162 | #if FSL_CLOCK_DRIVER_VERSION >= MAKE_VERSION(2, 2, 0) | ||
163 | CLOCK_BootToFeiMode(mcgConfig_BOARD_BootClockRUN.dmx32, mcgConfig_BOARD_BootClockRUN.drs, | ||
164 | CLOCK_CONFIG_FllStableDelay); | ||
165 | #else | ||
166 | CLOCK_BootToFeiMode(mcgConfig_BOARD_BootClockRUN.drs, CLOCK_CONFIG_FllStableDelay); | ||
167 | #endif | ||
168 | /* Configure the Internal Reference clock (MCGIRCLK). */ | ||
169 | CLOCK_SetInternalRefClkConfig(mcgConfig_BOARD_BootClockRUN.irclkEnableMode, mcgConfig_BOARD_BootClockRUN.ircs, | ||
170 | mcgConfig_BOARD_BootClockRUN.fcrdiv); | ||
171 | /* Set the clock configuration in SIM module. */ | ||
172 | CLOCK_SetSimConfig(&simConfig_BOARD_BootClockRUN); | ||
173 | /* Set SystemCoreClock variable. */ | ||
174 | SystemCoreClock = BOARD_BOOTCLOCKRUN_CORE_CLOCK; | ||
175 | } | ||
176 | |||
177 | /******************************************************************************* | ||
178 | ********************* Configuration BOARD_BootClockVLPR *********************** | ||
179 | ******************************************************************************/ | ||
180 | /* clang-format off */ | ||
181 | /* TEXT BELOW IS USED AS SETTING FOR TOOLS ************************************* | ||
182 | !!Configuration | ||
183 | name: BOARD_BootClockVLPR | ||
184 | outputs: | ||
185 | - {id: Bus_clock.outFreq, value: 800 kHz} | ||
186 | - {id: Core_clock.outFreq, value: 4 MHz} | ||
187 | - {id: ERCLK32K.outFreq, value: 1 kHz} | ||
188 | - {id: LPO_clock.outFreq, value: 1 kHz} | ||
189 | - {id: MCGIRCLK.outFreq, value: 4 MHz} | ||
190 | - {id: System_clock.outFreq, value: 4 MHz} | ||
191 | settings: | ||
192 | - {id: MCGMode, value: BLPI} | ||
193 | - {id: powerMode, value: VLPR} | ||
194 | - {id: MCG.CLKS.sel, value: MCG.IRCS} | ||
195 | - {id: MCG.FCRDIV.scale, value: '1', locked: true} | ||
196 | - {id: MCG.FRDIV.scale, value: '32'} | ||
197 | - {id: MCG.IRCS.sel, value: MCG.FCRDIV} | ||
198 | - {id: MCG_C1_IRCLKEN_CFG, value: Enabled} | ||
199 | - {id: MCG_C2_OSC_MODE_CFG, value: ModeOscLowPower} | ||
200 | - {id: MCG_C2_RANGE0_CFG, value: Very_high} | ||
201 | - {id: MCG_C2_RANGE0_FRDIV_CFG, value: Very_high} | ||
202 | - {id: SIM.OSC32KSEL.sel, value: PMC.LPOCLK} | ||
203 | - {id: SIM.OUTDIV1.scale, value: '1', locked: true} | ||
204 | - {id: SIM.OUTDIV4.scale, value: '5'} | ||
205 | - {id: SIM.OUTDIV5.scale, value: '1', locked: true} | ||
206 | sources: | ||
207 | - {id: OSC.OSC.outFreq, value: 10 MHz} | ||
208 | * BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR TOOLS **********/ | ||
209 | /* clang-format on */ | ||
210 | |||
211 | /******************************************************************************* | ||
212 | * Variables for BOARD_BootClockVLPR configuration | ||
213 | ******************************************************************************/ | ||
214 | const mcg_config_t mcgConfig_BOARD_BootClockVLPR = { | ||
215 | .mcgMode = kMCG_ModeBLPI, /* BLPI - Bypassed Low Power Internal */ | ||
216 | .irclkEnableMode = kMCG_IrclkEnable, /* MCGIRCLK enabled, MCGIRCLK disabled in STOP mode */ | ||
217 | .ircs = kMCG_IrcFast, /* Fast internal reference clock selected */ | ||
218 | .fcrdiv = 0x0U, /* Fast IRC divider: divided by 1 */ | ||
219 | .frdiv = 0x0U, /* FLL reference clock divider: divided by 32 */ | ||
220 | .drs = kMCG_DrsLow, /* Low frequency range */ | ||
221 | .dmx32 = kMCG_Dmx32Default, /* DCO has a default range of 25% */ | ||
222 | }; | ||
223 | const sim_clock_config_t simConfig_BOARD_BootClockVLPR = { | ||
224 | .er32kSrc = SIM_OSC32KSEL_LPO_CLK, /* OSC32KSEL select: LPO clock */ | ||
225 | .clkdiv1 = 0x40000U, /* SIM_CLKDIV1 - OUTDIV1: /1, OUTDIV4: /5, OUTDIV5: /1, disabled */ | ||
226 | }; | ||
227 | const osc_config_t oscConfig_BOARD_BootClockVLPR = { | ||
228 | .freq = 0U, /* Oscillator frequency: 0Hz */ | ||
229 | .capLoad = (OSC_CAP0P), /* Oscillator capacity load: 0pF */ | ||
230 | .workMode = kOSC_ModeOscLowPower, /* Oscillator low power */ | ||
231 | .oscerConfig = { | ||
232 | .enableMode = OSC_ER_CLK_DISABLE, /* Disable external reference clock */ | ||
233 | }}; | ||
234 | |||
235 | /******************************************************************************* | ||
236 | * Code for BOARD_BootClockVLPR configuration | ||
237 | ******************************************************************************/ | ||
238 | void BOARD_BootClockVLPR(void) | ||
239 | { | ||
240 | /* Set the system clock dividers in SIM to safe value. */ | ||
241 | CLOCK_SetSimSafeDivs(); | ||
242 | /* Set MCG to BLPI mode. */ | ||
243 | CLOCK_BootToBlpiMode(mcgConfig_BOARD_BootClockVLPR.fcrdiv, mcgConfig_BOARD_BootClockVLPR.ircs, | ||
244 | mcgConfig_BOARD_BootClockVLPR.irclkEnableMode); | ||
245 | /* Set the clock configuration in SIM module. */ | ||
246 | CLOCK_SetSimConfig(&simConfig_BOARD_BootClockVLPR); | ||
247 | /* Set VLPR power mode. */ | ||
248 | SMC_SetPowerModeProtection(SMC, kSMC_AllowPowerModeAll); | ||
249 | #if (defined(FSL_FEATURE_SMC_HAS_LPWUI) && FSL_FEATURE_SMC_HAS_LPWUI) | ||
250 | SMC_SetPowerModeVlpr(SMC, false); | ||
251 | #else | ||
252 | SMC_SetPowerModeVlpr(SMC); | ||
253 | #endif | ||
254 | while (SMC_GetPowerModeState(SMC) != kSMC_PowerStateVlpr) | ||
255 | { | ||
256 | } | ||
257 | /* Set SystemCoreClock variable. */ | ||
258 | SystemCoreClock = BOARD_BOOTCLOCKVLPR_CORE_CLOCK; | ||
259 | } | ||