MCUXpresso SDK API Reference Manual  Rev. 0
NXP Semiconductors
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
Clock Driver

Overview

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.

Modules

 Multipurpose Clock Generator (MCG)
 

Files

file  fsl_clock.h
 

Data Structures

struct  sim_clock_config_t
 SIM configuration structure for clock setting. More...
 
struct  osc_config_t
 OSC Initialization Configuration Structure. More...
 
struct  mcg_config_t
 MCG mode change configuration structure. More...
 

Macros

#define MCG_CONFIG_CHECK_PARAM   0U
 Configures whether to check a parameter in a function. More...
 
#define FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL   0
 Configure whether driver controls clock. More...
 
#define DMAMUX_CLOCKS
 Clock ip name array for DMAMUX. More...
 
#define RTC_CLOCKS
 Clock ip name array for RTC. More...
 
#define PIT_CLOCKS
 Clock ip name array for PIT. More...
 
#define PORT_CLOCKS
 Clock ip name array for PORT. More...
 
#define TSI_CLOCKS
 Clock ip name array for TSI. More...
 
#define DSPI_CLOCKS
 Clock ip name array for DSPI. More...
 
#define LPUART_CLOCKS
 Clock ip name array for LPUART. More...
 
#define DAC_CLOCKS
 Clock ip name array for DAC. More...
 
#define LPTMR_CLOCKS
 Clock ip name array for LPTMR. More...
 
#define ADC16_CLOCKS
 Clock ip name array for ADC16. More...
 
#define TRNG_CLOCKS
 Clock ip name array for TRNG. More...
 
#define EDMA_CLOCKS
 Clock ip name array for DMA. More...
 
#define CMT_CLOCKS
 Clock ip name array for CMT. More...
 
#define TPM_CLOCKS
 Clock ip name array for TPM. More...
 
#define LTC_CLOCKS
 Clock ip name array for LTC. More...
 
#define I2C_CLOCKS
 Clock ip name array for I2C. More...
 
#define CMP_CLOCKS
 Clock ip name array for CMP. More...
 
#define VREF_CLOCKS
 Clock ip name array for VREF. More...
 
#define DCDC_CLOCKS
 Clock ip name array for DCDC. More...
 
#define LPO_CLK_FREQ   1000U
 LPO clock frequency.
 
#define SYS_CLK   kCLOCK_CoreSysClk
 Prepherials clock source definition. More...
 

Enumerations

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_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_mode_t {
  kOSC_ModeExt = 0U,
  kOSC_ModeOscLowPower = MCG_C2_EREFS0_MASK,
  kOSC_ModeOscHighGain
}
 OSC work mode. More...
 
enum  mcg_fll_src_t {
  kMCG_FllSrcExternal,
  kMCG_FllSrcInternal
}
 MCG FLL reference clock source select. More...
 
enum  mcg_irc_mode_t {
  kMCG_IrcSlow,
  kMCG_IrcFast
}
 MCG internal reference clock select. More...
 
enum  mcg_dmx32_t {
  kMCG_Dmx32Default,
  kMCG_Dmx32Fine
}
 MCG DCO Maximum Frequency with 32.768 kHz Reference. More...
 
enum  mcg_drs_t {
  kMCG_DrsLow,
  kMCG_DrsMid,
  kMCG_DrsMidHigh,
  kMCG_DrsHigh
}
 MCG DCO range select. More...
 
enum  mcg_pll_ref_src_t {
  kMCG_PllRefOsc0,
  kMCG_PllRefOsc1
}
 MCG PLL reference clock select. More...
 
enum  mcg_clkout_src_t {
  kMCG_ClkOutSrcOut,
  kMCG_ClkOutSrcInternal,
  kMCG_ClkOutSrcExternal
}
 MCGOUT clock source. More...
 
enum  mcg_atm_select_t {
  kMCG_AtmSel32k,
  kMCG_AtmSel4m
}
 MCG Automatic Trim Machine Select. More...
 
enum  mcg_oscsel_t {
  kMCG_OscselOsc,
  kMCG_OscselRtc
}
 MCG OSC Clock Select. More...
 
enum  mcg_pll_clk_select_t { kMCG_PllClkSelPll0 }
 MCG PLLCS select. More...
 
enum  mcg_monitor_mode_t {
  kMCG_MonitorNone,
  kMCG_MonitorInt,
  kMCG_MonitorReset
}
 MCG clock monitor mode. More...
 
