1 /*
2  * Copyright 2017,2019 ,2021 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 setup clock using clock driver functions:
14  *
15  * 1. call CLOCK_SetSimSafeDivs() to set the system clock dividers in SIM to safe value.
16  *
17  * 2. If external oscillator is used Call CLOCK_SetXtal0Freq() to set XTAL0 frequency based on board settings and
18  *    call CLOCK_InitOsc0() to init the OSC.
19  *
20  * 3. Call CLOCK_BootToXxxMode()/CLOCK_SetXxxMode() to set ICS run at the target mode.
21  *
22  * 4. If ICSIRCLK is needed, call CLOCK_SetInternalRefClkConfig() to enable the clock.
23  *
24  * 5. call CLOCK_SetSimConfig() to configure the divider in sim.
25  */
26 
27 /* clang-format off */
28 /* TEXT BELOW IS USED AS SETTING FOR TOOLS *************************************
29 !!GlobalInfo
30 product: Clocks v7.0
31 processor: MKE04Z8xxx4
32 package_id: MKE04Z8VFK4
33 mcu_data: ksdk2_0
34 processor_version: 9.0.0
35  * BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR TOOLS **********/
36 /* clang-format on */
37 
38 #include "clock_config.h"
39 
40 /*******************************************************************************
41  * Definitions
42  ******************************************************************************/
43 
44 /*******************************************************************************
45  * Variables
46  ******************************************************************************/
47 /* System clock frequency. */
48 extern uint32_t SystemCoreClock;
49 
50 /*******************************************************************************
51  ************************ BOARD_InitBootClocks function ************************
52  ******************************************************************************/
BOARD_InitBootClocks(void)53 void BOARD_InitBootClocks(void)
54 {
55     BOARD_BootClockRUN();
56 }
57 
58 /*******************************************************************************
59  ********************** Configuration BOARD_BootClockRUN ***********************
60  ******************************************************************************/
61 /* clang-format off */
62 /* TEXT BELOW IS USED AS SETTING FOR TOOLS *************************************
63 !!Configuration
64 name: BOARD_BootClockRUN
65 called_from_default_init: true
66 outputs:
67 - {id: Bus_clock.outFreq, value: 20 MHz}
68 - {id: Core_clock.outFreq, value: 40 MHz}
69 - {id: Flash_clock.outFreq, value: 20 MHz}
70 - {id: ICSFF_clock.outFreq, value: 31.25 kHz}
71 - {id: ICSIR_clock.outFreq, value: 37.5 kHz}
72 - {id: LPO_clock.outFreq, value: 1 kHz}
73 - {id: OSCER_clock.outFreq, value: 8 MHz}
74 - {id: Plat_clock.outFreq, value: 40 MHz}
75 - {id: System_clock.outFreq, value: 40 MHz}
76 - {id: Timer_clock.outFreq, value: 40 MHz}
77 settings:
78 - {id: ICSMode, value: FEE}
79 - {id: ICS.BDIV.scale, value: '1', locked: true}
80 - {id: ICS.IREFS.sel, value: ICS.RDIV}
81 - {id: ICS.RDIV.scale, value: '256'}
82 - {id: ICS_C1_IRCLKEN_CFG, value: Enabled}
83 - {id: OSC_CR_OSCEN_CFG, value: Enabled}
84 - {id: OSC_CR_OSC_MODE_CFG, value: ModeOscLowPower}
85 - {id: OSC_CR_RANGE_CFG, value: High}
86 - {id: OSC_CR_RANGE_RDIV_CFG, value: High}
87 - {id: SIM.DIV2.scale, value: '2'}
88 sources:
89 - {id: OSC.OSC.outFreq, value: 8 MHz, enabled: true}
90  * BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR TOOLS **********/
91 /* clang-format on */
92 
93 /*******************************************************************************
94  * Variables for BOARD_BootClockRUN configuration
95  ******************************************************************************/
96 const ics_config_t icsConfig_BOARD_BootClockRUN =
97     {
98         .icsMode = kICS_ModeFEE,                  /* FEE - FLL Engaged External */
99         .irClkEnableMode = kICS_IrclkEnable,      /* ICSIRCLK enabled, ICSIRCLK disabled in STOP mode */
100         .bDiv = 0x0U,                             /* Bus clock divider: divided by 1 */
101         .rDiv = 0x3U,                             /* FLL external reference clock divider: divided by 256 */
102     };
103 const sim_clock_config_t simConfig_BOARD_BootClockRUN =
104     {
105         .outDiv1 = 0x0U,                          /* DIV1 clock divider: divided by 1 */
106         .outDiv2 = 0x1U,                          /* DIV2 clock divider: divided by 2 */
107         .outDiv3 = 0x0U,                          /* DIV3 clock divider: divided by 1 */
108         .busClkPrescaler = 0x0U,                  /* bus clock optional prescaler */
109     };
110 const osc_config_t oscConfig_BOARD_BootClockRUN =
111     {
112         .freq = 8000000U,                         /* Oscillator frequency: 8000000Hz */
113         .workMode = kOSC_ModeOscLowPower,         /* Oscillator low power */
114         .enableMode = kOSC_Enable,                /* Enable external reference clock, disable external reference clock in STOP mode */
115     };
116 
117 /*******************************************************************************
118  * Code for BOARD_BootClockRUN configuration
119  ******************************************************************************/
BOARD_BootClockRUN(void)120 void BOARD_BootClockRUN(void)
121 {
122     /* Set the system clock dividers in SIM to safe value. */
123     CLOCK_SetSimSafeDivs();
124     /* Initializes OSC0 according to board configuration. */
125     CLOCK_InitOsc0(&oscConfig_BOARD_BootClockRUN);
126     CLOCK_SetXtal0Freq(oscConfig_BOARD_BootClockRUN.freq);
127     /* Set ICS to FEE mode. */
128     CLOCK_BootToFeeMode(icsConfig_BOARD_BootClockRUN.bDiv,
129                         icsConfig_BOARD_BootClockRUN.rDiv);
130     /* Configure the Internal Reference clock (ICSIRCLK). */
131     CLOCK_SetInternalRefClkConfig(icsConfig_BOARD_BootClockRUN.irClkEnableMode);
132     /* Set the clock configuration in SIM module. */
133     CLOCK_SetSimConfig(&simConfig_BOARD_BootClockRUN);
134     /* Set SystemCoreClock variable. */
135     SystemCoreClock = BOARD_BOOTCLOCKRUN_CORE_CLOCK;
136 }
137 
138