aboutsummaryrefslogtreecommitdiff
path: root/lib/chibios-contrib/ext/mcux-sdk/devices/LPC55S16/project_template/clock_config.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/chibios-contrib/ext/mcux-sdk/devices/LPC55S16/project_template/clock_config.c')
-rw-r--r--lib/chibios-contrib/ext/mcux-sdk/devices/LPC55S16/project_template/clock_config.c369
1 files changed, 369 insertions, 0 deletions
diff --git a/lib/chibios-contrib/ext/mcux-sdk/devices/LPC55S16/project_template/clock_config.c b/lib/chibios-contrib/ext/mcux-sdk/devices/LPC55S16/project_template/clock_config.c
new file mode 100644
index 000000000..bb4352e37
--- /dev/null
+++ b/lib/chibios-contrib/ext/mcux-sdk/devices/LPC55S16/project_template/clock_config.c
@@ -0,0 +1,369 @@
1/*
2 * Copyright 2017-2018 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
27product: Clocks v6.0
28processor: LPC55S16
29package_id: LPC55S16JBD100
30mcu_data: ksdk2_0
31processor_version: 0.0.4
32board: LPCXpresso55S16
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. */
48extern uint32_t SystemCoreClock;
49
50/*******************************************************************************
51 ************************ BOARD_InitBootClocks function ************************
52 ******************************************************************************/
53void 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
64name: BOARD_BootClockFRO12M
65outputs:
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 ******************************************************************************/
77void BOARD_BootClockFRO12M(void)
78{
79#ifndef SDK_SECONDARY_CORE
80 /*!< Set up the clock sources */
81 /*!< Configure FRO192M */
82 POWER_DisablePD(kPDRUNCFG_PD_FRO192M); /*!< Ensure FRO is on */
83 CLOCK_SetupFROClocking(12000000U); /*!< Set up FRO to the 12 MHz, just for sure */
84 CLOCK_AttachClk(kFRO12M_to_MAIN_CLK); /*!< Switch to FRO 12MHz first to ensure we can change the clock setting */
85
86 POWER_SetVoltageForFreq(12000000U); /*!< Set voltage for the one of the fastest clock outputs: System clock output */
87 CLOCK_SetFLASHAccessCyclesForFreq(12000000U); /*!< Set FLASH wait states for core */
88
89 /*!< Set up dividers */
90 CLOCK_SetClkDiv(kCLOCK_DivAhbClk, 1U, false); /*!< Set AHBCLKDIV divider to value 1 */
91
92 /*!< Set up clock selectors - Attach clocks to the peripheries */
93 CLOCK_AttachClk(kFRO12M_to_MAIN_CLK); /*!< Switch MAIN_CLK to FRO12M */
94
95 /*< Set SystemCoreClock variable. */
96 SystemCoreClock = BOARD_BOOTCLOCKFRO12M_CORE_CLOCK;
97#endif
98}
99
100/*******************************************************************************
101 ******************* Configuration BOARD_BootClockFROHF96M *********************
102 ******************************************************************************/
103/* clang-format off */
104/* TEXT BELOW IS USED AS SETTING FOR TOOLS *************************************
105!!Configuration
106name: BOARD_BootClockFROHF96M
107outputs:
108- {id: FRO_12MHz_clock.outFreq, value: 12 MHz}
109- {id: System_clock.outFreq, value: 96 MHz}
110settings:
111- {id: ANALOG_CONTROL_FRO192M_CTRL_ENDI_FRO_96M_CFG, value: Enable}
112- {id: SYSCON.MAINCLKSELA.sel, value: ANACTRL.fro_hf_clk}
113sources:
114- {id: ANACTRL.fro_hf.outFreq, value: 96 MHz}
115 * BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR TOOLS **********/
116/* clang-format on */
117
118/*******************************************************************************
119 * Variables for BOARD_BootClockFROHF96M configuration
120 ******************************************************************************/
121/*******************************************************************************
122 * Code for BOARD_BootClockFROHF96M configuration
123 ******************************************************************************/
124void BOARD_BootClockFROHF96M(void)
125{
126#ifndef SDK_SECONDARY_CORE
127 /*!< Set up the clock sources */
128 /*!< Configure FRO192M */
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
155name: BOARD_BootClockPLL100M
156outputs:
157- {id: FRO_12MHz_clock.outFreq, value: 12 MHz}
158- {id: System_clock.outFreq, value: 100 MHz}
159settings:
160- {id: PLL0_Mode, value: Normal}
161- {id: ENABLE_CLKIN_ENA, value: Enabled}
162- {id: ENABLE_SYSTEM_CLK_OUT, value: Enabled}
163- {id: SYSCON.MAINCLKSELB.sel, value: SYSCON.PLL0_BYPASS}
164- {id: SYSCON.PLL0CLKSEL.sel, value: SYSCON.CLK_IN_EN}
165- {id: SYSCON.PLL0M_MULT.scale, value: '100', locked: true}
166- {id: SYSCON.PLL0N_DIV.scale, value: '4', locked: true}
167sources:
168- {id: SYSCON.XTAL32M.outFreq, value: 16 MHz, enabled: true}
169 * BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR TOOLS **********/
170/* clang-format on */
171
172/*******************************************************************************
173 * Variables for BOARD_BootClockPLL100M configuration
174 ******************************************************************************/
175/*******************************************************************************
176 * Code for BOARD_BootClockPLL100M configuration
177 ******************************************************************************/
178void BOARD_BootClockPLL100M(void)
179{
180#ifndef SDK_SECONDARY_CORE
181 /*!< Set up the clock sources */
182 /*!< Configure FRO192M */
183 POWER_DisablePD(kPDRUNCFG_PD_FRO192M); /*!< Ensure FRO is on */
184 CLOCK_SetupFROClocking(12000000U); /*!< Set up FRO to the 12 MHz, just for sure */
185 CLOCK_AttachClk(kFRO12M_to_MAIN_CLK); /*!< Switch to FRO 12MHz first to ensure we can change the clock setting */
186
187 /*!< Configure XTAL32M */
188 POWER_DisablePD(kPDRUNCFG_PD_XTAL32M); /* Ensure XTAL32M is powered */
189 POWER_DisablePD(kPDRUNCFG_PD_LDOXO32M); /* Ensure XTAL32M is powered */
190 CLOCK_SetupExtClocking(16000000U); /* Enable clk_in clock */
191 SYSCON->CLOCK_CTRL |= SYSCON_CLOCK_CTRL_CLKIN_ENA_MASK; /* Enable clk_in from XTAL32M clock */
192 ANACTRL->XO32M_CTRL |= ANACTRL_XO32M_CTRL_ENABLE_SYSTEM_CLK_OUT_MASK; /* Enable clk_in to system */
193
194 POWER_SetVoltageForFreq(100000000U); /*!< Set voltage for the one of the fastest clock outputs: System clock output */
195 CLOCK_SetFLASHAccessCyclesForFreq(100000000U); /*!< Set FLASH wait states for core */
196
197 /*!< Set up PLL */
198 CLOCK_AttachClk(kEXT_CLK_to_PLL0); /*!< Switch PLL0CLKSEL to EXT_CLK */
199 POWER_DisablePD(kPDRUNCFG_PD_PLL0); /* Ensure PLL is on */
200 POWER_DisablePD(kPDRUNCFG_PD_PLL0_SSCG);
201 const pll_setup_t pll0Setup = {
202 .pllctrl = SYSCON_PLL0CTRL_CLKEN_MASK | SYSCON_PLL0CTRL_SELI(53U) | SYSCON_PLL0CTRL_SELP(26U),
203 .pllndec = SYSCON_PLL0NDEC_NDIV(4U),
204 .pllpdec = SYSCON_PLL0PDEC_PDIV(2U),
205 .pllsscg = {0x0U,(SYSCON_PLL0SSCG1_MDIV_EXT(100U) | SYSCON_PLL0SSCG1_SEL_EXT_MASK)},
206 .pllRate = 100000000U,
207 .flags = PLL_SETUPFLAG_WAITLOCK
208 };
209 CLOCK_SetPLL0Freq(&pll0Setup); /*!< Configure PLL0 to the desired values */
210
211 /*!< Set up dividers */
212 CLOCK_SetClkDiv(kCLOCK_DivAhbClk, 1U, false); /*!< Set AHBCLKDIV divider to value 1 */
213
214 /*!< Set up clock selectors - Attach clocks to the peripheries */
215 CLOCK_AttachClk(kPLL0_to_MAIN_CLK); /*!< Switch MAIN_CLK to PLL0 */
216
217 /*< Set SystemCoreClock variable. */
218 SystemCoreClock = BOARD_BOOTCLOCKPLL100M_CORE_CLOCK;
219#endif
220}
221
222/*******************************************************************************
223 ******************** Configuration BOARD_BootClockPLL150M *********************
224 ******************************************************************************/
225/* clang-format off */
226/* TEXT BELOW IS USED AS SETTING FOR TOOLS *************************************
227!!Configuration
228name: BOARD_BootClockPLL150M
229called_from_default_init: true
230outputs:
231- {id: FRO_12MHz_clock.outFreq, value: 12 MHz}
232- {id: System_clock.outFreq, value: 150 MHz}
233settings:
234- {id: PLL0_Mode, value: Normal}
235- {id: ENABLE_CLKIN_ENA, value: Enabled}
236- {id: ENABLE_SYSTEM_CLK_OUT, value: Enabled}
237- {id: SYSCON.MAINCLKSELB.sel, value: SYSCON.PLL0_BYPASS}
238- {id: SYSCON.PLL0CLKSEL.sel, value: SYSCON.CLK_IN_EN}
239- {id: SYSCON.PLL0M_MULT.scale, value: '150', locked: true}
240- {id: SYSCON.PLL0N_DIV.scale, value: '8', locked: true}
241- {id: SYSCON.PLL0_PDEC.scale, value: '2', locked: true}
242sources:
243- {id: SYSCON.XTAL32M.outFreq, value: 16 MHz, enabled: true}
244 * BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR TOOLS **********/
245/* clang-format on */
246
247/*******************************************************************************
248 * Variables for BOARD_BootClockPLL150M configuration
249 ******************************************************************************/
250/*******************************************************************************
251 * Code for BOARD_BootClockPLL150M configuration
252 ******************************************************************************/
253void BOARD_BootClockPLL150M(void)
254{
255#ifndef SDK_SECONDARY_CORE
256 /*!< Set up the clock sources */
257 /*!< Configure FRO192M */
258 POWER_DisablePD(kPDRUNCFG_PD_FRO192M); /*!< Ensure FRO is on */
259 CLOCK_SetupFROClocking(12000000U); /*!< Set up FRO to the 12 MHz, just for sure */
260 CLOCK_AttachClk(kFRO12M_to_MAIN_CLK); /*!< Switch to FRO 12MHz first to ensure we can change the clock setting */
261
262 /*!< Configure XTAL32M */
263 POWER_DisablePD(kPDRUNCFG_PD_XTAL32M); /* Ensure XTAL32M is powered */
264 POWER_DisablePD(kPDRUNCFG_PD_LDOXO32M); /* Ensure XTAL32M is powered */
265 CLOCK_SetupExtClocking(16000000U); /* Enable clk_in clock */
266 SYSCON->CLOCK_CTRL |= SYSCON_CLOCK_CTRL_CLKIN_ENA_MASK; /* Enable clk_in from XTAL32M clock */
267 ANACTRL->XO32M_CTRL |= ANACTRL_XO32M_CTRL_ENABLE_SYSTEM_CLK_OUT_MASK; /* Enable clk_in to system */
268
269 POWER_SetVoltageForFreq(150000000U); /*!< Set voltage for the one of the fastest clock outputs: System clock output */
270 CLOCK_SetFLASHAccessCyclesForFreq(150000000U); /*!< Set FLASH wait states for core */
271
272 /*!< Set up PLL */
273 CLOCK_AttachClk(kEXT_CLK_to_PLL0); /*!< Switch PLL0CLKSEL to EXT_CLK */
274 POWER_DisablePD(kPDRUNCFG_PD_PLL0); /* Ensure PLL is on */
275 POWER_DisablePD(kPDRUNCFG_PD_PLL0_SSCG);
276 const pll_setup_t pll0Setup = {
277 .pllctrl = SYSCON_PLL0CTRL_CLKEN_MASK | SYSCON_PLL0CTRL_SELI(53U) | SYSCON_PLL0CTRL_SELP(31U),
278 .pllndec = SYSCON_PLL0NDEC_NDIV(8U),
279 .pllpdec = SYSCON_PLL0PDEC_PDIV(1U),
280 .pllsscg = {0x0U,(SYSCON_PLL0SSCG1_MDIV_EXT(150U) | SYSCON_PLL0SSCG1_SEL_EXT_MASK)},
281 .pllRate = 150000000U,
282 .flags = PLL_SETUPFLAG_WAITLOCK
283 };
284 CLOCK_SetPLL0Freq(&pll0Setup); /*!< Configure PLL0 to the desired values */
285
286 /*!< Set up dividers */
287 CLOCK_SetClkDiv(kCLOCK_DivAhbClk, 1U, false); /*!< Set AHBCLKDIV divider to value 1 */
288
289 /*!< Set up clock selectors - Attach clocks to the peripheries */
290 CLOCK_AttachClk(kPLL0_to_MAIN_CLK); /*!< Switch MAIN_CLK to PLL0 */
291
292 /*< Set SystemCoreClock variable. */
293 SystemCoreClock = BOARD_BOOTCLOCKPLL150M_CORE_CLOCK;
294#endif
295}
296
297/*******************************************************************************
298 ******************* Configuration BOARD_BootClockPLL1_150M ********************
299 ******************************************************************************/
300/* clang-format off */
301/* TEXT BELOW IS USED AS SETTING FOR TOOLS *************************************
302!!Configuration
303name: BOARD_BootClockPLL1_150M
304outputs:
305- {id: FRO_12MHz_clock.outFreq, value: 12 MHz}
306- {id: System_clock.outFreq, value: 150 MHz}
307settings:
308- {id: PLL1_Mode, value: Normal}
309- {id: ENABLE_CLKIN_ENA, value: Enabled}
310- {id: ENABLE_SYSTEM_CLK_OUT, value: Enabled}
311- {id: SYSCON.MAINCLKSELB.sel, value: SYSCON.PLL1_BYPASS}
312- {id: SYSCON.PLL1CLKSEL.sel, value: SYSCON.CLK_IN_EN}
313- {id: SYSCON.PLL1M_MULT.scale, value: '150', locked: true}
314- {id: SYSCON.PLL1N_DIV.scale, value: '8', locked: true}
315- {id: SYSCON.PLL1_PDEC.scale, value: '2', locked: true}
316sources:
317- {id: SYSCON.XTAL32M.outFreq, value: 16 MHz, enabled: true}
318 * BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR TOOLS **********/
319/* clang-format on */
320
321/*******************************************************************************
322 * Variables for BOARD_BootClockPLL1_150M configuration
323 ******************************************************************************/
324/*******************************************************************************
325 * Code for BOARD_BootClockPLL1_150M configuration
326 ******************************************************************************/
327void BOARD_BootClockPLL1_150M(void)
328{
329#ifndef SDK_SECONDARY_CORE
330 /*!< Set up the clock sources */
331 /*!< Configure FRO192M */
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 /*!< Configure XTAL32M */
337 POWER_DisablePD(kPDRUNCFG_PD_XTAL32M); /* Ensure XTAL32M is powered */
338 POWER_DisablePD(kPDRUNCFG_PD_LDOXO32M); /* Ensure XTAL32M is powered */
339 CLOCK_SetupExtClocking(16000000U); /* Enable clk_in clock */
340 SYSCON->CLOCK_CTRL |= SYSCON_CLOCK_CTRL_CLKIN_ENA_MASK; /* Enable clk_in from XTAL32M clock */
341 ANACTRL->XO32M_CTRL |= ANACTRL_XO32M_CTRL_ENABLE_SYSTEM_CLK_OUT_MASK; /* Enable clk_in to system */
342
343 POWER_SetVoltageForFreq(150000000U); /*!< Set voltage for the one of the fastest clock outputs: System clock output */
344 CLOCK_SetFLASHAccessCyclesForFreq(150000000U); /*!< Set FLASH wait states for core */
345
346 /*!< Set up PLL1 */
347 CLOCK_AttachClk(kEXT_CLK_to_PLL1); /*!< Switch PLL1CLKSEL to EXT_CLK */
348 POWER_DisablePD(kPDRUNCFG_PD_PLL1); /* Ensure PLL is on */
349 const pll_setup_t pll1Setup = {
350 .pllctrl = SYSCON_PLL1CTRL_CLKEN_MASK | SYSCON_PLL1CTRL_SELI(53U) | SYSCON_PLL1CTRL_SELP(31U),
351 .pllndec = SYSCON_PLL1NDEC_NDIV(8U),
352 .pllpdec = SYSCON_PLL1PDEC_PDIV(1U),
353 .pllmdec = SYSCON_PLL1MDEC_MDIV(150U),
354 .pllRate = 150000000U,
355 .flags = PLL_SETUPFLAG_WAITLOCK
356 };
357 CLOCK_SetPLL1Freq(&pll1Setup); /*!< Configure PLL1 to the desired values */
358
359 /*!< Set up dividers */
360 CLOCK_SetClkDiv(kCLOCK_DivAhbClk, 1U, false); /*!< Set AHBCLKDIV divider to value 1 */
361
362 /*!< Set up clock selectors - Attach clocks to the peripheries */
363 CLOCK_AttachClk(kPLL1_to_MAIN_CLK); /*!< Switch MAIN_CLK to PLL1 */
364
365 /*< Set SystemCoreClock variable. */
366 SystemCoreClock = BOARD_BOOTCLOCKPLL1_150M_CORE_CLOCK;
367#endif
368}
369