enum  _mcg_status {
  kStatus_MCG_ModeUnreachable = MAKE_STATUS(kStatusGroup_MCG, 0),
  kStatus_MCG_ModeInvalid = MAKE_STATUS(kStatusGroup_MCG, 1),
  kStatus_MCG_AtmBusClockInvalid = MAKE_STATUS(kStatusGroup_MCG, 2),
  kStatus_MCG_AtmDesiredFreqInvalid = MAKE_STATUS(kStatusGroup_MCG, 3),
  kStatus_MCG_AtmIrcUsed = MAKE_STATUS(kStatusGroup_MCG, 4),
  kStatus_MCG_AtmHardwareFail = MAKE_STATUS(kStatusGroup_MCG, 5),
  kStatus_MCG_SourceUsed = MAKE_STATUS(kStatusGroup_MCG, 6)
}
 MCG status. More...
 
enum  _mcg_status_flags_t { kMCG_RtcOscLostFlag = (1U << 4U) }
 MCG status flags. More...
 
enum  _mcg_irclk_enable_mode {
  kMCG_IrclkEnable = MCG_C1_IRCLKEN_MASK,
  kMCG_IrclkEnableInStop = MCG_C1_IREFSTEN_MASK
}
 MCG internal reference clock (MCGIRCLK) enable mode definition. More...
 
enum  mcg_mode_t {
  kMCG_ModeFEI = 0U,
  kMCG_ModeFBI,
  kMCG_ModeBLPI,
  kMCG_ModeFEE,
  kMCG_ModeFBE,
  kMCG_ModeBLPE,
  kMCG_ModeError
}
 MCG mode definitions. More...
 

Functions

static void CLOCK_EnableClock (clock_ip_name_t name)
 Enable the clock for specific IP. More...
 
static void CLOCK_DisableClock (clock_ip_name_t name)
 Disable the clock for specific IP. More...
 
static void CLOCK_SetEr32kClock (uint32_t src)
 Set ERCLK32K source. More...
 
static void CLOCK_SetLpuartClock (uint32_t src)
 Set LPUART clock source. More...
 
static void CLOCK_SetTpmClock (uint32_t src)
 Set TPM clock source. More...
 
static void CLOCK_SetClkOutClock (uint32_t src)
 Set CLKOUT source. More...
 
static void CLOCK_SetOutDiv (uint32_t outdiv1, uint32_t outdiv4)
 System clock divider. More...
 
uint32_t CLOCK_GetFreq (clock_name_t clockName)
 Gets the clock frequency for a specific clock name. More...
 
uint32_t CLOCK_GetCoreSysClkFreq (void)
 Get the core clock or system clock frequency. More...
 
uint32_t CLOCK_GetPlatClkFreq (void)
 Get the platform clock frequency. More...
 
uint32_t CLOCK_GetBusClkFreq (void)
 Get the bus clock frequency. More...
 
uint32_t CLOCK_GetFlashClkFreq (void)
 Get the flash clock frequency. More...
 
uint32_t CLOCK_GetEr32kClkFreq (void)
 Get the external reference 32K clock frequency (ERCLK32K). More...
 
uint32_t CLOCK_GetOsc0ErClkFreq (void)
 Get the OSC0 external reference clock frequency (OSC0ERCLK). More...
 
void CLOCK_SetSimConfig (sim_clock_config_t const *config)
 Set the clock configure in SIM module. More...
 
static void CLOCK_SetSimSafeDivs (void)
 Set the system clock dividers in SIM to safe value. More...
 

Variables

uint32_t g_xtal0Freq
 External XTAL0 (OSC0) clock frequency. More...
 
uint32_t g_xtal32Freq
 External XTAL32/EXTAL32/RTC_CLKIN clock frequency. More...
 

Driver version

#define FSL_CLOCK_DRIVER_VERSION   (MAKE_VERSION(2, 2, 1))
 CLOCK driver version 2.2.1. More...
 

MCG frequency functions.

uint32_t CLOCK_GetOutClkFreq (void)
 Gets the MCG output clock (MCGOUTCLK) frequency. More...
 
uint32_t CLOCK_GetFllFreq (void)
 Gets the MCG FLL clock (MCGFLLCLK) frequency. More...
 
uint32_t CLOCK_GetInternalRefClkFreq (void)
 Gets the MCG internal reference clock (MCGIRCLK) frequency. More...
 
uint32_t CLOCK_GetFixedFreqClkFreq (void)
 Gets the MCG fixed frequency clock (MCGFFCLK) frequency. More...
 

MCG clock configuration.

static void CLOCK_SetLowPowerEnable (bool enable)
 Enables or disables the MCG low power. More...
 
status_t CLOCK_SetInternalRefClkConfig (uint8_t enableMode, mcg_irc_mode_t ircs, uint8_t fcrdiv)
 Configures the Internal Reference clock (MCGIRCLK). More...
 
status_t CLOCK_SetExternalRefClkConfig (mcg_oscsel_t oscsel)
 Selects the MCG external reference clock. More...
 
static void CLOCK_SetFllExtRefDiv (uint8_t frdiv)
 Set the FLL external reference clock divider value. More...
 

