ISSDK  1.8
IoT Sensing Software Development Kit
clock_config.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015, Freescale Semiconductor, Inc.
3  * Copyright 2016-2017 NXP
4  * All rights reserved.
5  *
6  * SPDX-License-Identifier: BSD-3-Clause
7  */
8 
9 /*
10  * How to setup clock using clock driver functions:
11  *
12  * 1. CLOCK_SetSimSafeDivs, to make sure core clock, bus clock, flexbus clock
13  * and flash clock are in allowed range during clock mode switch.
14  *
15  * 2. Call CLOCK_Osc0Init to setup OSC clock, if it is used in target mode.
16  *
17  * 3. Call CLOCK_SetMcgliteConfig to set MCG_Lite configuration.
18  *
19  * 4. Call CLOCK_SetSimConfig to set the clock configuration in SIM.
20  */
21 
22 /* TEXT BELOW IS USED AS SETTING FOR THE CLOCKS TOOL *****************************
23 !!ClocksProfile
24 product: Clocks v1.0
25 processor: MKL27Z64xxx4
26 package_id: MKL27Z64VLH4
27 mcu_data: ksdk2_0
28 processor_version: 1.0.1
29 board: FRDM-KL27Z
30  * BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR THE CLOCKS TOOL **/
31 
32 #include "fsl_smc.h"
33 #include "clock_config.h"
34 
35 /*******************************************************************************
36  * Definitions
37  ******************************************************************************/
38 #define SIM_OSC32KSEL_OSC32KCLK_CLK 0U /*!< OSC32KSEL select: OSC32KCLK clock */
39 
40 /*******************************************************************************
41  * Variables
42  ******************************************************************************/
43 /* System clock frequency. */
44 extern uint32_t SystemCoreClock;
45 
46 /*******************************************************************************
47  ********************** Configuration BOARD_BootClockRUN ***********************
48  ******************************************************************************/
49 /* TEXT BELOW IS USED AS SETTING FOR THE CLOCKS TOOL *****************************
50 !!Configuration
51 name: BOARD_BootClockRUN
52 outputs:
53 - {id: Bus_clock.outFreq, value: 24 MHz}
54 - {id: Core_clock.outFreq, value: 48 MHz}
55 - {id: Flash_clock.outFreq, value: 24 MHz}
56 - {id: LPO_clock.outFreq, value: 1 kHz}
57 - {id: MCGIRCLK.outFreq, value: 8 MHz}
58 - {id: MCGPCLK.outFreq, value: 48 MHz}
59 - {id: System_clock.outFreq, value: 48 MHz}
60 settings:
61 - {id: MCGMode, value: HIRC}
62 - {id: MCG.CLKS.sel, value: MCG.HIRC}
63 - {id: MCG_C2_OSC_MODE_CFG, value: ModeOscLowPower}
64 - {id: MCG_MC_HIRCEN_CFG, value: Enabled}
65 - {id: OSC0_CR_ERCLKEN_CFG, value: Enabled}
66 - {id: OSC_CR_ERCLKEN_CFG, value: Enabled}
67 - {id: OSC_CR_SYS_OSC_CAP_LOAD_CFG, value: SC12PF}
68 - {id: SIM.CLKOUTSEL.sel, value: MCG.MCGPCLK}
69 - {id: SIM.COPCLKSEL.sel, value: OSC.OSCERCLK}
70 - {id: SIM.FLEXIOSRCSEL.sel, value: MCG.MCGPCLK}
71 - {id: SIM.LPUART0SRCSEL.sel, value: MCG.MCGPCLK}
72 - {id: SIM.LPUART1SRCSEL.sel, value: MCG.MCGPCLK}
73 - {id: SIM.RTCCLKOUTSEL.sel, value: OSC.OSCERCLK}
74 - {id: SIM.TPMSRCSEL.sel, value: MCG.MCGPCLK}
75 - {id: SIM.USBSRCSEL.sel, value: MCG.MCGPCLK}
76 sources:
77 - {id: MCG.HIRC.outFreq, value: 48 MHz}
78 - {id: OSC.OSC.outFreq, value: 32.768 kHz}
79  * BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR THE CLOCKS TOOL **/
80 
81 /*******************************************************************************
82  * Variables for BOARD_BootClockRUN configuration
83  ******************************************************************************/
84 const mcglite_config_t mcgliteConfig_BOARD_BootClockRUN =
85  {
86  .outSrc = kMCGLITE_ClkSrcHirc, /* MCGOUTCLK source is HIRC */
87  .irclkEnableMode = kMCGLITE_IrclkEnable, /* MCGIRCLK enabled, MCGIRCLK disabled in STOP mode */
88  .ircs = kMCGLITE_Lirc8M, /* Slow internal reference (LIRC) 8 MHz clock selected */
89  .fcrdiv = kMCGLITE_LircDivBy1, /* Low-frequency Internal Reference Clock Divider: divided by 1 */
90  .lircDiv2 = kMCGLITE_LircDivBy1, /* Second Low-frequency Internal Reference Clock Divider: divided by 1 */
91  .hircEnableInNotHircMode = true, /* HIRC source is enabled */
92  };
93 const sim_clock_config_t simConfig_BOARD_BootClockRUN =
94  {
95  .er32kSrc = SIM_OSC32KSEL_OSC32KCLK_CLK, /* OSC32KSEL select: OSC32KCLK clock */
96  .clkdiv1 = 0x10000U, /* SIM_CLKDIV1 - OUTDIV1: /1, OUTDIV4: /2 */
97  };
98 const osc_config_t oscConfig_BOARD_BootClockRUN =
99  {
100  .freq = 0U, /* Oscillator frequency: 0Hz */
101  .capLoad = (kOSC_Cap4P | kOSC_Cap8P), /* Oscillator capacity load: 12pF */
102  .workMode = kOSC_ModeOscLowPower, /* Oscillator low power */
103  .oscerConfig =
104  {
105  .enableMode = kOSC_ErClkEnable, /* Enable external reference clock, disable external reference clock in STOP mode */
106  }
107  };
108 
109 /*******************************************************************************
110  * Code for BOARD_BootClockRUN configuration
111  ******************************************************************************/
113 {
114  /* Set the system clock dividers in SIM to safe value. */
115  CLOCK_SetSimSafeDivs();
116  /* Set MCG to HIRC mode. */
117  CLOCK_SetMcgliteConfig(&mcgliteConfig_BOARD_BootClockRUN);
118  /* Set the clock configuration in SIM module. */
119  CLOCK_SetSimConfig(&simConfig_BOARD_BootClockRUN);
120  /* Set SystemCoreClock variable. */
122 }
123 
124 /*******************************************************************************
125  ********************* Configuration BOARD_BootClockVLPR ***********************
126  ******************************************************************************/
127 /* TEXT BELOW IS USED AS SETTING FOR THE CLOCKS TOOL *****************************
128 !!Configuration
129 name: BOARD_BootClockVLPR
130 outputs:
131 - {id: Bus_clock.outFreq, value: 1 MHz}
132 - {id: Core_clock.outFreq, value: 2 MHz}
133 - {id: Flash_clock.outFreq, value: 1 MHz}
134 - {id: LPO_clock.outFreq, value: 1 kHz}
135 - {id: MCGIRCLK.outFreq, value: 2 MHz}
136 - {id: System_clock.outFreq, value: 2 MHz}
137 settings:
138 - {id: MCGMode, value: LIRC2M}
139 - {id: powerMode, value: VLPR}
140 - {id: MCG.LIRCDIV1.scale, value: '1', locked: true}
141 - {id: OSC0_CR_ERCLKEN_CFG, value: Enabled}
142 - {id: OSC_CR_ERCLKEN_CFG, value: Enabled}
143 - {id: OSC_CR_SYS_OSC_CAP_LOAD_CFG, value: SC12PF}
144 - {id: RTCCLKOUTConfig, value: 'yes'}
145 - {id: SIM.OUTDIV1.scale, value: '1', locked: true}
146 - {id: SIM.OUTDIV4.scale, value: '2', locked: true}
147 - {id: SIM.RTCCLKOUTSEL.sel, value: OSC.OSCERCLK}
148 sources:
149 - {id: MCG.LIRC.outFreq, value: 2 MHz}
150 - {id: OSC.OSC.outFreq, value: 32.768 kHz}
151  * BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR THE CLOCKS TOOL **/
152 
153 /*******************************************************************************
154  * Variables for BOARD_BootClockVLPR configuration
155  ******************************************************************************/
156 const mcglite_config_t mcgliteConfig_BOARD_BootClockVLPR =
157  {
158  .outSrc = kMCGLITE_ClkSrcLirc, /* MCGOUTCLK source is LIRC */
159  .irclkEnableMode = kMCGLITE_IrclkEnable, /* MCGIRCLK enabled, MCGIRCLK disabled in STOP mode */
160  .ircs = kMCGLITE_Lirc2M, /* Slow internal reference (LIRC) 2 MHz clock selected */
161  .fcrdiv = kMCGLITE_LircDivBy1, /* Low-frequency Internal Reference Clock Divider: divided by 1 */
162  .lircDiv2 = kMCGLITE_LircDivBy1, /* Second Low-frequency Internal Reference Clock Divider: divided by 1 */
163  .hircEnableInNotHircMode = false, /* HIRC source is not enabled */
164  };
165 const sim_clock_config_t simConfig_BOARD_BootClockVLPR =
166  {
167  .er32kSrc = SIM_OSC32KSEL_OSC32KCLK_CLK, /* OSC32KSEL select: OSC32KCLK clock */
168  .clkdiv1 = 0x10000U, /* SIM_CLKDIV1 - OUTDIV1: /1, OUTDIV4: /2 */
169  };
170 const osc_config_t oscConfig_BOARD_BootClockVLPR =
171  {
172  .freq = 0U, /* Oscillator frequency: 0Hz */
173  .capLoad = (kOSC_Cap4P | kOSC_Cap8P), /* Oscillator capacity load: 12pF */
174  .workMode = kOSC_ModeExt, /* Use external clock */
175  .oscerConfig =
176  {
177  .enableMode = kOSC_ErClkEnable, /* Enable external reference clock, disable external reference clock in STOP mode */
178  }
179  };
180 
181 /*******************************************************************************
182  * Code for BOARD_BootClockVLPR configuration
183  ******************************************************************************/
185 {
186  /* Set the system clock dividers in SIM to safe value. */
187  CLOCK_SetSimSafeDivs();
188  /* Set MCG to LIRC2M mode. */
189  CLOCK_SetMcgliteConfig(&mcgliteConfig_BOARD_BootClockVLPR);
190  /* Set the clock configuration in SIM module. */
191  CLOCK_SetSimConfig(&simConfig_BOARD_BootClockVLPR);
192  /* Set VLPR power mode. */
193  SMC_SetPowerModeProtection(SMC, kSMC_AllowPowerModeAll);
194 #if (defined(FSL_FEATURE_SMC_HAS_LPWUI) && FSL_FEATURE_SMC_HAS_LPWUI)
195  SMC_SetPowerModeVlpr(SMC, false);
196 #else
198 #endif
199  while (SMC_GetPowerModeState(SMC) != kSMC_PowerStateVlpr)
200  {
201  }
202  /* Set SystemCoreClock variable. */
204 }
205 
const mcglite_config_t mcgliteConfig_BOARD_BootClockRUN
MCG lite set for BOARD_BootClockRUN configuration.
Definition: clock_config.c:84
void BOARD_BootClockVLPR(void)
This function executes configuration of clocks.
Definition: clock_config.c:266
status_t SMC_SetPowerModeVlpr(void *arg)
Configures the system to VLPR power mode. API name used from Kinetis family to maintain compatibility...
Definition: lpc54114.c:169
#define SMC
Definition: lpc54114.h:118
#define SIM_OSC32KSEL_OSC32KCLK_CLK
Definition: clock_config.c:38
const sim_clock_config_t simConfig_BOARD_BootClockRUN
SIM module set for BOARD_BootClockRUN configuration.
Definition: clock_config.c:148
const osc_config_t oscConfig_BOARD_BootClockRUN
OSC set for BOARD_BootClockRUN configuration.
Definition: clock_config.c:154
const osc_config_t oscConfig_BOARD_BootClockVLPR
OSC set for BOARD_BootClockVLPR configuration.
Definition: clock_config.c:252
const mcglite_config_t mcgliteConfig_BOARD_BootClockVLPR
MCG lite set for BOARD_BootClockVLPR configuration.
Definition: clock_config.c:156
const sim_clock_config_t simConfig_BOARD_BootClockVLPR
SIM module set for BOARD_BootClockVLPR configuration.
Definition: clock_config.c:246
uint32_t SystemCoreClock
void BOARD_BootClockRUN(void)
This function executes configuration of clocks.
Definition: clock_config.c:168
#define BOARD_BOOTCLOCKVLPR_CORE_CLOCK
Definition: clock_config.h:60
#define BOARD_BOOTCLOCKRUN_CORE_CLOCK
Definition: clock_config.h:25