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 a peripheral clock driver for the SYSCON module of MCUXpresso SDK devices.

Function description

Clock driver provides these functions:

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 

Files

file  fsl_clock.h
 

Data Structures

struct  clock_sys_pll_t
 PLL configuration structure. More...
 

Macros

#define CLOCK_FRO_SETTING_API_ROM_ADDRESS   (0x0F0026F5U)
 FRO clock setting API address in ROM. More...
 
#define CLOCK_FAIM_BASE   (0x50010000U)
 FAIM base address.
 
#define ADC_CLOCKS
 Clock ip name array for ADC. More...
 
#define ACMP_CLOCKS
 Clock ip name array for ACMP. More...
 
#define DAC_CLOCKS
 Clock ip name array for DAC. More...
 
#define SWM_CLOCKS
 Clock ip name array for SWM. More...
 
#define ROM_CLOCKS
 Clock ip name array for ROM. More...
 
#define SRAM_CLOCKS
 Clock ip name array for SRAM. More...
 
#define IOCON_CLOCKS
 Clock ip name array for IOCON. More...
 
#define GPIO_CLOCKS
 Clock ip name array for GPIO. More...
 
#define GPIO_INT_CLOCKS
 Clock ip name array for GPIO_INT. More...
 
#define DMA_CLOCKS
 Clock ip name array for DMA. More...
 
#define CRC_CLOCKS
 Clock ip name array for CRC. More...
 
#define WWDT_CLOCKS
 Clock ip name array for WWDT. More...
 
#define SCT_CLOCKS
 Clock ip name array for SCT0. More...
 
#define I2C_CLOCKS
 Clock ip name array for I2C. More...
 
#define USART_CLOCKS
 Clock ip name array for I2C. More...
 
#define SPI_CLOCKS
 Clock ip name array for SPI. More...
 
#define CAPT_CLOCKS
 Clock ip name array for CAPT. More...
 
#define CTIMER_CLOCKS
 Clock ip name array for CTIMER. More...
 
#define MTB_CLOCKS
 Clock ip name array for MTB. More...
 
#define MRT_CLOCKS
 Clock ip name array for MRT. More...
 
#define WKT_CLOCKS
 Clock ip name array for WKT. More...
 
#define CLK_GATE_DEFINE(reg, bit)   ((((reg)&0xFFU) << 8U) | ((bit)&0xFFU))
 Internal used Clock definition only. More...
 

Enumerations

enum  clock_ip_name_t
 Clock gate name used for CLOCK_EnableClock/CLOCK_DisableClock. More...
 
enum  clock_name_t {
  kCLOCK_CoreSysClk,
  kCLOCK_MainClk,
  kCLOCK_Fro,
  kCLOCK_FroDiv,
  kCLOCK_ExtClk,
  kCLOCK_PllOut,
  kCLOCK_WdtOsc,
  kCLOCK_Frg0,
  kCLOCK_Frg1
}
 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_fro_src_t {
  kCLOCK_FroSrcLpwrBootValue = 0U,
  kCLOCK_FroSrcFroOsc = 1U << SYSCON_FROOSCCTRL_FRO_DIRECT_SHIFT
}
 fro output frequency source definition More...
 
enum  clock_fro_osc_freq_t {
  kCLOCK_FroOscOut18M = 18000U,
  kCLOCK_FroOscOut24M = 24000U,
  kCLOCK_FroOscOut30M = 30000U
}
 fro oscillator output frequency value definition More...
 
enum  clock_sys_pll_src {
  kCLOCK_SysPllSrcFRO = 0U,
  kCLOCK_SysPllSrcExtClk = 1U,
  kCLOCK_SysPllSrcWdtOsc = 2U,
  kCLOCK_SysPllSrcFroDiv = 3U
}
 PLL clock definition. More...
 
enum  clock_main_clk_src_t {
  kCLOCK_MainClkSrcFro = CLK_MAIN_CLK_MUX_DEFINE(0U, 0U),
  kCLOCK_MainClkSrcExtClk = CLK_MAIN_CLK_MUX_DEFINE(1U, 0U),
  kCLOCK_MainClkSrcWdtOsc = CLK_MAIN_CLK_MUX_DEFINE(2U, 0U),
  kCLOCK_MainClkSrcFroDiv = CLK_MAIN_CLK_MUX_DEFINE(3U, 0U),
  kCLOCK_MainClkSrcSysPll = CLK_MAIN_CLK_MUX_DEFINE(0U, 1U)
}
 