MCG clock lock monitor functions.

void CLOCK_SetRtcOscMonitorMode (mcg_monitor_mode_t mode)
 Sets the RTC OSC clock monitor mode. More...
 
uint32_t CLOCK_GetStatusFlags (void)
 Gets the MCG status flags. More...
 
void CLOCK_ClearStatusFlags (uint32_t mask)
 Clears the MCG status flags. More...
 

OSC configuration

void CLOCK_InitOsc0 (osc_config_t const *config)
 Initializes the OSC0. More...
 
void CLOCK_DeinitOsc0 (void)
 Deinitializes the OSC0. More...
 

External clock frequency

static void CLOCK_SetXtal0Freq (uint32_t freq)
 Sets the XTAL0 frequency based on board settings. More...
 
static void CLOCK_SetXtal32Freq (uint32_t freq)
 Sets the XTAL32/RTC_CLKIN frequency based on board settings. More...
 

MCG auto-trim machine.

status_t CLOCK_TrimInternalRefClk (uint32_t extFreq, uint32_t desireFreq, uint32_t *actualFreq, mcg_atm_select_t atms)
 Auto trims the internal reference clock. More...
 

MCG mode functions.

mcg_mode_t CLOCK_GetMode (void)
 Gets the current MCG mode. More...
 
status_t CLOCK_SetFeiMode (mcg_dmx32_t dmx32, mcg_drs_t drs, void(*fllStableDelay)(void))
 Sets the MCG to FEI mode. More...
 
status_t CLOCK_SetFeeMode (uint8_t frdiv, mcg_dmx32_t dmx32, mcg_drs_t drs, void(*fllStableDelay)(void))
 Sets the MCG to FEE mode. More...
 
status_t CLOCK_SetFbiMode (mcg_dmx32_t dmx32, mcg_drs_t drs, void(*fllStableDelay)(void))
 Sets the MCG to FBI mode. More...
 
status_t CLOCK_SetFbeMode (uint8_t frdiv, mcg_dmx32_t dmx32, mcg_drs_t drs, void(*fllStableDelay)(void))
 Sets the MCG to FBE mode. More...
 
status_t CLOCK_SetBlpiMode (void)
 Sets the MCG to BLPI mode. More...
 
status_t CLOCK_SetBlpeMode (void)
 Sets the MCG to BLPE mode. More...
 
status_t CLOCK_ExternalModeToFbeModeQuick (void)
 Switches the MCG to FBE mode from the external mode. More...
 
status_t CLOCK_InternalModeToFbiModeQuick (void)
 Switches the MCG to FBI mode from internal modes. More...
 
status_t CLOCK_BootToFeiMode (mcg_dmx32_t dmx32, mcg_drs_t drs, void(*fllStableDelay)(void))
 Sets the MCG to FEI mode during system boot up. More...
 
status_t CLOCK_BootToFeeMode (mcg_oscsel_t oscsel, uint8_t frdiv, mcg_dmx32_t dmx32, mcg_drs_t drs, void(*fllStableDelay)(void))
 Sets the MCG to FEE mode during system bootup. More...
 
status_t CLOCK_BootToBlpiMode (uint8_t fcrdiv, mcg_irc_mode_t ircs, uint8_t ircEnableMode)
 Sets the MCG to BLPI mode during system boot up. More...
 
status_t CLOCK_BootToBlpeMode (mcg_oscsel_t oscsel)
 Sets the MCG to BLPE mode during sytem boot up. More...
 
status_t CLOCK_SetMcgConfig (mcg_config_t const *config)
 Sets the MCG to a target mode. More...
 

Data Structure Documentation

struct sim_clock_config_t

Data Fields

uint8_t pllFllSel
 PLL/FLL/IRC48M selection. More...
 
uint8_t pllFllDiv
 PLLFLLSEL clock divider divisor. More...
 
uint8_t pllFllFrac
 PLLFLLSEL clock divider fraction. More...
 
uint8_t er32kSrc
 ERCLK32K source selection. More...
 
uint32_t clkdiv1
 SIM_CLKDIV1. More...
 

Field Documentation

uint8_t sim_clock_config_t::pllFllSel
uint8_t sim_clock_config_t::pllFllDiv
uint8_t sim_clock_config_t::pllFllFrac
uint8_t sim_clock_config_t::er32kSrc
uint32_t sim_clock_config_t::clkdiv1
struct osc_config_t

Defines the configuration data structure to initialize the OSC. When porting to a new board, set the following members according to the board setting:

  1. freq: The external frequency.
  2. workMode: The OSC module mode.

Data Fields

uint32_t freq
 External clock frequency. More...
 
osc_mode_t workMode
 OSC work mode setting. More...
 

Field Documentation

uint32_t osc_config_t::freq
osc_mode_t osc_config_t::workMode
struct mcg_config_t

