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