Variables

volatile uint32_t g_Wdt_Osc_Freq
 watchdog oscilltor clock frequency. More...
 
volatile uint32_t g_Ext_Clk_Freq
 external clock frequency. More...
 

Driver version

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

Clock gate, mux, and divider.

static void CLOCK_EnableClock (clock_ip_name_t clk)
 
static void CLOCK_DisableClock (clock_ip_name_t clk)
 
static void CLOCK_Select (clock_select_t sel)
 
static void CLOCK_SetClkDivider (clock_divider_t name, uint32_t value)
 
static uint32_t CLOCK_GetClkDivider (clock_divider_t name)
 
static void CLOCK_SetCoreSysClkDiv (uint32_t value)
 
void CLOCK_SetMainClkSrc (clock_main_clk_src_t src)
 Set main clock reference source. More...
 
void CLOCK_SetFroOutClkSrc (clock_fro_src_t src)
 Set FRO clock source. More...
 
static void CLOCK_SetFRGClkMul (uint32_t *base, uint32_t mul)
 

Get frequency

uint32_t CLOCK_GetFRG0ClkFreq (void)
 Return Frequency of FRG0 Clock. More...
 
uint32_t CLOCK_GetFRG1ClkFreq (void)
 Return Frequency of FRG1 Clock. More...
 
uint32_t CLOCK_GetMainClkFreq (void)
 Return Frequency of Main Clock. More...
 
uint32_t CLOCK_GetFroFreq (void)
 Return Frequency of FRO. More...
 
static uint32_t CLOCK_GetCoreSysClkFreq (void)
 Return Frequency of core. More...
 
uint32_t CLOCK_GetClockOutClkFreq (void)
 Return Frequency of ClockOut. More...
 
uint32_t CLOCK_GetFreq (clock_name_t clockName)
 Return Frequency of selected clock. More...
 
uint32_t CLOCK_GetSystemPLLInClockRate (void)
 Return System PLL input clock rate. More...
 
static uint32_t CLOCK_GetSystemPLLFreq (void)
 Return Frequency of System PLL. More...
 
static uint32_t CLOCK_GetWdtOscFreq (void)
 Get watch dog OSC frequency. More...
 
static uint32_t CLOCK_GetExtClkFreq (void)
 Get external clock frequency. More...
 

PLL operations

void CLOCK_InitSystemPll (const clock_sys_pll_t *config)
 System PLL initialize. More...
 
static void CLOCK_DenitSystemPll (void)
 System PLL Deinitialize. More...
 

Fractional clock operations

bool CLOCK_SetFRG0ClkFreq (uint32_t freq)
 Set FRG0 output frequency. More...
 
bool CLOCK_SetFRG1ClkFreq (uint32_t freq)
 Set FRG1 output frequency. More...
 

External/internal oscillator clock operations

void CLOCK_InitExtClkin (uint32_t clkInFreq)
 Init external CLK IN, select the CLKIN as the external clock source. More...
 
void CLOCK_InitSysOsc (uint32_t oscFreq)
 Init SYS OSC. More...
 
void CLOCK_InitXtalin (uint32_t xtalInFreq)
 XTALIN init function system oscillator is bypassed, sys_osc_clk is fed driectly from the XTALIN. More...
 
static void CLOCK_DeinitSysOsc (void)
 Deinit SYS OSC. More...
 
void CLOCK_InitWdtOsc (clock_wdt_analog_freq_t wdtOscFreq, uint32_t wdtOscDiv)
 Init watch dog OSC Any setting of the FREQSEL bits will yield a Fclkana value within 40% of the listed frequency value. More...
 
static void CLOCK_DeinitWdtOsc (void)
 Deinit watch dog OSC. More...
 
static void CLOCK_SetFroOscFreq (clock_fro_osc_freq_t freq)
 Set FRO oscillator output frequency. More...
 
void SDK_DelayAtLeastUs (uint32_t delay_us)
 Delay at least for several microseconds. More...
 

