1 /*
2 * Copyright 2018,2019 ,2021 NXP
3 * All rights reserved.
4 *
5 *
6 * SPDX-License-Identifier: BSD-3-Clause
7 */
8
9 /*
10 * How to set up clock using clock driver functions:
11 *
12 * 1. Setup clock sources.
13 *
14 * 2. Set up all dividers.
15 *
16 * 3. Set up all selectors to provide selected clocks.
17 */
18
19 /* TEXT BELOW IS USED AS SETTING FOR TOOLS *************************************
20 !!GlobalInfo
21 product: Clocks v7.0
22 processor: LPC845
23 package_id: LPC845M301JBD64
24 mcu_data: ksdk2_0
25 processor_version: 9.0.0
26 * BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR TOOLS **********/
27
28 #include "fsl_power.h"
29 #include "fsl_clock.h"
30 #include "clock_config.h"
31
32 /*******************************************************************************
33 * Definitions
34 ******************************************************************************/
35
36 /*******************************************************************************
37 * Variables
38 ******************************************************************************/
39 /* System clock frequency. */
40 extern uint32_t SystemCoreClock;
41
42 /*******************************************************************************
43 ************************ BOARD_InitBootClocks function ************************
44 ******************************************************************************/
BOARD_InitBootClocks(void)45 void BOARD_InitBootClocks(void)
46 {
47 BOARD_BootClockFRO18M();
48 }
49
50 /*******************************************************************************
51 ******************** Configuration BOARD_BootClockFRO18M **********************
52 ******************************************************************************/
53 /* TEXT BELOW IS USED AS SETTING FOR TOOLS *************************************
54 !!Configuration
55 name: BOARD_BootClockFRO18M
56 called_from_default_init: true
57 outputs:
58 - {id: FROHF_clock.outFreq, value: 18 MHz}
59 - {id: LowPower_clock.outFreq, value: 10 kHz}
60 - {id: System_clock.outFreq, value: 18 MHz}
61 - {id: divto750k_clock.outFreq, value: 750 kHz}
62 settings:
63 - {id: SYSCON.ADCCLKSEL.sel, value: NO_CLOCK}
64 - {id: SYSCON.CLKOUTSEL.sel, value: NO_CLOCK}
65 - {id: SYSCON.FRG0CLKSEL.sel, value: NO_CLOCK}
66 - {id: SYSCON.FRG1CLKSEL.sel, value: NO_CLOCK}
67 - {id: SYSCON.FRO_DIRECT.sel, value: SYSCON.fro_osc}
68 - {id: SYSCON.SCTCLKSEL.sel, value: NO_CLOCK}
69 - {id: SYSCON_PDRUNCFG0_PDEN_PLL_CFG, value: Power_down}
70 sources:
71 - {id: SYSCON.fro_osc.outFreq, value: 18 MHz}
72 * BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR TOOLS **********/
73
74 /*******************************************************************************
75 * Variables for BOARD_BootClockFRO18M configuration
76 ******************************************************************************/
77 /*******************************************************************************
78 * Code for BOARD_BootClockFRO18M configuration
79 ******************************************************************************/
BOARD_BootClockFRO18M(void)80 void BOARD_BootClockFRO18M(void)
81 {
82 /*!< Set up the clock sources */
83 /*!< Set up FRO */
84 POWER_DisablePD(kPDRUNCFG_PD_FRO_OUT); /*!< Ensure FRO is on */
85 POWER_DisablePD(kPDRUNCFG_PD_FRO); /*!< Ensure FRO is on */
86 CLOCK_SetFroOscFreq(kCLOCK_FroOscOut18M); /*!< Set up FRO freq */
87 CLOCK_SetFroOutClkSrc(kCLOCK_FroSrcFroOsc); /*!< Set FRO clock source */
88 POWER_DisablePD(kPDRUNCFG_PD_SYSOSC); /*!< Ensure Main osc is on */
89 CLOCK_Select(kEXT_Clk_From_SysOsc); /*!<select external clock source to sys_osc */
90 CLOCK_SetMainClkSrc(kCLOCK_MainClkSrcFro); /*!< select fro for main clock */
91 CLOCK_SetCoreSysClkDiv(1U);
92 /*!< Set SystemCoreClock variable. */
93 SystemCoreClock = BOARD_BOOTCLOCKFRO18M_CORE_CLOCK;
94 }
95
96 /*******************************************************************************
97 ******************** Configuration BOARD_BootClockFRO24M **********************
98 ******************************************************************************/
99 /* TEXT BELOW IS USED AS SETTING FOR TOOLS *************************************
100 !!Configuration
101 name: BOARD_BootClockFRO24M
102 outputs:
103 - {id: FROHF_clock.outFreq, value: 24 MHz}
104 - {id: LowPower_clock.outFreq, value: 10 kHz}
105 - {id: System_clock.outFreq, value: 24 MHz}
106 - {id: divto750k_clock.outFreq, value: 750 kHz}
107 settings:
108 - {id: SYSCON.ADCCLKSEL.sel, value: NO_CLOCK}
109 - {id: SYSCON.CLKOUTSEL.sel, value: NO_CLOCK}
110 - {id: SYSCON.FRG0CLKSEL.sel, value: NO_CLOCK}
111 - {id: SYSCON.FRG1CLKSEL.sel, value: NO_CLOCK}
112 - {id: SYSCON.FRO_DIRECT.sel, value: SYSCON.fro_osc}
113 - {id: SYSCON.SCTCLKSEL.sel, value: NO_CLOCK}
114 - {id: SYSCON_PDRUNCFG0_PDEN_PLL_CFG, value: Power_down}
115 sources:
116 - {id: SYSCON.fro_osc.outFreq, value: 24 MHz}
117 * BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR TOOLS **********/
118
119 /*******************************************************************************
120 * Variables for BOARD_BootClockFRO24M configuration
121 ******************************************************************************/
122 /*******************************************************************************
123 * Code for BOARD_BootClockFRO24M configuration
124 ******************************************************************************/
BOARD_BootClockFRO24M(void)125 void BOARD_BootClockFRO24M(void)
126 {
127 /*!< Set up the clock sources */
128 /*!< Set up FRO */
129 POWER_DisablePD(kPDRUNCFG_PD_FRO_OUT); /*!< Ensure FRO is on */
130 POWER_DisablePD(kPDRUNCFG_PD_FRO); /*!< Ensure FRO is on */
131 CLOCK_SetFroOscFreq(kCLOCK_FroOscOut24M); /*!< Set up FRO freq */
132 CLOCK_SetFroOutClkSrc(kCLOCK_FroSrcFroOsc); /*!< Set FRO clock source */
133 POWER_DisablePD(kPDRUNCFG_PD_SYSOSC); /*!< Ensure Main osc is on */
134 CLOCK_Select(kEXT_Clk_From_SysOsc); /*!<select external clock source to sys_osc */
135 CLOCK_SetMainClkSrc(kCLOCK_MainClkSrcFro); /*!< select fro for main clock */
136 CLOCK_SetCoreSysClkDiv(1U);
137 /*!< Set SystemCoreClock variable. */
138 SystemCoreClock = BOARD_BOOTCLOCKFRO24M_CORE_CLOCK;
139 }
140
141 /*******************************************************************************
142 ******************** Configuration BOARD_BootClockFRO30M **********************
143 ******************************************************************************/
144 /* TEXT BELOW IS USED AS SETTING FOR TOOLS *************************************
145 !!Configuration
146 name: BOARD_BootClockFRO30M
147 outputs:
148 - {id: FROHF_clock.outFreq, value: 30 MHz}
149 - {id: LowPower_clock.outFreq, value: 10 kHz}
150 - {id: System_clock.outFreq, value: 30 MHz}
151 - {id: divto750k_clock.outFreq, value: 750 kHz}
152 settings:
153 - {id: SYSCON.ADCCLKSEL.sel, value: NO_CLOCK}
154 - {id: SYSCON.CLKOUTSEL.sel, value: NO_CLOCK}
155 - {id: SYSCON.FRG0CLKSEL.sel, value: NO_CLOCK}
156 - {id: SYSCON.FRG1CLKSEL.sel, value: NO_CLOCK}
157 - {id: SYSCON.FRO_DIRECT.sel, value: SYSCON.fro_osc}
158 - {id: SYSCON.SCTCLKSEL.sel, value: NO_CLOCK}
159 - {id: SYSCON_PDRUNCFG0_PDEN_PLL_CFG, value: Power_down}
160 * BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR TOOLS **********/
161
162 /*******************************************************************************
163 * Variables for BOARD_BootClockFRO30M configuration
164 ******************************************************************************/
165 /*******************************************************************************
166 * Code for BOARD_BootClockFRO30M configuration
167 ******************************************************************************/
BOARD_BootClockFRO30M(void)168 void BOARD_BootClockFRO30M(void)
169 {
170 /*!< Set up the clock sources */
171 /*!< Set up FRO */
172 POWER_DisablePD(kPDRUNCFG_PD_FRO_OUT); /*!< Ensure FRO is on */
173 POWER_DisablePD(kPDRUNCFG_PD_FRO); /*!< Ensure FRO is on */
174 CLOCK_SetFroOscFreq(kCLOCK_FroOscOut30M); /*!< Set up FRO freq */
175 CLOCK_SetFroOutClkSrc(kCLOCK_FroSrcFroOsc); /*!< Set FRO clock source */
176 POWER_DisablePD(kPDRUNCFG_PD_SYSOSC); /*!< Ensure Main osc is on */
177 CLOCK_Select(kEXT_Clk_From_SysOsc); /*!<select external clock source to sys_osc */
178 CLOCK_SetMainClkSrc(kCLOCK_MainClkSrcFro); /*!< select fro for main clock */
179 CLOCK_SetCoreSysClkDiv(1U);
180 /*!< Set SystemCoreClock variable. */
181 SystemCoreClock = BOARD_BOOTCLOCKFRO30M_CORE_CLOCK;
182 }
183
184 /*******************************************************************************
185 ******************** Configuration BOARD_BootClockPll24M **********************
186 ******************************************************************************/
187 /* TEXT BELOW IS USED AS SETTING FOR TOOLS *************************************
188 !!Configuration
189 name: BOARD_BootClockPll24M
190 outputs:
191 - {id: FROHF_clock.outFreq, value: 24 MHz}
192 - {id: LowPower_clock.outFreq, value: 10 kHz}
193 - {id: SYSPLL_clock.outFreq, value: 24 MHz}
194 - {id: System_clock.outFreq, value: 24 MHz}
195 - {id: divto750k_clock.outFreq, value: 750 kHz}
196 settings:
197 - {id: SYSCON.ADCCLKSEL.sel, value: NO_CLOCK}
198 - {id: SYSCON.CLKOUTSEL.sel, value: NO_CLOCK}
199 - {id: SYSCON.FRG0CLKSEL.sel, value: NO_CLOCK}
200 - {id: SYSCON.FRG1CLKSEL.sel, value: NO_CLOCK}
201 - {id: SYSCON.FRO_DIRECT.sel, value: SYSCON.fro_osc}
202 - {id: SYSCON.MAINCLKPLLSEL.sel, value: SYSCON.PLL}
203 - {id: SYSCON.SCTCLKSEL.sel, value: NO_CLOCK}
204 sources:
205 - {id: SYSCON.fro_osc.outFreq, value: 24 MHz}
206 * BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR TOOLS **********/
207
208 /*******************************************************************************
209 * Variables for BOARD_BootClockPll24M configuration
210 ******************************************************************************/
211 /*******************************************************************************
212 * Code for BOARD_BootClockPll24M configuration
213 ******************************************************************************/
BOARD_BootClockPll24M(void)214 void BOARD_BootClockPll24M(void)
215 {
216 /*!< Set up the clock sources */
217 /*!< Set up FRO */
218 POWER_DisablePD(kPDRUNCFG_PD_FRO_OUT); /*!< Ensure FRO is on */
219 POWER_DisablePD(kPDRUNCFG_PD_FRO); /*!< Ensure FRO is on */
220 CLOCK_SetFroOscFreq(kCLOCK_FroOscOut24M); /*!< Set up FRO freq */
221 CLOCK_SetFroOutClkSrc(kCLOCK_FroSrcFroOsc); /*!< Set FRO clock source */
222 POWER_DisablePD(kPDRUNCFG_PD_SYSOSC); /*!< Ensure Main osc is on */
223 CLOCK_Select(kEXT_Clk_From_SysOsc); /*!<select external clock source to sys_osc */
224 clock_sys_pll_t config;
225 config.src = kCLOCK_SysPllSrcFRO; /*!< select FRO for SYSPLL */
226 config.targetFreq = 24000000U; /*!< set pll target freq */
227 CLOCK_InitSystemPll(&config); /*!< set parameters */
228 CLOCK_SetMainClkSrc(kCLOCK_MainClkSrcSysPll); /*!< select syspll for main clock */
229 CLOCK_SetCoreSysClkDiv(1U);
230 /*!< Set SystemCoreClock variable. */
231 SystemCoreClock = BOARD_BOOTCLOCKPLL24M_CORE_CLOCK;
232 }
233
234