When porting to a new board, set the following members according to the board setting:

  1. frdiv: If the FLL uses the external reference clock, set this value to ensure that the external reference clock divided by frdiv is in the 31.25 kHz to 39.0625 kHz range.
  2. The PLL reference clock divider PRDIV: PLL reference clock frequency after PRDIV should be in the FSL_FEATURE_MCG_PLL_REF_MIN to FSL_FEATURE_MCG_PLL_REF_MAX range.

Data Fields

mcg_mode_t mcgMode
 MCG mode. More...
 
uint8_t irclkEnableMode
 MCGIRCLK enable mode. More...
 
mcg_irc_mode_t ircs
 Source, MCG_C2[IRCS]. More...
 
uint8_t fcrdiv
 Divider, MCG_SC[FCRDIV]. More...
 
uint8_t frdiv
 Divider MCG_C1[FRDIV]. More...
 
mcg_drs_t drs
 DCO range MCG_C4[DRST_DRS]. More...
 
mcg_dmx32_t dmx32
 MCG_C4[DMX32]. More...
 
mcg_oscsel_t oscsel
 OSC select MCG_C7[OSCSEL]. More...
 

Field Documentation

mcg_mode_t mcg_config_t::mcgMode
uint8_t mcg_config_t::irclkEnableMode
mcg_irc_mode_t mcg_config_t::ircs
uint8_t mcg_config_t::fcrdiv
uint8_t mcg_config_t::frdiv
mcg_drs_t mcg_config_t::drs
mcg_dmx32_t mcg_config_t::dmx32
mcg_oscsel_t mcg_config_t::oscsel

Macro Definition Documentation

#define MCG_CONFIG_CHECK_PARAM   0U

Some MCG settings must be changed with conditions, for example:

  1. MCGIRCLK settings, such as the source, divider, and the trim value should not change when MCGIRCLK is used as a system clock source.
  2. MCG_C7[OSCSEL] should not be changed when the external reference clock is used as a system clock source. For example, in FBE/BLPE/PBE modes.
  3. The users should only switch between the supported clock modes.

MCG functions check the parameter and MCG status before setting, if not allowed to change, the functions return error. The parameter checking increases code size, if code size is a critical requirement, change MCG_CONFIG_CHECK_PARAM to 0 to disable parameter checking.

#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.
#define FSL_CLOCK_DRIVER_VERSION   (MAKE_VERSION(2, 2, 1))
#define DMAMUX_CLOCKS
Value:
{ \
kCLOCK_Dmamux0 \
}
#define RTC_CLOCKS
Value:
{ \
kCLOCK_Rtc0 \
}
#define PIT_CLOCKS
Value:
{ \
kCLOCK_Pit0 \
}
#define PORT_CLOCKS
Value:
{ \
kCLOCK_PortA, kCLOCK_PortB, kCLOCK_PortC \
}
#define TSI_CLOCKS
Value:
{ \
kCLOCK_Tsi0 \
}
#define DSPI_CLOCKS
Value:
{ \
kCLOCK_Spi0, kCLOCK_Spi1 \
}
#define LPUART_CLOCKS
Value:
{ \
kCLOCK_Lpuart0 \
}
#define DAC_CLOCKS
Value:
{ \
kCLOCK_Dac0 \
}
#define LPTMR_CLOCKS
Value:
{ \
kCLOCK_Lptmr0 \
}
#define ADC16_CLOCKS
Value:
{ \
kCLOCK_Adc0 \
}
#define TRNG_CLOCKS
Value:
{ \
kCLOCK_Trng0 \
}
#define EDMA_CLOCKS
Value:
{ \
kCLOCK_Dma0 \
}
#define CMT_CLOCKS
Value:
{ \
kCLOCK_Cmt0 \
}
#define TPM_CLOCKS
Value:
{ \
kCLOCK_Tpm0, kCLOCK_Tpm1, kCLOCK_Tpm2 \
}
#define LTC_CLOCKS
Value:
{ \
kCLOCK_Ltc0 \
}
#define I2C_CLOCKS
Value:
{ \
kCLOCK_I2c0, kCLOCK_I2c1 \
}
#define CMP_CLOCKS
Value:
{ \
kCLOCK_Cmp0 \
}
#define VREF_CLOCKS
Value:
{ \
kCLOCK_Vref0 \
}
#define DCDC_CLOCKS
Value:
{ \
kCLOCK_Dcdc0 \
}
#define SYS_CLK   kCLOCK_CoreSysClk

Enumeration Type Documentation

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_LpoClk 

LPO clock.

enum osc_mode_t
Enumerator
kOSC_ModeExt 

Use an external clock.

kOSC_ModeOscLowPower 

Oscillator low power.

kOSC_ModeOscHighGain 

Oscillator high gain.

