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: LPC804
23 package_id: LPC804M101JDH24
24 mcu_data: ksdk2_0
25 processor_version: 9.0.0
26 board: LPCXpresso804
27  * BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR TOOLS **********/
28 
29 #include "fsl_power.h"
30 #include "fsl_clock.h"
31 #include "clock_config.h"
32 
33 /*******************************************************************************
34  * Definitions
35  ******************************************************************************/
36 
37 /*******************************************************************************
38  * Variables
39  ******************************************************************************/
40 /* System clock frequency. */
41 extern uint32_t SystemCoreClock;
42 
43 /*******************************************************************************
44  ************************ BOARD_InitBootClocks function ************************
45  ******************************************************************************/
BOARD_InitBootClocks(void)46 void BOARD_InitBootClocks(void)
47 {
48     BOARD_BootClockFRO30M();
49 }
50 
51 /*******************************************************************************
52  ******************** Configuration BOARD_BootClockFRO18M **********************
53  ******************************************************************************/
54 /* TEXT BELOW IS USED AS SETTING FOR TOOLS *************************************
55 !!Configuration
56 name: BOARD_BootClockFRO18M
57 outputs:
58 - {id: FROHF_clock.outFreq, value: 18 MHz}
59 - {id: LowPower_clock.outFreq, value: 1 MHz}
60 - {id: System_clock.outFreq, value: 9 MHz}
61 - {id: WWDT_clock.outFreq, value: 1 MHz}
62 - {id: divto750k_clock.outFreq, value: 750 kHz}
63 sources:
64 - {id: SYSCON.fro_osc.outFreq, value: 18 MHz}
65  * BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR TOOLS **********/
66 
67 /*******************************************************************************
68  * Variables for BOARD_BootClockFRO18M configuration
69  ******************************************************************************/
70 /*******************************************************************************
71  * Code for BOARD_BootClockFRO18M configuration
72  ******************************************************************************/
BOARD_BootClockFRO18M(void)73 void BOARD_BootClockFRO18M(void)
74 {
75     /*!< Set up the clock sources */
76     /*!< Set up FRO */
77     POWER_DisablePD(kPDRUNCFG_PD_FRO_OUT);                   /*!< Ensure FRO OUT is on  */
78     POWER_DisablePD(kPDRUNCFG_PD_FRO);                      /*!< Ensure FRO is on  */
79     CLOCK_SetFroOscFreq(kCLOCK_FroOscOut18M);                    /*!< Set up FRO freq */
80     POWER_DisablePD(kPDRUNCFG_PD_LPOSC);                  /*!< Ensure LPOSC is on */
81     CLOCK_SetMainClkSrc(kCLOCK_MainClkSrcFro);            /*!< select fro for main clock */
82     CLOCK_Select(kFRG0_Clk_From_Fro);                     /*!< select fro for frg0 */
83     CLOCK_SetFRG0ClkFreq(9000000U);                     /*!< select frg0 freq */
84     CLOCK_Select(kCLKOUT_From_Fro);                         /*!< select FRO for CLKOUT */
85     CLOCK_Select(kADC_Clk_From_Fro);                       /*!< select FRO for ADC */
86     CLOCK_SetCoreSysClkDiv(1U);
87     /*!< Set SystemCoreClock variable. */
88     SystemCoreClock = BOARD_BOOTCLOCKFRO18M_CORE_CLOCK;
89 }
90 
91 /*******************************************************************************
92  ******************** Configuration BOARD_BootClockFRO24M **********************
93  ******************************************************************************/
94 /* TEXT BELOW IS USED AS SETTING FOR TOOLS *************************************
95 !!Configuration
96 name: BOARD_BootClockFRO24M
97 outputs:
98 - {id: FROHF_clock.outFreq, value: 24 MHz}
99 - {id: LowPower_clock.outFreq, value: 1 MHz}
100 - {id: System_clock.outFreq, value: 12 MHz}
101 - {id: WWDT_clock.outFreq, value: 1 MHz}
102 - {id: divto750k_clock.outFreq, value: 750 kHz}
103 sources:
104 - {id: SYSCON.fro_osc.outFreq, value: 24 MHz}
105  * BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR TOOLS **********/
106 
107 /*******************************************************************************
108  * Variables for BOARD_BootClockFRO24M configuration
109  ******************************************************************************/
110 /*******************************************************************************
111  * Code for BOARD_BootClockFRO24M configuration
112  ******************************************************************************/
BOARD_BootClockFRO24M(void)113 void BOARD_BootClockFRO24M(void)
114 {
115     /*!< Set up the clock sources */
116     /*!< Set up FRO */
117     POWER_DisablePD(kPDRUNCFG_PD_FRO_OUT);                   /*!< Ensure FRO OUT is on  */
118     POWER_DisablePD(kPDRUNCFG_PD_FRO);                      /*!< Ensure FRO is on  */
119     CLOCK_SetFroOscFreq(kCLOCK_FroOscOut24M);                    /*!< Set up FRO freq */
120     POWER_DisablePD(kPDRUNCFG_PD_LPOSC);                  /*!< Ensure LPOSC is on */
121     CLOCK_SetMainClkSrc(kCLOCK_MainClkSrcFro);            /*!< select fro for main clock */
122     CLOCK_Select(kFRG0_Clk_From_Fro);                     /*!< select fro for frg0 */
123     CLOCK_SetFRG0ClkFreq(12000000U);                     /*!< select frg0 freq */
124     CLOCK_Select(kCLKOUT_From_Fro);                         /*!< select FRO for CLKOUT */
125     CLOCK_Select(kADC_Clk_From_Fro);                       /*!< select FRO for ADC */
126     CLOCK_SetCoreSysClkDiv(1U);
127     /*!< Set SystemCoreClock variable. */
128     SystemCoreClock = BOARD_BOOTCLOCKFRO24M_CORE_CLOCK;
129 }
130 
131 /*******************************************************************************
132  ******************** Configuration BOARD_BootClockFRO30M **********************
133  ******************************************************************************/
134 /* TEXT BELOW IS USED AS SETTING FOR TOOLS *************************************
135 !!Configuration
136 name: BOARD_BootClockFRO30M
137 called_from_default_init: true
138 outputs:
139 - {id: FROHF_clock.outFreq, value: 30 MHz}
140 - {id: LowPower_clock.outFreq, value: 1 MHz}
141 - {id: System_clock.outFreq, value: 15 MHz}
142 - {id: WWDT_clock.outFreq, value: 1 MHz}
143 - {id: divto750k_clock.outFreq, value: 750 kHz}
144  * BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR TOOLS **********/
145 
146 /*******************************************************************************
147  * Variables for BOARD_BootClockFRO30M configuration
148  ******************************************************************************/
149 /*******************************************************************************
150  * Code for BOARD_BootClockFRO30M configuration
151  ******************************************************************************/
BOARD_BootClockFRO30M(void)152 void BOARD_BootClockFRO30M(void)
153 {
154     /*!< Set up the clock sources */
155     /*!< Set up FRO */
156     POWER_DisablePD(kPDRUNCFG_PD_FRO_OUT);                   /*!< Ensure FRO OUT is on  */
157     POWER_DisablePD(kPDRUNCFG_PD_FRO);                      /*!< Ensure FRO is on  */
158     CLOCK_SetFroOscFreq(kCLOCK_FroOscOut30M);                    /*!< Set up FRO freq */
159     POWER_DisablePD(kPDRUNCFG_PD_LPOSC);                  /*!< Ensure LPOSC is on */
160     CLOCK_SetMainClkSrc(kCLOCK_MainClkSrcFro);            /*!< select fro for main clock */
161     CLOCK_Select(kFRG0_Clk_From_Fro);                     /*!< select fro for frg0 */
162     CLOCK_SetFRG0ClkFreq(15000000U);                     /*!< select frg0 freq */
163     CLOCK_Select(kCLKOUT_From_Fro);                         /*!< select FRO for CLKOUT */
164     CLOCK_Select(kADC_Clk_From_Fro);                       /*!< select FRO for ADC */
165     CLOCK_SetCoreSysClkDiv(1U);
166     /*!< Set SystemCoreClock variable. */
167     SystemCoreClock = BOARD_BOOTCLOCKFRO30M_CORE_CLOCK;
168 }
169 
170