Data Structure Documentation

struct clock_sys_pll_t

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.
 

Macro Definition Documentation

#define FSL_CLOCK_DRIVER_VERSION   (MAKE_VERSION(2, 1, 0))
#define CLOCK_FRO_SETTING_API_ROM_ADDRESS   (0x0F0026F5U)
#define ADC_CLOCKS
Value:
{ \
kCLOCK_Adc, \
}
#define ACMP_CLOCKS
Value:
{ \
kCLOCK_Acmp, \
}
#define DAC_CLOCKS
Value:
{ \
kCLOCK_Dac0, kCLOCK_Dac1, \
}
#define SWM_CLOCKS
Value:
{ \
kCLOCK_Swm, \
}
#define ROM_CLOCKS
Value:
{ \
kCLOCK_Rom, \
}
#define SRAM_CLOCKS
Value:
{ \
kCLOCK_Ram0_1, \
}
#define IOCON_CLOCKS
Value:
{ \
kCLOCK_Iocon, \
}
#define GPIO_CLOCKS
Value:
{ \
kCLOCK_Gpio0, kCLOCK_Gpio1, \
}
#define GPIO_INT_CLOCKS
Value:
{ \
kCLOCK_GpioInt, \
}
#define DMA_CLOCKS
Value:
{ \
kCLOCK_Dma, \
}
#define CRC_CLOCKS
Value:
{ \
kCLOCK_Crc, \
}
#define WWDT_CLOCKS
Value:
{ \
kCLOCK_Wwdt, \
}
#define SCT_CLOCKS
Value:
{ \
kCLOCK_Sct, \
}
#define I2C_CLOCKS
Value:
{ \
kCLOCK_I2c0, kCLOCK_I2c1, kCLOCK_I2c2, kCLOCK_I2c3, \
}
#define USART_CLOCKS
Value:
{ \
kCLOCK_Uart0, kCLOCK_Uart1, kCLOCK_Uart2, kCLOCK_Uart3, kCLOCK_Uart4, \
}
#define SPI_CLOCKS
Value:
{ \
kCLOCK_Spi0, kCLOCK_Spi1, \
}
#define CAPT_CLOCKS
Value:
{ \
kCLOCK_Capt, \
}
#define CTIMER_CLOCKS
Value:
{ \
kCLOCK_Ctimer0, \
}
#define MTB_CLOCKS
Value:
{ \
kCLOCK_Mtb, \
}
#define MRT_CLOCKS
Value:
{ \
kCLOCK_Mrt, \
}
#define WKT_CLOCKS
Value:
{ \
kCLOCK_Wkt, \
}
#define CLK_GATE_DEFINE (   reg,
  bit 
)    ((((reg)&0xFFU) << 8U) | ((bit)&0xFFU))

Enumeration Type Documentation

Enumerator
kCLOCK_CoreSysClk 

Cpu/AHB/AHB matrix/Memories,etc.

kCLOCK_MainClk 

Main clock.

kCLOCK_Fro 

FRO18/24/30.

kCLOCK_FroDiv 

FRO div clock.

kCLOCK_ExtClk 

External Clock.

kCLOCK_PllOut 

PLL Output.

kCLOCK_WdtOsc 

Watchdog Oscillator.

kCLOCK_Frg0 

fractional rate0

kCLOCK_Frg1 

fractional rate1

Enumerator
kCLOCK_FroSrcLpwrBootValue 

fro source from the fro oscillator divided by low power boot value

kCLOCK_FroSrcFroOsc 

fre source from the fro oscillator directly

Enumerator
kCLOCK_FroOscOut18M 

FRO oscillator output 18M.

kCLOCK_FroOscOut24M 

FRO oscillator output 24M.

kCLOCK_FroOscOut30M 

FRO oscillator output 30M.

Enumerator
kCLOCK_SysPllSrcFRO 

system pll source from FRO

kCLOCK_SysPllSrcExtClk 

system pll source from external clock

kCLOCK_SysPllSrcWdtOsc 

system pll source from watchdog oscillator

kCLOCK_SysPllSrcFroDiv 

system pll source from FRO divided clock

Enumerator
kCLOCK_MainClkSrcFro 

main clock source from FRO

