The MCUXpresso SDK provides APIs for MCUXpresso SDK devices' clock operation.
The clock driver supports:
- Clock generator (PLL, FLL, and so on) configuration
- Clock mux and divider configuration
- Getting clock frequency
The MCUXpresso SDK provides a peripheral clock driver for the SYSCON module of MCUXpresso SDK devices.
Function description
Clock driver provides these functions:
- Functions to initialize the Core clock to given frequency
- Functions to configure the clock selection muxes.
- Functions to setup peripheral clock dividers
- Functions to set the flash wait states for the input freuqency
- Functions to get the frequency of the selected clock
- Functions to set PLL frequency
SYSCON Clock frequency functions
SYSCON clock module provides clocks, such as MCLKCLK, ADCCLK, DMICCLK, MCGFLLCLK, FXCOMCLK, WDTOSC, RTCOSC, USBCLK, and SYSPLL. The functions CLOCK_EnableClock() and CLOCK_DisableClock() enables and disables the various clocks. CLOCK_SetupFROClocking() initializes the FRO to 12 MHz, 48 MHz, or 96 MHz frequency. CLOCK_SetupPLLData(), CLOCK_SetupSystemPLLPrec(), and CLOCK_SetPLLFreq() functions are used to setup the PLL. The SYSCON clock driver provides functions to get the frequency of these clocks, such as CLOCK_GetFreq(), CLOCK_GetFro12MFreq(), CLOCK_GetExtClkFreq(), CLOCK_GetWdtOscFreq(), CLOCK_GetFroHfFreq(), CLOCK_GetPllOutFreq(), CLOCK_GetOsc32KFreq(), CLOCK_GetCoreSysClkFreq(), CLOCK_GetI2SMClkFreq(), CLOCK_GetFlexCommClkFreq, and CLOCK_GetAsyncApbClkFreq.
SYSCON clock Selection Muxes
The SYSCON clock driver provides the function to configure the clock selected. The function CLOCK_AttachClk() is implemented for this. The function selects the clock source for a particular peripheral like MAINCLK, DMIC, FLEXCOMM, USB, ADC, and PLL.
SYSCON clock dividers
The SYSCON clock module provides the function to setup the peripheral clock dividers. The function CLOCK_SetClkDiv() configures the CLKDIV registers for various periperals like USB, DMIC, I2S, SYSTICK, AHB, ADC, and also CLKOUT and TRACE functions.
SYSCON flash wait states
The SYSCON clock driver provides the function CLOCK_SetFLASHAccessCyclesForFreq() that configures FLASHCFG register with a selected FLASHTIM value.
Typical use case
POWER_DisablePD(kPDRUNCFG_PD_FRO_EN); /*!< Ensure FRO is on so that we can switch to its 12MHz mode temporarily
|
enum | clock_ip_name_t |
| Clock gate name used for CLOCK_EnableClock/CLOCK_DisableClock. More...
|
|
enum | clock_name_t {
kCLOCK_CoreSysClk,
kCLOCK_MainClk,
kCLOCK_SysOsc,
kCLOCK_Irc,
kCLOCK_ExtClk,
kCLOCK_PllOut,
kCLOCK_Pllin,
kCLOCK_WdtOsc
} |
| Clock name used to get clock frequency. More...
|
|
enum | clock_select_t |
| Clock Mux Switches CLK_MUX_DEFINE(reg, mux) reg is used to define the mux register mux is used to define the mux value. More...
|
|
enum | clock_divider_t |
| Clock divider.
|
|
enum | clock_wdt_analog_freq_t |
| watch dog analog output frequency
|
|
enum | clock_sys_pll_src {
kCLOCK_SysPllSrcIrc = 0U,
kCLOCK_SysPllSrcSysosc = 1U,
kCLOCK_SysPllSrcExtClk = 3U
} |
| PLL clock definition. More...
|
|
enum | clock_main_clk_src_t {
kCLOCK_MainClkSrcIrc = CLK_MAIN_CLK_MUX_DEFINE(0U, 0U),
kCLOCK_MainClkSrcSysPllin = CLK_MAIN_CLK_MUX_DEFINE(1U, 0U),
kCLOCK_MainClkSrcWdtOsc = CLK_MAIN_CLK_MUX_DEFINE(2U, 0U),
kCLOCK_MainClkSrcSysPll = CLK_MAIN_CLK_MUX_DEFINE(3U, 0U)
} |
| Main clock source definition. More...
|
|
Data Fields |
uint32_t | targetFreq |
| System pll fclk output frequency, the output frequency should be lower than 100MHZ.
|
|
clock_sys_pll_src | src |
| System pll clock source.
|
|
Value:{ \
kCLOCK_Uart0, kCLOCK_Uart1, kCLOCK_Uart2, \
}
Value:{ \
kCLOCK_Spi0, kCLOCK_Spi1, \
}
#define CLK_GATE_DEFINE |
( |
|
reg, |
|
|
|
bit |
|
) |
| ((((reg)&0xFFU) << 8U) | ((bit)&0xFFU)) |
Enumerator |
---|
kCLOCK_CoreSysClk |
Cpu/AHB/AHB matrix/Memories,etc.
|
kCLOCK_MainClk |
Main clock.
|
kCLOCK_SysOsc |
Crystal Oscillator.
|
kCLOCK_Irc |
IRC12M.
|
kCLOCK_ExtClk |
External Clock.
|
kCLOCK_PllOut |
PLL Output.
|
kCLOCK_Pllin |
PLL Input.
|
kCLOCK_WdtOsc |
Watchdog Oscillator.
|
Enumerator |
---|
kCLOCK_SysPllSrcIrc |
system pll source from FRO
|
kCLOCK_SysPllSrcSysosc |
system pll source from system osc
|
kCLOCK_SysPllSrcExtClk |
system pll source from ext clkin
|
Enumerator |
---|
kCLOCK_MainClkSrcIrc |
main clock source from FRO
|
kCLOCK_MainClkSrcSysPllin |
main clock source from pll input
|
kCLOCK_MainClkSrcWdtOsc |
main clock source from watchdog oscillator
|
kCLOCK_MainClkSrcSysPll |
main clock source from system pll
|
- Parameters
-
src | Refer to clock_main_clk_src_t to set the main clock source. |
uint32_t CLOCK_GetMainClkFreq |
( |
void |
| ) |
|
- Returns
- Frequency of Main Clock.
static uint32_t CLOCK_GetCoreSysClkFreq |
( |
void |
| ) |
|
|
inlinestatic |
- Returns
- Frequency of core.
uint32_t CLOCK_GetClockOutClkFreq |
( |
void |
| ) |
|
- Returns
- Frequency of ClockOut
uint32_t CLOCK_GetIrcFreq |
( |
void |
| ) |
|
uint32_t CLOCK_GetSysOscFreq |
( |
void |
| ) |
|
- Returns
- Frequency of SYSOSC
uint32_t CLOCK_GetUartClkFreq |
( |
void |
| ) |
|
- Returns
- Frequency of selected clock
uint32_t CLOCK_GetSystemPLLInClockRate |
( |
void |
| ) |
|
- Returns
- System PLL input clock rate
static uint32_t CLOCK_GetSystemPLLFreq |
( |
void |
| ) |
|
|
inlinestatic |
static uint32_t CLOCK_GetWdtOscFreq |
( |
void |
| ) |
|
|
inlinestatic |
- Return values
-
watch | dog OSC frequency value. |
static uint32_t CLOCK_GetExtClkFreq |
( |
void |
| ) |
|
|
inlinestatic |
- Return values
-
external | clock frequency value. |
- Parameters
-
config | System PLL configurations. |
static void CLOCK_DenitSystemPll |
( |
void |
| ) |
|
|
inlinestatic |
void CLOCK_InitExtClkin |
( |
uint32_t |
clkInFreq | ) |
|
- Parameters
-
clkInFreq | external clock in frequency. |
void CLOCK_InitSysOsc |
( |
uint32_t |
oscFreq | ) |
|
- Parameters
-
oscFreq | oscillator frequency value. |
void CLOCK_InitXtalin |
( |
uint32_t |
xtalInFreq | ) |
|
- Parameters
-
xtalInFreq | XTALIN frequency value |
- Returns
- Frequency of PLL
The watchdog oscillator is the clock source with the lowest power consumption. If accurate timing is required, use the FRO or system oscillator. The frequency of the watchdog oscillator is undefined after reset. The watchdog oscillator frequency must be programmed by writing to the WDTOSCCTRL register before using the watchdog oscillator. Watchdog osc output frequency = wdtOscFreq / wdtOscDiv, should in range 9.3KHZ to 2.3MHZ.
- Parameters
-
wdtOscFreq | watch dog analog part output frequency, reference _wdt_analog_output_freq. |
wdtOscDiv | watch dog analog part output frequency divider, shoule be a value >= 2U and multiple of 2 |
bool CLOCK_SetUARTFRGClkFreq |
( |
uint32_t |
freq | ) |
|
- Parameters
-
freq | The frequency specified by src. |
static void CLOCK_SetUARTFRGMULT |
( |
uint32_t |
mul | ) |
|
|
inlinestatic |
- Deprecated:
- Do not use this function. Refer to CLOCK_SetFRGClkMul().
- Parameters
-
volatile uint32_t g_Wdt_Osc_Freq |
This variable is used to store the watchdog oscillator frequency which is set by CLOCK_InitWdtOsc, and it is returned by CLOCK_GetWdtOscFreq.
volatile uint32_t g_Ext_Clk_Freq |
This variable is used to store the external clock frequency which is include external oscillator clock and external clk in clock frequency value, it is set by CLOCK_InitExtClkin when CLK IN is used as external clock or by CLOCK_InitSysOsc when external oscillator is used as external clock ,and it is returned by CLOCK_GetExtClkFreq.