aboutsummaryrefslogtreecommitdiff
path: root/lib/chibios-contrib/ext/mcux-sdk/boards/lpcxpresso51u68/clock_config.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/chibios-contrib/ext/mcux-sdk/boards/lpcxpresso51u68/clock_config.c')
-rw-r--r--lib/chibios-contrib/ext/mcux-sdk/boards/lpcxpresso51u68/clock_config.c243
1 files changed, 243 insertions, 0 deletions
diff --git a/lib/chibios-contrib/ext/mcux-sdk/boards/lpcxpresso51u68/clock_config.c b/lib/chibios-contrib/ext/mcux-sdk/boards/lpcxpresso51u68/clock_config.c
new file mode 100644
index 000000000..16f6e46fc
--- /dev/null
+++ b/lib/chibios-contrib/ext/mcux-sdk/boards/lpcxpresso51u68/clock_config.c
@@ -0,0 +1,243 @@
1/*
2 * Copyright (c) 2015, Freescale Semiconductor, Inc.
3 * Copyright 2016-2017,2019 NXP
4 * All rights reserved.
5 *
6 * SPDX-License-Identifier: BSD-3-Clause
7 */
8/*
9 * How to set up clock using clock driver functions:
10 *
11 * 1. Setup clock sources.
12 *
13 * 2. Setup voltage for the fastest of the clock outputs
14 *
15 * 3. Set up wait states of the flash.
16 *
17 * 4. Set up all dividers.
18 *
19 * 5. Set up all selectors to provide selected clocks.
20 */
21
22/* TEXT BELOW IS USED AS SETTING FOR TOOLS *************************************
23!!GlobalInfo
24product: Clocks v7.0
25processor: LPC51U68
26package_id: LPC51U68JBD64
27mcu_data: ksdk2_0
28processor_version: 0.7.1
29board: LPCXpresso51U68
30 * BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR TOOLS **********/
31
32#include "fsl_power.h"
33#include "fsl_clock.h"
34#include "clock_config.h"
35
36/*******************************************************************************
37 * Definitions
38 ******************************************************************************/
39
40/*******************************************************************************
41 * Variables
42 ******************************************************************************/
43/* System clock frequency. */
44extern uint32_t SystemCoreClock;
45
46/*******************************************************************************
47 ************************ BOARD_InitBootClocks function ************************
48 ******************************************************************************/
49void BOARD_InitBootClocks(void)
50{
51 BOARD_BootClockPLL150M();
52}
53
54/*******************************************************************************
55 ******************** Configuration BOARD_BootClockFRO12M **********************
56 ******************************************************************************/
57/* TEXT BELOW IS USED AS SETTING FOR TOOLS *************************************
58!!Configuration
59name: BOARD_BootClockFRO12M
60outputs:
61- {id: System_clock.outFreq, value: 12 MHz}
62 * BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR TOOLS **********/
63
64/*******************************************************************************
65 * Variables for BOARD_BootClockFRO12M configuration
66 ******************************************************************************/
67/*******************************************************************************
68 * Code for BOARD_BootClockFRO12M configuration
69 ******************************************************************************/
70void BOARD_BootClockFRO12M(void)
71{
72 /*!< Set up the clock sources */
73 /*!< Set up FRO */
74 POWER_DisablePD(kPDRUNCFG_PD_FRO_EN); /*!< Ensure FRO is on */
75 CLOCK_SetupFROClocking(12000000U); /*!< Set up FRO to the 12 MHz, just for sure */
76 CLOCK_AttachClk(kFRO12M_to_MAIN_CLK); /*!< Switch to FRO 12MHz first to ensure we can change voltage without
77 accidentally being below the voltage for current speed */
78 POWER_SetVoltageForFreq(
79 12000000U); /*!< Set voltage for the one of the fastest clock outputs: System clock output */
80 CLOCK_SetFLASHAccessCyclesForFreq(12000000U); /*!< Set FLASH wait states for core */
81
82 /*!< Set up dividers */
83 CLOCK_SetClkDiv(kCLOCK_DivAhbClk, 1U, false); /*!< Set AHBCLKDIV divider to value 1 */
84
85 /*!< Set up clock selectors - Attach clocks to the peripheries */
86 CLOCK_AttachClk(kFRO12M_to_MAIN_CLK); /*!< Switch MAIN_CLK to FRO12M */
87 /*!< Set SystemCoreClock variable. */
88 SystemCoreClock = BOARD_BOOTCLOCKFRO12M_CORE_CLOCK;
89}
90
91/*******************************************************************************
92 ******************* Configuration BOARD_BootClockFROHF48M *********************
93 ******************************************************************************/
94/* TEXT BELOW IS USED AS SETTING FOR TOOLS *************************************
95!!Configuration
96name: BOARD_BootClockFROHF48M
97outputs:
98- {id: System_clock.outFreq, value: 48 MHz}
99settings:
100- {id: SYSCON.MAINCLKSELA.sel, value: SYSCON.fro_hf}
101 * BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR TOOLS **********/
102
103/*******************************************************************************
104 * Variables for BOARD_BootClockFROHF48M configuration
105 ******************************************************************************/
106/*******************************************************************************
107 * Code for BOARD_BootClockFROHF48M configuration
108 ******************************************************************************/
109void BOARD_BootClockFROHF48M(void)
110{
111 /*!< Set up the clock sources */
112 /*!< Set up FRO */
113 POWER_DisablePD(kPDRUNCFG_PD_FRO_EN); /*!< Ensure FRO is on */
114 CLOCK_SetupFROClocking(12000000U); /*!< Set up FRO to the 12 MHz, just for sure */
115 CLOCK_AttachClk(kFRO12M_to_MAIN_CLK); /*!< Switch to FRO 12MHz first to ensure we can change voltage without
116 accidentally being below the voltage for current speed */
117 POWER_SetVoltageForFreq(
118 48000000U); /*!< Set voltage for the one of the fastest clock outputs: System clock output */
119 CLOCK_SetFLASHAccessCyclesForFreq(48000000U); /*!< Set FLASH wait states for core */
120
121 CLOCK_SetupFROClocking(48000000U); /*!< Set up high frequency FRO output to selected frequency */
122
123 /*!< Set up dividers */
124 CLOCK_SetClkDiv(kCLOCK_DivAhbClk, 1U, false); /*!< Set AHBCLKDIV divider to value 1 */
125
126 /*!< Set up clock selectors - Attach clocks to the peripheries */
127 CLOCK_AttachClk(kFRO_HF_to_MAIN_CLK); /*!< Switch MAIN_CLK to FRO_HF */
128 /*!< Set SystemCoreClock variable. */
129 SystemCoreClock = BOARD_BOOTCLOCKFROHF48M_CORE_CLOCK;
130}
131
132/*******************************************************************************
133 ******************* Configuration BOARD_BootClockFROHF96M *********************
134 ******************************************************************************/
135/* TEXT BELOW IS USED AS SETTING FOR TOOLS *************************************
136!!Configuration
137name: BOARD_BootClockFROHF96M
138outputs:
139- {id: System_clock.outFreq, value: 96 MHz}
140settings:
141- {id: SYSCON.MAINCLKSELA.sel, value: SYSCON.fro_hf}
142sources:
143- {id: SYSCON.fro_hf.outFreq, value: 96 MHz}
144 * BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR TOOLS **********/
145
146/*******************************************************************************
147 * Variables for BOARD_BootClockFROHF96M configuration
148 ******************************************************************************/
149/*******************************************************************************
150 * Code for BOARD_BootClockFROHF96M configuration
151 ******************************************************************************/
152void BOARD_BootClockFROHF96M(void)
153{
154 /*!< Set up the clock sources */
155 /*!< Set up FRO */
156 POWER_DisablePD(kPDRUNCFG_PD_FRO_EN); /*!< Ensure FRO is on */
157 CLOCK_SetupFROClocking(12000000U); /*!< Set up FRO to the 12 MHz, just for sure */
158 CLOCK_AttachClk(kFRO12M_to_MAIN_CLK); /*!< Switch to FRO 12MHz first to ensure we can change voltage without
159 accidentally being below the voltage for current speed */
160 POWER_SetVoltageForFreq(
161 96000000U); /*!< Set voltage for the one of the fastest clock outputs: System clock output */
162 CLOCK_SetFLASHAccessCyclesForFreq(96000000U); /*!< Set FLASH wait states for core */
163
164 CLOCK_SetupFROClocking(96000000U); /*!< Set up high frequency FRO output to selected frequency */
165
166 /*!< Set up dividers */
167 CLOCK_SetClkDiv(kCLOCK_DivAhbClk, 1U, false); /*!< Set AHBCLKDIV divider to value 1 */
168
169 /*!< Set up clock selectors - Attach clocks to the peripheries */
170 CLOCK_AttachClk(kFRO_HF_to_MAIN_CLK); /*!< Switch MAIN_CLK to FRO_HF */
171 /*!< Set SystemCoreClock variable. */
172 SystemCoreClock = BOARD_BOOTCLOCKFROHF96M_CORE_CLOCK;
173}
174
175/*******************************************************************************
176 ******************** Configuration BOARD_BootClockPLL150M *********************
177 ******************************************************************************/
178/* TEXT BELOW IS USED AS SETTING FOR TOOLS *************************************
179!!Configuration
180name: BOARD_BootClockPLL150M
181called_from_default_init: true
182outputs:
183- {id: PLL_clock.outFreq, value: 150 MHz}
184- {id: System_clock.outFreq, value: 150 MHz}
185settings:
186- {id: SYSCON.DIRECTO.sel, value: SYSCON.PLL}
187- {id: SYSCON.MAINCLKSELB.sel, value: SYSCON.PLL_BYPASS}
188- {id: SYSCON.M_MULT.scale, value: '153600', locked: true}
189- {id: SYSCON.N_DIV.scale, value: '6', locked: true}
190- {id: SYSCON.SYSPLLCLKSEL.sel, value: SYSCON.fro_12m}
191 * BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR TOOLS **********/
192
193/*******************************************************************************
194 * Variables for BOARD_BootClockPLL150M configuration
195 ******************************************************************************/
196/*******************************************************************************
197 * Code for BOARD_BootClockPLL150M configuration
198 ******************************************************************************/
199void BOARD_BootClockPLL150M(void)
200{
201 /*!< Set up the clock sources */
202 /*!< Set up FRO */
203 POWER_DisablePD(kPDRUNCFG_PD_FRO_EN); /*!< Ensure FRO is on */
204 CLOCK_SetupFROClocking(12000000U); /*!< Set up FRO to the 12 MHz, just for sure */
205 CLOCK_AttachClk(kFRO12M_to_MAIN_CLK); /*!< Switch to FRO 12MHz first to ensure we can change voltage without
206 accidentally being below the voltage for current speed */
207 POWER_SetVoltageForFreq(
208 150000000U); /*!< Set voltage for the one of the fastest clock outputs: System clock output */
209 CLOCK_SetFLASHAccessCyclesForFreq(150000000U); /*!< Set FLASH wait states for core */
210
211 /*!< Set up PLL */
212 CLOCK_AttachClk(kFRO12M_to_SYS_PLL); /*!< Switch PLL clock source selector to FRO12M */
213 const pll_setup_t pllSetup = {.syspllctrl = SYSCON_SYSPLLCTRL_UPLIMOFF_MASK | SYSCON_SYSPLLCTRL_DIRECTO_MASK,
214 .syspllndec = SYSCON_SYSPLLNDEC_NDEC(11U),
215 .syspllpdec = SYSCON_SYSPLLPDEC_PDEC(2U),
216 .syspllssctrl = {0x0U, (SYSCON_SYSPLLSSCTRL1_MD(76800U) | (uint32_t)(kSS_MF_512) |
217 (uint32_t)(kSS_MR_K0) | (uint32_t)(kSS_MC_NOC))},
218 .pllRate = 150000000U,
219 .flags = PLL_SETUPFLAG_POWERUP};
220 CLOCK_SetPLLFreq(&pllSetup); /*!< Configure PLL to the desired values */
221
222 /* PLL in Fractional/Spread spectrum mode */
223 /* SYSTICK is used for waiting for PLL stabilization */
224
225 SysTick->LOAD = 111999UL; /*!< Set SysTick count value */
226 SysTick->VAL = 0UL; /*!< Reset current count value */
227 SysTick->CTRL = SysTick_CTRL_ENABLE_Msk; /*!< Enable SYSTICK */
228 while ((SysTick->CTRL & SysTick_CTRL_COUNTFLAG_Msk) != SysTick_CTRL_COUNTFLAG_Msk)
229 {
230 } /*!< Waiting for PLL stabilization */
231 SysTick->CTRL = 0UL; /*!< Stop SYSTICK */
232
233 /*!< Set up dividers */
234 CLOCK_SetClkDiv(kCLOCK_DivAhbClk, 1U, false); /*!< Set AHBCLKDIV divider to value 1 */
235
236 /*!< Set up clock selectors - Attach clocks to the peripheries */
237 CLOCK_AttachClk(kSYS_PLL_to_MAIN_CLK); /*!< Switch MAIN_CLK to SYS_PLL */
238 SYSCON->MAINCLKSELA =
239 ((SYSCON->MAINCLKSELA & ~SYSCON_MAINCLKSELA_SEL_MASK) |
240 SYSCON_MAINCLKSELA_SEL(0U)); /*!< Switch MAINCLKSELA to FRO12M even it is not used for MAINCLKSELB */
241 /*!< Set SystemCoreClock variable. */
242 SystemCoreClock = BOARD_BOOTCLOCKPLL150M_CORE_CLOCK;
243}