kCLOCK_MainClkSrcExtClk 

main clock source from Ext clock

kCLOCK_MainClkSrcWdtOsc 

main clock source from watchdog oscillator

kCLOCK_MainClkSrcFroDiv 

main clock source from FRO Div

kCLOCK_MainClkSrcSysPll 

main clock source from system pll

Function Documentation

void CLOCK_SetMainClkSrc ( clock_main_clk_src_t  src)
Parameters
src,referenceclock_main_clk_src_t to set the main clock source.
void CLOCK_SetFroOutClkSrc ( clock_fro_src_t  src)
Parameters
src,pleasereference _clock_fro_src definition.
uint32_t CLOCK_GetFRG0ClkFreq ( void  )
Returns
Frequency of FRG0 Clock.
uint32_t CLOCK_GetFRG1ClkFreq ( void  )
Returns
Frequency of FRG1 Clock.
uint32_t CLOCK_GetMainClkFreq ( void  )
Returns
Frequency of Main Clock.
uint32_t CLOCK_GetFroFreq ( void  )
Returns
Frequency of FRO.
static uint32_t CLOCK_GetCoreSysClkFreq ( void  )
inlinestatic
Returns
Frequency of core.
uint32_t CLOCK_GetClockOutClkFreq ( void  )
Returns
Frequency of ClockOut
uint32_t CLOCK_GetFreq ( clock_name_t  clockName)
Returns
Frequency of selected clock
uint32_t CLOCK_GetSystemPLLInClockRate ( void  )
Returns
System PLL input clock rate
static uint32_t CLOCK_GetSystemPLLFreq ( void  )
inlinestatic
Returns
Frequency of PLL
static uint32_t CLOCK_GetWdtOscFreq ( void  )
inlinestatic
Return values
watchdog OSC frequency value.
static uint32_t CLOCK_GetExtClkFreq ( void  )
inlinestatic
Return values
externalclock frequency value.
void CLOCK_InitSystemPll ( const clock_sys_pll_t config)
Parameters
configSystem PLL configurations.
static void CLOCK_DenitSystemPll ( void  )
inlinestatic
bool CLOCK_SetFRG0ClkFreq ( uint32_t  freq)
Parameters
freq,targetoutput frequency,freq < input and (input / freq) < 2 should be satisfy.
Return values
true- successfully, false - input argument is invalid.
bool CLOCK_SetFRG1ClkFreq ( uint32_t  freq)
Parameters
freq,targetoutput frequency,freq < input and (input / freq) < 2 should be satisfy.
Return values
true- successfully, false - input argument is invalid.
void CLOCK_InitExtClkin ( uint32_t  clkInFreq)
Parameters
clkInFreqexternal clock in frequency.
void CLOCK_InitSysOsc ( uint32_t  oscFreq)
Parameters
oscFreqoscillator frequency value.
void CLOCK_InitXtalin ( uint32_t  xtalInFreq)
Parameters
xtalInFreqXTALIN frequency value
Returns
Frequency of PLL
static void CLOCK_DeinitSysOsc ( void  )
inlinestatic
Parameters
configoscillator configuration.
void CLOCK_InitWdtOsc ( clock_wdt_analog_freq_t  wdtOscFreq,
uint32_t  wdtOscDiv 
)

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
wdtOscFreqwatch dog analog part output frequency, reference _wdt_analog_output_freq.
wdtOscDivwatch dog analog part output frequency divider, shoule be a value >= 2U and multiple of 2
static void CLOCK_DeinitWdtOsc ( void  )
inlinestatic
Parameters
configoscillator configuration.
static void CLOCK_SetFroOscFreq ( clock_fro_osc_freq_t  freq)
inlinestatic

Initialize the FRO clock to given frequency (18, 24 or 30 MHz).

Parameters
freq,pleasereference clock_fro_osc_freq_t definition, frequency must be one of 18000, 24000 or 30000 KHz.
void SDK_DelayAtLeastUs ( uint32_t  delay_us)

Please note that, this API will calculate the microsecond period with the maximum supported CPU frequency, so this API will only delay for at least the given microseconds, if precise delay count was needed, please implement a new timer count to achieve this function.

Parameters
delay_usDelay time in unit of microsecond.

Variable Documentation

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.