Enumerator
kMCG_FllSrcExternal 

External reference clock is selected.

kMCG_FllSrcInternal 

The slow internal reference clock is selected.

Enumerator
kMCG_IrcSlow 

Slow internal reference clock selected.

kMCG_IrcFast 

Fast internal reference clock selected.

Enumerator
kMCG_Dmx32Default 

DCO has a default range of 25%.

kMCG_Dmx32Fine 

DCO is fine-tuned for maximum frequency with 32.768 kHz reference.

enum mcg_drs_t
Enumerator
kMCG_DrsLow 

Low frequency range.

kMCG_DrsMid 

Mid frequency range.

kMCG_DrsMidHigh 

Mid-High frequency range.

kMCG_DrsHigh 

High frequency range.

Enumerator
kMCG_PllRefOsc0 

Selects OSC0 as PLL reference clock.

kMCG_PllRefOsc1 

Selects OSC1 as PLL reference clock.

Enumerator
kMCG_ClkOutSrcOut 

Output of the FLL is selected (reset default)

kMCG_ClkOutSrcInternal 

Internal reference clock is selected.

kMCG_ClkOutSrcExternal 

External reference clock is selected.

Enumerator
kMCG_AtmSel32k 

32 kHz Internal Reference Clock selected

kMCG_AtmSel4m 

4 MHz Internal Reference Clock selected

Enumerator
kMCG_OscselOsc 

Selects System Oscillator (OSCCLK)

kMCG_OscselRtc 

Selects 32 kHz RTC Oscillator.

Enumerator
kMCG_PllClkSelPll0 

PLL0 output clock is selected.

Enumerator
kMCG_MonitorNone 

Clock monitor is disabled.

kMCG_MonitorInt 

Trigger interrupt when clock lost.

kMCG_MonitorReset 

System reset when clock lost.

Enumerator
kStatus_MCG_ModeUnreachable 

Can't switch to target mode.

kStatus_MCG_ModeInvalid 

Current mode invalid for the specific function.

kStatus_MCG_AtmBusClockInvalid 

Invalid bus clock for ATM.

kStatus_MCG_AtmDesiredFreqInvalid 

Invalid desired frequency for ATM.

kStatus_MCG_AtmIrcUsed 

IRC is used when using ATM.

kStatus_MCG_AtmHardwareFail 

Hardware fail occurs during ATM.

kStatus_MCG_SourceUsed 

Can't change the clock source because it is in use.

Enumerator
kMCG_RtcOscLostFlag 

RTC OSC lost.

Enumerator
kMCG_IrclkEnable 

MCGIRCLK enable.

kMCG_IrclkEnableInStop 

MCGIRCLK enable in stop mode.

enum mcg_mode_t
Enumerator
kMCG_ModeFEI 

FEI - FLL Engaged Internal.

kMCG_ModeFBI 

FBI - FLL Bypassed Internal.

kMCG_ModeBLPI 

BLPI - Bypassed Low Power Internal.

kMCG_ModeFEE 

FEE - FLL Engaged External.

kMCG_ModeFBE 

FBE - FLL Bypassed External.

kMCG_ModeBLPE 

BLPE - Bypassed Low Power External.

kMCG_ModeError 

Unknown mode.

Function Documentation

static void CLOCK_EnableClock ( clock_ip_name_t  name)
inlinestatic
Parameters
nameWhich clock to enable, see clock_ip_name_t.
static void CLOCK_DisableClock ( clock_ip_name_t  name)
inlinestatic
Parameters
nameWhich clock to disable, see clock_ip_name_t.
static void CLOCK_SetEr32kClock ( uint32_t  src)
inlinestatic
Parameters
srcThe value to set ERCLK32K clock source.
static void CLOCK_SetLpuartClock ( uint32_t  src)
inlinestatic
Parameters
srcThe value to set LPUART clock source.
static void CLOCK_SetTpmClock ( uint32_t  src)
inlinestatic
Parameters
srcThe value to set TPM clock source.
static void CLOCK_SetClkOutClock ( uint32_t  src)
inlinestatic
Parameters
srcThe value to set CLKOUT source.
static void CLOCK_SetOutDiv ( uint32_t  outdiv1,
uint32_t  outdiv4 
)
inlinestatic

Set the SIM_CLKDIV1[OUTDIV1], SIM_CLKDIV1[OUTDIV4].

Parameters
outdiv1Clock 1 output divider value.
outdiv4Clock 4 output divider value.
uint32_t CLOCK_GetFreq ( clock_name_t  clockName)

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
clockNameClock 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.
void CLOCK_SetSimConfig ( sim_clock_config_t const *  config)

This function sets system layer clock settings in SIM module.

Parameters
configPointer 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
configPointer to the configure structure.
uint32_t CLOCK_GetOutClkFreq ( void  )

