The MCUXpresso SDK provides APIs for MCUXpresso SDK devices' clock operation.
Get frequency
A centralized function CLOCK_GetFreq gets different clock type frequencies by passing a clock name. For example, pass a kCLOCK_CoreSysClk to get the core clock and pass a kCLOCK_BusClk to get the bus clock. Additionally, there are separate functions to get the frequency. For example, use CLOCK_GetCoreSysClkFreq to get the core clock frequency and CLOCK_GetBusClkFreq to get the bus clock frequency. Using these functions reduces the image size.
External clock frequency
The external clocks EXTAL0/EXTAL1/EXTAL32 are decided by the board level design. The Clock driver uses variables g_xtal0Freq/g_xtal1Freq/g_xtal32Freq to save clock frequencies. Likewise, the APIs CLOCK_SetXtal0Freq, CLOCK_SetXtal1Freq, and CLOCK_SetXtal32Freq are used to set these variables.
The upper layer must set these values correctly. For example, after OSC0(SYSOSC) is initialized using CLOCK_InitOsc0 or CLOCK_InitSysOsc, the upper layer should call the CLOCK_SetXtal0Freq. Otherwise, the clock frequency get functions may not receive valid values. This is useful for multicore platforms where only one core calls CLOCK_InitOsc0 to initialize OSC0 and other cores call CLOCK_SetXtal0Freq.
|
enum | clock_name_t {
kCLOCK_CoreSysClk,
kCLOCK_PlatClk,
kCLOCK_BusClk,
kCLOCK_FlashClk,
kCLOCK_Er32kClk,
kCLOCK_Osc0ErClk,
kCLOCK_McgFixedFreqClk,
kCLOCK_McgInternalRefClk,
kCLOCK_McgFllClk,
kCLOCK_McgPeriphClk,
kCLOCK_McgIrc48MClk,
kCLOCK_LpoClk
} |
| Clock name used to get clock frequency. More...
|
|
enum | clock_ip_name_t |
| Clock gate name used for CLOCK_EnableClock/CLOCK_DisableClock. More...
|
|
enum | _osc_cap_load {
kOSC_Cap2P = OSC_CR_SC2P_MASK,
kOSC_Cap4P = OSC_CR_SC4P_MASK,
kOSC_Cap8P = OSC_CR_SC8P_MASK,
kOSC_Cap16P = OSC_CR_SC16P_MASK
} |
| Oscillator capacitor load setting. More...
|
|
enum | _oscer_enable_mode {
kOSC_ErClkEnable = OSC_CR_ERCLKEN_MASK,
kOSC_ErClkEnableInStop = OSC_CR_EREFSTEN_MASK
} |
| OSCERCLK enable mode. More...
|
|
enum | osc_mode_t {
kOSC_ModeExt = 0U,
kOSC_ModeOscLowPower = MCG_C2_EREFS0_MASK
} |
| The OSC work mode. More...
|
|
enum | mcglite_clkout_src_t {
kMCGLITE_ClkSrcHirc,
kMCGLITE_ClkSrcLirc,
kMCGLITE_ClkSrcExt
} |
| MCG_Lite clock source selection. More...
|
|
enum | mcglite_lirc_mode_t {
kMCGLITE_Lirc2M,
kMCGLITE_Lirc8M
} |
| MCG_Lite LIRC select. More...
|
|
enum | mcglite_lirc_div_t {
kMCGLITE_LircDivBy1 = 0U,
kMCGLITE_LircDivBy2,
kMCGLITE_LircDivBy4,
kMCGLITE_LircDivBy8,
kMCGLITE_LircDivBy16,
kMCGLITE_LircDivBy32,
kMCGLITE_LircDivBy64,
kMCGLITE_LircDivBy128
} |
| MCG_Lite divider factor selection for clock source. More...
|
|
enum | mcglite_mode_t {
kMCGLITE_ModeHirc48M,
kMCGLITE_ModeLirc8M,
kMCGLITE_ModeLirc2M,
kMCGLITE_ModeExt,
kMCGLITE_ModeError
} |
| MCG_Lite clock mode definitions. More...
|
|
enum | _mcglite_irclk_enable_mode {
kMCGLITE_IrclkEnable = MCG_C1_IRCLKEN_MASK,
kMCGLITE_IrclkEnableInStop = MCG_C1_IREFSTEN_MASK
} |
| MCG internal reference clock (MCGIRCLK) enable mode definition. More...
|
|
struct sim_clock_config_t |
uint8_t sim_clock_config_t::er32kSrc |
uint32_t sim_clock_config_t::clkdiv1 |
uint8_t oscer_config_t::enableMode |
Defines the configuration data structure to initialize the OSC. When porting to a new board, set the following members according to the board settings:
- freq: The external frequency.
- workMode: The OSC module mode.
uint32_t osc_config_t::freq |
uint8_t osc_config_t::capLoad |
uint8_t mcglite_config_t::irclkEnableMode |
bool mcglite_config_t::hircEnableInNotHircMode |
#define FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL 0 |
When set to 0, peripheral drivers will enable clock in initialize function and disable clock in de-initialize function. When set to 1, peripheral driver will not control the clock, application could contol the clock out of the driver.
- Note
- All drivers share this feature switcher. If it is set to 1, application should handle clock enable and disable for all drivers.
Value:{ \
kCLOCK_Tpm0, kCLOCK_Tpm1 \
}
Value:{ \
kCLOCK_PortA, kCLOCK_PortB \
}
Enumerator |
---|
kCLOCK_CoreSysClk |
Core/system clock.
|
kCLOCK_PlatClk |
Platform clock.
|
kCLOCK_BusClk |
Bus clock.
|
kCLOCK_FlashClk |
Flash clock.
|
kCLOCK_Er32kClk |
External reference 32K clock (ERCLK32K)
|
kCLOCK_Osc0ErClk |
OSC0 external reference clock (OSC0ERCLK)
|
kCLOCK_McgFixedFreqClk |
MCG fixed frequency clock (MCGFFCLK)
|
kCLOCK_McgInternalRefClk |
MCG internal reference clock (MCGIRCLK)
|
kCLOCK_McgFllClk |
MCGFLLCLK.
|
kCLOCK_McgPeriphClk |
MCG peripheral clock (MCGPCLK)
|
kCLOCK_McgIrc48MClk |
MCG IRC48M clock.
|
kCLOCK_LpoClk |
LPO clock.
|
Enumerator |
---|
kOSC_Cap2P |
2 pF capacitor load
|
kOSC_Cap4P |
4 pF capacitor load
|
kOSC_Cap8P |
8 pF capacitor load
|
kOSC_Cap16P |
16 pF capacitor load
|
Enumerator |
---|
kOSC_ErClkEnable |
Enable.
|
kOSC_ErClkEnableInStop |
Enable in stop mode.
|
Enumerator |
---|
kOSC_ModeExt |
Use external clock.
|
kOSC_ModeOscLowPower |
Oscillator low power.
|
Enumerator |
---|
kMCGLITE_ClkSrcHirc |
MCGOUTCLK source is HIRC.
|
kMCGLITE_ClkSrcLirc |
MCGOUTCLK source is LIRC.
|
kMCGLITE_ClkSrcExt |
MCGOUTCLK source is external clock source.
|
Enumerator |
---|
kMCGLITE_Lirc2M |
Slow internal reference(LIRC) 2 MHz clock selected.
|
kMCGLITE_Lirc8M |
Slow internal reference(LIRC) 8 MHz clock selected.
|
Enumerator |
---|
kMCGLITE_LircDivBy1 |
Divider is 1.
|
kMCGLITE_LircDivBy2 |
Divider is 2.
|
kMCGLITE_LircDivBy4 |
Divider is 4.
|
kMCGLITE_LircDivBy8 |
Divider is 8.
|
kMCGLITE_LircDivBy16 |
Divider is 16.
|
kMCGLITE_LircDivBy32 |
Divider is 32.
|
kMCGLITE_LircDivBy64 |
Divider is 64.
|
kMCGLITE_LircDivBy128 |
Divider is 128.
|
Enumerator |
---|
kMCGLITE_ModeHirc48M |
Clock mode is HIRC 48 M.
|
kMCGLITE_ModeLirc8M |
Clock mode is LIRC 8 M.
|
kMCGLITE_ModeLirc2M |
Clock mode is LIRC 2 M.
|
kMCGLITE_ModeExt |
Clock mode is EXT.
|
kMCGLITE_ModeError |
Unknown mode.
|
Enumerator |
---|
kMCGLITE_IrclkEnable |
MCGIRCLK enable.
|
kMCGLITE_IrclkEnableInStop |
MCGIRCLK enable in stop mode.
|
static void CLOCK_SetEr32kClock |
( |
uint32_t |
src | ) |
|
|
inlinestatic |
- Parameters
-
src | The value to set ERCLK32K clock source. |
static void CLOCK_SetLpuart0Clock |
( |
uint32_t |
src | ) |
|
|
inlinestatic |
- Parameters
-
src | The value to set LPUART clock source. |
static void CLOCK_SetTpmClock |
( |
uint32_t |
src | ) |
|
|
inlinestatic |
- Parameters
-
src | The value to set TPM clock source. |
static void CLOCK_SetClkOutClock |
( |
uint32_t |
src | ) |
|
|
inlinestatic |
- Parameters
-
src | The value to set CLKOUT source. |
static void CLOCK_SetRtcClkOutClock |
( |
uint32_t |
src | ) |
|
|
inlinestatic |
- Parameters
-
src | The value to set RTC_CLKOUT source. |
static void CLOCK_SetOutDiv |
( |
uint32_t |
outdiv1, |
|
|
uint32_t |
outdiv4 |
|
) |
| |
|
inlinestatic |
Set the SIM_CLKDIV1[OUTDIV1], SIM_CLKDIV1[OUTDIV4].
- Parameters
-
outdiv1 | Clock 1 output divider value. |
outdiv4 | Clock 4 output divider value. |
This function checks the current clock configurations and then calculates the clock frequency for a specific clock name defined in clock_name_t. The MCG must be properly configured before using this function.
- Parameters
-
clockName | Clock names defined in clock_name_t |
- Returns
- Clock frequency value in Hertz
uint32_t CLOCK_GetCoreSysClkFreq |
( |
void |
| ) |
|
- Returns
- Clock frequency in Hz.
uint32_t CLOCK_GetPlatClkFreq |
( |
void |
| ) |
|
- Returns
- Clock frequency in Hz.
uint32_t CLOCK_GetBusClkFreq |
( |
void |
| ) |
|
- Returns
- Clock frequency in Hz.
uint32_t CLOCK_GetFlashClkFreq |
( |
void |
| ) |
|
- Returns
- Clock frequency in Hz.
uint32_t CLOCK_GetEr32kClkFreq |
( |
void |
| ) |
|
- Returns
- Clock frequency in Hz.
uint32_t CLOCK_GetOsc0ErClkFreq |
( |
void |
| ) |
|
- Returns
- Clock frequency in Hz.
This function sets system layer clock settings in SIM module.
- Parameters
-
config | Pointer to the configure structure. |
static void CLOCK_SetSimSafeDivs |
( |
void |
| ) |
|
|
inlinestatic |
The system level clocks (core clock, bus clock, flexbus clock and flash clock) must be in allowed ranges. During MCG clock mode switch, the MCG output clock changes then the system level clocks may be out of range. This function could be used before MCG mode change, to make sure system level clocks are in allowed range.
- Parameters
-
config | Pointer to the configure structure. |
uint32_t CLOCK_GetOutClkFreq |
( |
void |
| ) |
|
This function gets the MCG_Lite output clock frequency in Hz based on the current MCG_Lite register value.
- Returns
- The frequency of MCGOUTCLK.
uint32_t CLOCK_GetInternalRefClkFreq |
( |
void |
| ) |
|
This function gets the MCG_Lite internal reference clock frequency in Hz based on the current MCG register value.
- Returns
- The frequency of MCGIRCLK.
uint32_t CLOCK_GetPeriphClkFreq |
( |
void |
| ) |
|
This function gets the MCGPCLK frequency in Hz based on the current MCG_Lite register settings.
- Returns
- The frequency of MCGPCLK.
This function checks the MCG_Lite registers and determines the current MCG_Lite mode.
- Returns
- The current MCG_Lite mode or error code.
This function configures the MCG_Lite, includes the output clock source, MCGIRCLK settings, HIRC settings, and so on. See mcglite_config_t for details.
- Parameters
-
targetConfig | Pointer to the target MCG_Lite mode configuration structure. |
- Returns
- Error code.
static void OSC_SetExtRefClkConfig |
( |
OSC_Type * |
base, |
|
|
oscer_config_t const * |
config |
|
) |
| |
|
inlinestatic |
This function configures the OSC external reference clock (OSCERCLK). This is an example to enable the OSCERCLK in normal mode and stop mode, and set the output divider to 1.
- Parameters
-
base | OSC peripheral address. |
config | Pointer to the configuration structure. |
static void OSC_SetCapLoad |
( |
OSC_Type * |
base, |
|
|
uint8_t |
capLoad |
|
) |
| |
|
inlinestatic |
This function sets the specified capacitor configuration for the oscillator. This should be done in the early system level initialization function call based on the system configuration.
- Parameters
-
base | OSC peripheral address. |
capLoad | OR'ed value for the capacitor load option.See _osc_cap_load. |
Example:
This function initializes the OSC0 according to the board configuration.
- Parameters
-
config | Pointer to the OSC0 configuration structure. |
void CLOCK_DeinitOsc0 |
( |
void |
| ) |
|
This function deinitializes the OSC0.
static void CLOCK_SetXtal0Freq |
( |
uint32_t |
freq | ) |
|
|
inlinestatic |
- Parameters
-
freq | The XTAL0/EXTAL0 input clock frequency in Hz. |
static void CLOCK_SetXtal32Freq |
( |
uint32_t |
freq | ) |
|
|
inlinestatic |
- Parameters
-
freq | The XTAL32/EXTAL32/RTC_CLKIN input clock frequency in Hz. |
The XTAL0/EXTAL0 (OSC0) clock frequency in Hz. When the clock is set up, use the function CLOCK_SetXtal0Freq to set the value in the clock driver. For example, if XTAL0 is 8 MHz:
This is important for the multicore platforms where one core needs to set up the OSC0 using the CLOCK_InitOsc0. All other cores need to call the CLOCK_SetXtal0Freq to get a valid clock frequency.
The XTAL32/EXTAL32/RTC_CLKIN clock frequency in Hz. When the clock is set up, use the function CLOCK_SetXtal32Freq to set the value in the clock driver.
This is important for the multicore platforms where one core needs to set up the clock. All other cores need to call the CLOCK_SetXtal32Freq to get a valid clock frequency.