This function gets the MCG output clock frequency in Hz based on the current MCG register value.

Returns
The frequency of MCGOUTCLK.
uint32_t CLOCK_GetFllFreq ( void  )

This function gets the MCG FLL clock frequency in Hz based on the current MCG register value. The FLL is enabled in FEI/FBI/FEE/FBE mode and disabled in low power state in other modes.

Returns
The frequency of MCGFLLCLK.
uint32_t CLOCK_GetInternalRefClkFreq ( void  )

This function gets the MCG internal reference clock frequency in Hz based on the current MCG register value.

Returns
The frequency of MCGIRCLK.
uint32_t CLOCK_GetFixedFreqClkFreq ( void  )

This function gets the MCG fixed frequency clock frequency in Hz based on the current MCG register value.

Returns
The frequency of MCGFFCLK.
static void CLOCK_SetLowPowerEnable ( bool  enable)
inlinestatic

Enabling the MCG low power disables the PLL and FLL in bypass modes. In other words, in FBE and PBE modes, enabling low power sets the MCG to BLPE mode. In FBI and PBI modes, enabling low power sets the MCG to BLPI mode. When disabling the MCG low power, the PLL or FLL are enabled based on MCG settings.

Parameters
enableTrue to enable MCG low power, false to disable MCG low power.
status_t CLOCK_SetInternalRefClkConfig ( uint8_t  enableMode,
mcg_irc_mode_t  ircs,
uint8_t  fcrdiv 
)

This function sets the MCGIRCLK base on parameters. It also selects the IRC source. If the fast IRC is used, this function sets the fast IRC divider. This function also sets whether the MCGIRCLK is enabled in stop mode. Calling this function in FBI/PBI/BLPI modes may change the system clock. As a result, using the function in these modes it is not allowed.

Parameters
enableModeMCGIRCLK enable mode, OR'ed value of _mcg_irclk_enable_mode.
ircsMCGIRCLK clock source, choose fast or slow.
fcrdivFast IRC divider setting (FCRDIV).
Return values
kStatus_MCG_SourceUsedBecause the internall reference clock is used as a clock source, the confuration should not be changed. Otherwise, a glitch occurs.
kStatus_SuccessMCGIRCLK configuration finished successfully.
status_t CLOCK_SetExternalRefClkConfig ( mcg_oscsel_t  oscsel)

Selects the MCG external reference clock source, changes the MCG_C7[OSCSEL], and waits for the clock source to be stable. Because the external reference clock should not be changed in FEE/FBE/BLPE/PBE/PEE modes, do not call this function in these modes.

Parameters
oscselMCG external reference clock source, MCG_C7[OSCSEL].
Return values
kStatus_MCG_SourceUsedBecause the external reference clock is used as a clock source, the confuration should not be changed. Otherwise, a glitch occurs.
kStatus_SuccessExternal reference clock set successfully.
static void CLOCK_SetFllExtRefDiv ( uint8_t  frdiv)
inlinestatic

Sets the FLL external reference clock divider value, the register MCG_C1[FRDIV].

Parameters
frdivThe FLL external reference clock divider value, MCG_C1[FRDIV].
void CLOCK_SetRtcOscMonitorMode ( mcg_monitor_mode_t  mode)

This function sets the RTC OSC clock monitor mode. See mcg_monitor_mode_t for details.

Parameters
modeMonitor mode to set.
uint32_t CLOCK_GetStatusFlags ( void  )

This function gets the MCG clock status flags. All status flags are returned as a logical OR of the enumeration _mcg_status_flags_t. To check a specific flag, compare the return value with the flag.

Example:

// To check the clock lost lock status of OSC0 and PLL0.
uint32_t mcgFlags;
mcgFlags = CLOCK_GetStatusFlags();
if (mcgFlags & kMCG_Osc0LostFlag)
{
// OSC0 clock lock lost. Do something.
}
if (mcgFlags & kMCG_Pll0LostFlag)
{
// PLL0 clock lock lost. Do something.
}
Returns
Logical OR value of the _mcg_status_flags_t.
void CLOCK_ClearStatusFlags ( uint32_t  mask)

This function clears the MCG clock lock lost status. The parameter is a logical OR value of the flags to clear. See _mcg_status_flags_t.

Example:

// To clear the clock lost lock status flags of OSC0 and PLL0.
CLOCK_ClearStatusFlags(kMCG_Osc0LostFlag | kMCG_Pll0LostFlag);
Parameters
maskThe status flags to clear. This is a logical OR of members of the enumeration _mcg_status_flags_t.
void CLOCK_InitOsc0 ( osc_config_t const *  config)

This function initializes the OSC0 according to the board configuration.

Parameters
configPointer to the OSC0 configuration structure.
void CLOCK_DeinitOsc0 ( void  )

This function deinitializes the OSC0.

static void CLOCK_SetXtal0Freq ( uint32_t  freq)
inlinestatic
Parameters
freqThe XTAL0/EXTAL0 input clock frequency in Hz.
static void CLOCK_SetXtal32Freq ( uint32_t  freq)
inlinestatic
Parameters
freqThe XTAL32/EXTAL32/RTC_CLKIN input clock frequency in Hz.
status_t CLOCK_TrimInternalRefClk ( uint32_t  extFreq,
uint32_t  desireFreq,
uint32_t *  actualFreq,
mcg_atm_select_t  atms 
)

This function trims the internal reference clock by using the external clock. If successful, it returns the kStatus_Success and the frequency after trimming is received in the parameter actualFreq. If an error occurs, the error code is returned.

Parameters
extFreqExternal clock frequency, which should be a bus clock.
desireFreqFrequency to trim to.
actualFreqActual frequency after trimming.
atmsTrim fast or slow internal reference clock.
Return values
kStatus_SuccessATM success.
kStatus_MCG_AtmBusClockInvalidThe bus clock is not in allowed range for the ATM.
kStatus_MCG_AtmDesiredFreqInvalidMCGIRCLK could not be trimmed to the desired frequency.
kStatus_MCG_AtmIrcUsedCould not trim because MCGIRCLK is used as a bus clock source.
kStatus_MCG_AtmHardwareFailHardware fails while trimming.
mcg_mode_t CLOCK_GetMode ( void  )

This function checks the MCG registers and determines the current MCG mode.

Returns
Current MCG mode or error code; See mcg_mode_t.
status_t CLOCK_SetFeiMode ( mcg_dmx32_t  dmx32,
mcg_drs_t  drs,
void(*)(void)  fllStableDelay 
)

This function sets the MCG to FEI mode. If setting to FEI mode fails from the current mode, this function returns an error.

Parameters
dmx32DMX32 in FEI mode.
drsThe DCO range selection.
fllStableDelayDelay function to ensure that the FLL is stable. Passing NULL does not cause a delay.
Return values
kStatus_MCG_ModeUnreachableCould not switch to the target mode.
kStatus_SuccessSwitched to the target mode successfully.
Note
If dmx32 is set to kMCG_Dmx32Fine, the slow IRC must not be trimmed to a frequency above 32768 Hz.
status_t CLOCK_SetFeeMode ( uint8_t  frdiv,
mcg_dmx32_t  dmx32,
mcg_drs_t  drs,
void(*)(void)  fllStableDelay 
)

This function sets the MCG to FEE mode. If setting to FEE mode fails from the current mode, this function returns an error.

Parameters
frdivFLL reference clock divider setting, FRDIV.
dmx32DMX32 in FEE mode.
drsThe DCO range selection.
fllStableDelayDelay function to make sure FLL is stable. Passing NULL does not cause a delay.
Return values
kStatus_MCG_ModeUnreachableCould not switch to the target mode.
kStatus_SuccessSwitched to the target mode successfully.
status_t CLOCK_SetFbiMode ( mcg_dmx32_t  dmx32,
mcg_drs_t  drs,
void(*)(void)  fllStableDelay 
)

This function sets the MCG to FBI mode. If setting to FBI mode fails from the current mode, this function returns an error.

Parameters
dmx32DMX32 in FBI mode.
drsThe DCO range selection.
fllStableDelayDelay function to make sure FLL is stable. If the FLL is not used in FBI mode, this parameter can be NULL. Passing NULL does not cause a delay.
Return values
kStatus_MCG_ModeUnreachableCould not switch to the target mode.
kStatus_SuccessSwitched to the target mode successfully.
Note
If dmx32 is set to kMCG_Dmx32Fine, the slow IRC must not be trimmed to frequency above 32768 Hz.
status_t CLOCK_SetFbeMode ( uint8_t  frdiv,
mcg_dmx32_t  dmx32,
mcg_drs_t  drs,
void(*)(void)  fllStableDelay 
)

This function sets the MCG to FBE mode. If setting to FBE mode fails from the current mode, this function returns an error.

Parameters
frdivFLL reference clock divider setting, FRDIV.
dmx32DMX32 in FBE mode.
drsThe DCO range selection.
fllStableDelayDelay function to make sure FLL is stable. If the FLL is not used in FBE mode, this parameter can be NULL. Passing NULL does not cause a delay.
Return values
kStatus_MCG_ModeUnreachableCould not switch to the target mode.
kStatus_SuccessSwitched to the target mode successfully.
status_t CLOCK_SetBlpiMode ( void  )

This function sets the MCG to BLPI mode. If setting to BLPI mode fails from the current mode, this function returns an error.

Return values
kStatus_MCG_ModeUnreachableCould not switch to the target mode.
kStatus_SuccessSwitched to the target mode successfully.
status_t CLOCK_SetBlpeMode ( void  )

This function sets the MCG to BLPE mode. If setting to BLPE mode fails from the current mode, this function returns an error.

Return values
kStatus_MCG_ModeUnreachableCould not switch to the target mode.
kStatus_SuccessSwitched to the target mode successfully.
status_t CLOCK_ExternalModeToFbeModeQuick ( void  )

This function switches the MCG from external modes (PEE/PBE/BLPE/FEE) to the FBE mode quickly. The external clock is used as the system clock souce and PLL is disabled. However, the FLL settings are not configured. This is a lite function with a small code size, which is useful during the mode switch. For example, to switch from PEE mode to FEI mode:

Return values
kStatus_SuccessSwitched successfully.
kStatus_MCG_ModeInvalidIf the current mode is not an external mode, do not call this function.
status_t CLOCK_InternalModeToFbiModeQuick ( void  )

This function switches the MCG from internal modes (PEI/PBI/BLPI/FEI) to the FBI mode quickly. The MCGIRCLK is used as the system clock souce and PLL is disabled. However, FLL settings are not configured. This is a lite function with a small code size, which is useful during the mode switch. For example, to switch from PEI mode to FEE mode:

Return values
kStatus_SuccessSwitched successfully.
kStatus_MCG_ModeInvalidIf the current mode is not an internal mode, do not call this function.
status_t CLOCK_BootToFeiMode ( mcg_dmx32_t  dmx32,
mcg_drs_t  drs,
void(*)(void)  fllStableDelay 
)

This function sets the MCG to FEI mode from the reset mode. It can also be used to set up MCG during system boot up.

Parameters
dmx32DMX32 in FEI mode.
drsThe DCO range selection.
fllStableDelayDelay function to ensure that the FLL is stable.
Return values
kStatus_MCG_ModeUnreachableCould not switch to the target mode.
kStatus_SuccessSwitched to the target mode successfully.
Note
If dmx32 is set to kMCG_Dmx32Fine, the slow IRC must not be trimmed to frequency above 32768 Hz.
status_t CLOCK_BootToFeeMode ( mcg_oscsel_t  oscsel,
uint8_t  frdiv,
mcg_dmx32_t  dmx32,
mcg_drs_t  drs,
void(*)(void)  fllStableDelay 
)

This function sets MCG to FEE mode from the reset mode. It can also be used to set up the MCG during system boot up.

Parameters
oscselOSC clock select, OSCSEL.
frdivFLL reference clock divider setting, FRDIV.
dmx32DMX32 in FEE mode.
drsThe DCO range selection.
fllStableDelayDelay function to ensure that the FLL is stable.
Return values
kStatus_MCG_ModeUnreachableCould not switch to the target mode.
kStatus_SuccessSwitched to the target mode successfully.
status_t CLOCK_BootToBlpiMode ( uint8_t  fcrdiv,
mcg_irc_mode_t  ircs,
uint8_t  ircEnableMode 
)

This function sets the MCG to BLPI mode from the reset mode. It can also be used to set up the MCG during sytem boot up.

Parameters
fcrdivFast IRC divider, FCRDIV.
ircsThe internal reference clock to select, IRCS.
ircEnableModeThe MCGIRCLK enable mode, OR'ed value of _mcg_irclk_enable_mode.
Return values
kStatus_MCG_SourceUsedCould not change MCGIRCLK setting.
kStatus_SuccessSwitched to the target mode successfully.
status_t CLOCK_BootToBlpeMode ( mcg_oscsel_t  oscsel)

This function sets the MCG to BLPE mode from the reset mode. It can also be used to set up the MCG during sytem boot up.

Parameters
oscselOSC clock select, MCG_C7[OSCSEL].
Return values
kStatus_MCG_ModeUnreachableCould not switch to the target mode.
kStatus_SuccessSwitched to the target mode successfully.
status_t CLOCK_SetMcgConfig ( mcg_config_t const *  config)

This function sets MCG to a target mode defined by the configuration structure. If switching to the target mode fails, this function chooses the correct path.

Parameters
configPointer to the target MCG mode configuration structure.
Returns
Return kStatus_Success if switched successfully; Otherwise, it returns an error code _mcg_status.
Note
If the external clock is used in the target mode, ensure that it is enabled. For example, if the OSC0 is used, set up OSC0 correctly before calling this function.

Variable Documentation

uint32_t g_xtal0Freq

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:

* CLOCK_InitOsc0(...); // Set up the OSC0
* CLOCK_SetXtal0Freq(80000000); // Set the XTAL0 value to the clock driver.
*

This is important for the multicore platforms where only 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.

uint32_t g_xtal32Freq

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 only one core needs to set up the clock. All other cores need to call the CLOCK_SetXtal32Freq to get a valid clock frequency.