![]() |
MCUXpresso SDK API Reference Manual
Rev. 0
NXP Semiconductors
|
The MCUXpresso SDK provides APIs for MCUXpresso SDK devices' clock operation.
The clock driver supports:
Modules | |
System Clock Generator (SCG) | |
Files | |
file | fsl_clock.h |
Data Structures | |
struct | scg_sys_clk_config_t |
SCG system clock configuration. More... | |
struct | scg_sirc_config_t |
SCG slow IRC clock configuration. More... | |
struct | scg_firc_trim_config_t |
SCG fast IRC clock trim configuration. More... | |
struct | scg_firc_config_t |
SCG fast IRC clock configuration. More... | |
struct | scg_lpfll_trim_config_t |
SCG LPFLL clock trim configuration. More... | |
struct | scg_lpfll_config_t |
SCG low power FLL configuration. More... | |
struct | scg_rosc_config_t |
SCG RTC OSC configuration. More... | |
Macros | |
#define | FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL 0 |
Configure whether driver controls clock. More... | |
#define | MAX_CLOCKS |
Clock ip name array for MAX. More... | |
#define | EDMA_CLOCKS |
Clock ip name array for EDMA. More... | |
#define | FLEXBUS_CLOCKS |
Clock ip name array for FLEXBUS. More... | |
#define | FSL_CLOCK_XRDC_GATE_COUNT (5U) |
XRDC clock gate number. More... | |
#define | XRDC_CLOCKS |
Clock ip name array for XRDC. More... | |
#define | SEMA42_CLOCKS |
Clock ip name array for SEMA42. More... | |
#define | DMAMUX_CLOCKS |
Clock ip name array for DMAMUX. More... | |
#define | MU_CLOCKS |
Clock ip name array for MU. More... | |
#define | CRC_CLOCKS |
Clock ip name array for CRC. More... | |
#define | LPIT_CLOCKS |
Clock ip name array for LPIT. More... | |
#define | TPM_CLOCKS |
Clock ip name array for TPM. More... | |
#define | TRNG_CLOCKS |
Clock ip name array for TRNG. More... | |
#define | EMVSIM_CLOCKS |
Clock ip name array for SMVSIM. More... | |
#define | EWM_CLOCKS |
Clock ip name array for EWM. More... | |
#define | FLEXIO_CLOCKS |
Clock ip name array for FLEXIO. More... | |
#define | LPI2C_CLOCKS |
Clock ip name array for LPI2C0. More... | |
#define | SAI_CLOCKS |
Clock ip name array for SAI. More... | |
#define | USDHC_CLOCKS |
Clock ip name array for SDHC. More... | |
#define | LPSPI_CLOCKS |
Clock ip name array for LPSPI. More... | |
#define | LPUART_CLOCKS |
Clock ip name array for LPUART. More... | |
#define | USB_CLOCKS |
Clock ip name array for USB. More... | |
#define | PORT_CLOCKS |
Clock ip name array for PORT. More... | |
#define | LPADC_CLOCKS |
Clock ip name array for LPADC. More... | |
#define | LPDAC_CLOCKS |
Clock ip name array for DAC. More... | |
#define | INTMUX_CLOCKS |
Clock ip name array for INTMUX. More... | |
#define | EXT_CLOCKS |
Clock ip name array for EXT. More... | |
#define | VREF_CLOCKS |
Clock ip name array for VREF. More... | |
#define | FGPIO_CLOCKS |
Clock ip name array for FGPIO. More... | |
#define | MAKE_PCC_REGADDR(base, offset) ((base) + (offset)) |
Peripheral clock name difinition used for clock gate, clock source and clock divider setting. 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 bool | CLOCK_IsEnabledByOtherCore (clock_ip_name_t name) |
Check whether the clock is already enabled and configured by any other core. More... | |
static void | CLOCK_SetIpSrc (clock_ip_name_t name, clock_ip_src_t src) |
Set the clock source for specific IP module. More... | |
static void | CLOCK_SetIpSrcDiv (clock_ip_name_t name, clock_ip_src_t src, uint8_t divValue, uint8_t fracValue) |
Set the clock source and divider for specific IP module. 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_GetOsc32kClkFreq (void) |
Get the OSC 32K clock frequency (OSC32KCLK). More... | |
uint32_t | CLOCK_GetExtClkFreq (void) |
Get the external clock frequency (EXTCLK). More... | |
static uint32_t | CLOCK_GetLpoClkFreq (void) |
Get the LPO clock frequency. More... | |
uint32_t | CLOCK_GetIpFreq (clock_ip_name_t name) |
Gets the functional clock frequency for a specific IP module. More... | |
static void | CLOCK_EnableRtcOsc (bool enable) |
Enable the RTC Oscillator. More... | |
bool | CLOCK_EnableUsbfs0Clock (clock_usb_src_t src, uint32_t freq) |
Enable USB FS clock. More... | |
static void | CLOCK_DisableUsbfs0Clock (void) |
Disable USB FS clock. More... | |
uint32_t | CLOCK_GetRtcOscFreq (void) |
Gets the SCG RTC OSC clock frequency. More... | |
static bool | CLOCK_IsRtcOscErr (void) |
Checks whether the RTC OSC clock error occurs. More... | |
static void | CLOCK_ClearRtcOscErr (void) |
Clears the RTC OSC clock error. | |
static void | CLOCK_SetRtcOscMonitorMode (scg_rosc_monitor_mode_t mode) |
Sets the RTC OSC monitor mode. More... | |
static bool | CLOCK_IsRtcOscValid (void) |
Checks whether the RTC OSC clock is valid. More... | |
Variables | |
volatile uint32_t | g_xtal0Freq |
External XTAL0 (OSC0/SYSOSC) clock frequency. More... | |
volatile uint32_t | g_xtal32Freq |
External XTAL32/EXTAL32 clock frequency. More... | |
Driver version | |
#define | FSL_CLOCK_DRIVER_VERSION (MAKE_VERSION(2, 2, 1)) |
CLOCK driver version 2.2.1. More... | |
MCU System Clock. | |
uint32_t | CLOCK_GetSysClkFreq (scg_sys_clk_t type) |
Gets the SCG system clock frequency. More... | |
static void | CLOCK_SetVlprModeSysClkConfig (const scg_sys_clk_config_t *config) |
Sets the system clock configuration for VLPR mode. More... | |
static void | CLOCK_SetRunModeSysClkConfig (const scg_sys_clk_config_t *config) |
Sets the system clock configuration for RUN mode. More... | |
static void | CLOCK_SetHsrunModeSysClkConfig (const scg_sys_clk_config_t *config) |
Sets the system clock configuration for HSRUN mode. More... | |
static void | CLOCK_GetCurSysClkConfig (scg_sys_clk_config_t *config) |
Gets the system clock configuration in the current power mode. More... | |
static void | CLOCK_SetClkOutSel (clock_clkout_src_t setting) |
Sets the clock out selection. More... | |
SCG Slow IRC Clock. | |
status_t | CLOCK_InitSirc (const scg_sirc_config_t *config) |
Initializes the SCG slow IRC clock. More... | |
status_t | CLOCK_DeinitSirc (void) |
De-initializes the SCG slow IRC. More... | |
static void | CLOCK_SetSircAsyncClkDiv (scg_async_clk_t asyncClk, scg_async_clk_div_t divider) |
Set the asynchronous clock divider. More... | |
uint32_t | CLOCK_GetSircFreq (void) |
Gets the SCG SIRC clock frequency. More... | |
uint32_t | CLOCK_GetSircAsyncFreq (scg_async_clk_t type) |
Gets the SCG asynchronous clock frequency from the SIRC. More... | |
static bool | CLOCK_IsSircValid (void) |
Checks whether the SIRC clock is valid. More... | |
SCG Fast IRC Clock. | |
status_t | CLOCK_InitFirc (const scg_firc_config_t *config) |
Initializes the SCG fast IRC clock. More... | |
status_t | CLOCK_DeinitFirc (void) |
De-initializes the SCG fast IRC. More... | |
static void | CLOCK_SetFircAsyncClkDiv (scg_async_clk_t asyncClk, scg_async_clk_div_t divider) |
Set the asynchronous clock divider. More... | |
uint32_t | CLOCK_GetFircFreq (void) |
Gets the SCG FIRC clock frequency. More... | |
uint32_t | CLOCK_GetFircAsyncFreq (scg_async_clk_t type) |
Gets the SCG asynchronous clock frequency from the FIRC. More... | |
static bool | CLOCK_IsFircErr (void) |
Checks whether the FIRC clock error occurs. More... | |
static void | CLOCK_ClearFircErr (void) |
Clears the FIRC clock error. | |
static bool | CLOCK_IsFircValid (void) |
Checks whether the FIRC clock is valid. More... | |
struct scg_sys_clk_config_t |
Data Fields | |
uint32_t | divSlow: 4 |
Slow clock divider, see scg_sys_clk_div_t. More... | |
uint32_t | divBus: 4 |
Bus clock divider, see scg_sys_clk_div_t. More... | |
uint32_t | divExt: 4 |
External clock divider, see scg_sys_clk_div_t. More... | |
uint32_t | __pad0__: 4 |
Reserved. More... | |
uint32_t | divCore: 4 |
Core clock divider, see scg_sys_clk_div_t. More... | |
uint32_t | __pad1__: 4 |
Reserved. More... | |
uint32_t | src: 4 |
System clock source, see scg_sys_clk_src_t. More... | |
uint32_t | __pad2__: 4 |
reserved. More... | |
uint32_t scg_sys_clk_config_t::divSlow |
uint32_t scg_sys_clk_config_t::divBus |
uint32_t scg_sys_clk_config_t::divExt |
uint32_t scg_sys_clk_config_t::__pad0__ |
uint32_t scg_sys_clk_config_t::divCore |
uint32_t scg_sys_clk_config_t::__pad1__ |
uint32_t scg_sys_clk_config_t::src |
uint32_t scg_sys_clk_config_t::__pad2__ |
struct scg_sirc_config_t |
Data Fields | |
uint32_t | enableMode |
Enable mode, OR'ed value of _scg_sirc_enable_mode. More... | |
scg_async_clk_div_t | div1 |
SIRCDIV1 value. More... | |
scg_async_clk_div_t | div2 |
SIRCDIV2 value. More... | |
scg_async_clk_div_t | div3 |
SIRCDIV3 value. More... | |
scg_sirc_range_t | range |
Slow IRC frequency range. More... | |
uint32_t scg_sirc_config_t::enableMode |
scg_async_clk_div_t scg_sirc_config_t::div1 |
scg_async_clk_div_t scg_sirc_config_t::div2 |
scg_async_clk_div_t scg_sirc_config_t::div3 |
scg_sirc_range_t scg_sirc_config_t::range |
struct scg_firc_trim_config_t |
Data Fields | |
scg_firc_trim_mode_t | trimMode |
FIRC trim mode. More... | |
scg_firc_trim_src_t | trimSrc |
Trim source. More... | |
uint8_t | trimCoar |
Trim coarse value; Irrelevant if trimMode is kSCG_FircTrimUpdate. More... | |
uint8_t | trimFine |
Trim fine value; Irrelevant if trimMode is kSCG_FircTrimUpdate. More... | |
scg_firc_trim_mode_t scg_firc_trim_config_t::trimMode |
scg_firc_trim_src_t scg_firc_trim_config_t::trimSrc |
uint8_t scg_firc_trim_config_t::trimCoar |
uint8_t scg_firc_trim_config_t::trimFine |
struct scg_firc_config_t |
Data Fields | |
uint32_t | enableMode |
Enable mode, OR'ed value of _scg_firc_enable_mode. More... | |
scg_async_clk_div_t | div1 |
FIRCDIV1 value. More... | |
scg_async_clk_div_t | div2 |
FIRCDIV2 value. More... | |
scg_async_clk_div_t | div3 |
FIRCDIV3 value. More... | |
scg_firc_range_t | range |
Fast IRC frequency range. More... | |
const scg_firc_trim_config_t * | trimConfig |
Pointer to the FIRC trim configuration; set NULL to disable trim. More... | |
uint32_t scg_firc_config_t::enableMode |
scg_async_clk_div_t scg_firc_config_t::div1 |
scg_async_clk_div_t scg_firc_config_t::div2 |
scg_async_clk_div_t scg_firc_config_t::div3 |
scg_firc_range_t scg_firc_config_t::range |
const scg_firc_trim_config_t* scg_firc_config_t::trimConfig |
struct scg_lpfll_trim_config_t |
Data Fields | |
scg_lpfll_trim_mode_t | trimMode |
Trim mode. More... | |
scg_lpfll_lock_mode_t | lockMode |
Lock mode; Irrelevant if the trimMode is kSCG_LpFllTrimNonUpdate. More... | |
scg_lpfll_trim_src_t | trimSrc |
Trim source. More... | |
uint8_t | trimDiv |
Trim predivideds value, which can be 0 ~ 31. More... | |
uint8_t | trimValue |
Trim value; Irrelevant if trimMode is the kSCG_LpFllTrimUpdate. More... | |
scg_lpfll_trim_mode_t scg_lpfll_trim_config_t::trimMode |
scg_lpfll_lock_mode_t scg_lpfll_trim_config_t::lockMode |
scg_lpfll_trim_src_t scg_lpfll_trim_config_t::trimSrc |
uint8_t scg_lpfll_trim_config_t::trimDiv |
[ Trim source frequency / (trimDiv + 1) ] must be 2 MHz or 32768 Hz.
uint8_t scg_lpfll_trim_config_t::trimValue |
struct scg_lpfll_config_t |
Data Fields | |
uint8_t | enableMode |
Enable mode, OR'ed value of _scg_lpfll_enable_mode. | |
scg_async_clk_div_t | div1 |
LPFLLDIV1 value. More... | |
scg_async_clk_div_t | div2 |
LPFLLDIV2 value. More... | |
scg_async_clk_div_t | div3 |
LPFLLDIV3 value. More... | |
scg_lpfll_range_t | range |
LPFLL frequency range. More... | |
const scg_lpfll_trim_config_t * | trimConfig |
Trim configuration; set NULL to disable trim. More... | |
scg_async_clk_div_t scg_lpfll_config_t::div1 |
scg_async_clk_div_t scg_lpfll_config_t::div2 |
scg_async_clk_div_t scg_lpfll_config_t::div3 |
scg_lpfll_range_t scg_lpfll_config_t::range |
const scg_lpfll_trim_config_t* scg_lpfll_config_t::trimConfig |
struct scg_rosc_config_t |
Data Fields | |
scg_rosc_monitor_mode_t | monitorMode |
Clock monitor mode selected. More... | |
scg_rosc_monitor_mode_t scg_rosc_config_t::monitorMode |
#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 control the clock out of the driver.
#define FSL_CLOCK_DRIVER_VERSION (MAKE_VERSION(2, 2, 1)) |
#define MAX_CLOCKS |
#define EDMA_CLOCKS |
#define FLEXBUS_CLOCKS |
#define FSL_CLOCK_XRDC_GATE_COUNT (5U) |
#define XRDC_CLOCKS |
#define SEMA42_CLOCKS |
#define DMAMUX_CLOCKS |
#define MU_CLOCKS |
#define CRC_CLOCKS |
#define LPIT_CLOCKS |
#define TPM_CLOCKS |
#define TRNG_CLOCKS |
#define EMVSIM_CLOCKS |
#define EWM_CLOCKS |
#define FLEXIO_CLOCKS |
#define LPI2C_CLOCKS |
#define SAI_CLOCKS |
#define USDHC_CLOCKS |
#define LPSPI_CLOCKS |
#define LPUART_CLOCKS |
#define USB_CLOCKS |
#define PORT_CLOCKS |
#define LPADC_CLOCKS |
#define LPDAC_CLOCKS |
#define INTMUX_CLOCKS |
#define EXT_CLOCKS |
#define VREF_CLOCKS |
#define FGPIO_CLOCKS |
#define MAKE_PCC_REGADDR | ( | base, | |
offset | |||
) | ((base) + (offset)) |
It is defined as the corresponding register address.
enum clock_name_t |
These clocks source would be generated from SCG module.
enum clock_ip_src_t |
enum clock_usb_src_t |
enum scg_sys_clk_t |
enum scg_sys_clk_src_t |
enum scg_sys_clk_div_t |
enum clock_clkout_src_t |
enum scg_async_clk_t |
enum scg_async_clk_div_t |
enum scg_sirc_range_t |
enum scg_firc_trim_mode_t |
Enumerator | |
---|---|
kSCG_FircTrimNonUpdate |
FIRC trim enable but not enable trim value update. In this mode, the trim value is fixed to the initialized value which is defined by trimCoar and trimFine in configure structure scg_firc_trim_config_t. |
kSCG_FircTrimUpdate |
FIRC trim enable and trim value update enable. In this mode, the trim value is auto update. |
enum scg_firc_trim_div_t |
enum scg_firc_trim_src_t |
enum scg_firc_range_t |
enum scg_lpfll_range_t |
Enumerator | |
---|---|
kSCG_LpFllTrimNonUpdate |
LPFLL trim is enabled but the trim value update is not enabled. In this mode, the trim value is fixed to the initialized value, which is defined by the trimValue in the structure scg_lpfll_trim_config_t. |
kSCG_LpFllTrimUpdate |
FIRC trim is enabled and trim value update is enabled. In this mode, the trim value is automatically updated. |
enum scg_lpfll_trim_src_t |
|
inlinestatic |
name | Which clock to enable, see enumeration clock_ip_name_t. |
|
inlinestatic |
name | Which clock to disable, see enumeration clock_ip_name_t. |
|
inlinestatic |
name | Which peripheral to check, see enumeration clock_ip_name_t. |
|
inlinestatic |
Set the clock source for specific IP, not all modules need to set the clock source, should only use this function for the modules need source setting.
name | Which peripheral to check, see enumeration clock_ip_name_t. |
src | Clock source to set. |
|
inlinestatic |
Set the clock source and divider for specific IP, not all modules need to set the clock source and divider, should only use this function for the modules need source and divider setting.
Divider output clock = Divider input clock x [(fracValue+1)/(divValue+1)]).
name | Which peripheral to check, see enumeration clock_ip_name_t. |
src | Clock source to set. |
divValue | The divider value. |
fracValue | The fraction multiply 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.
clockName | Clock names defined in clock_name_t |
uint32_t CLOCK_GetCoreSysClkFreq | ( | void | ) |
uint32_t CLOCK_GetPlatClkFreq | ( | void | ) |
uint32_t CLOCK_GetBusClkFreq | ( | void | ) |
uint32_t CLOCK_GetFlashClkFreq | ( | void | ) |
uint32_t CLOCK_GetOsc32kClkFreq | ( | void | ) |
uint32_t CLOCK_GetExtClkFreq | ( | void | ) |
|
inlinestatic |
uint32_t CLOCK_GetIpFreq | ( | clock_ip_name_t | name | ) |
This function gets the IP module's functional clock frequency based on PCC registers. It is only used for the IP modules which could select clock source by PCC[PCS].
name | Which peripheral to get, see enumeration clock_ip_name_t. |
|
inlinestatic |
This function enables the Oscillator for RTC external crystal.
enable | Enable the Oscillator or not. |
bool CLOCK_EnableUsbfs0Clock | ( | clock_usb_src_t | src, |
uint32_t | freq | ||
) |
src | USB FS clock source. |
freq | The frequency specified by src. |
true | The clock is set successfully. |
false | The clock source is invalid to get proper USB FS clock. |
|
inlinestatic |
Disable USB FS clock.
uint32_t CLOCK_GetSysClkFreq | ( | scg_sys_clk_t | type | ) |
This function gets the SCG system clock frequency. These clocks are used for core, platform, external, and bus clock domains.
type | Which type of clock to get, core clock or slow clock. |
|
inlinestatic |
This function sets the system clock configuration for VLPR mode.
config | Pointer to the configuration. |
|
inlinestatic |
This function sets the system clock configuration for RUN mode.
config | Pointer to the configuration. |
|
inlinestatic |
This function sets the system clock configuration for HSRUN mode.
config | Pointer to the configuration. |
|
inlinestatic |
This function gets the system configuration in the current power mode.
config | Pointer to the configuration. |
|
inlinestatic |
This function sets the clock out selection (CLKOUTSEL).
setting | The selection to set. |
status_t CLOCK_InitSirc | ( | const scg_sirc_config_t * | config | ) |
This function enables the SCG slow IRC clock according to the configuration.
config | Pointer to the configuration structure. |
kStatus_Success | SIRC is initialized. |
kStatus_SCG_Busy | SIRC has been enabled and is used by system clock. |
kStatus_ReadOnly | SIRC control register is locked. |
status_t CLOCK_DeinitSirc | ( | void | ) |
This function disables the SCG slow IRC.
kStatus_Success | SIRC is deinitialized. |
kStatus_SCG_Busy | SIRC is used by system clock. |
kStatus_ReadOnly | SIRC control register is locked. |
|
inlinestatic |
asyncClk | Which asynchronous clock to configure. |
divider | The divider value to set. |
uint32_t CLOCK_GetSircFreq | ( | void | ) |
uint32_t CLOCK_GetSircAsyncFreq | ( | scg_async_clk_t | type | ) |
type | The asynchronous clock type. |
|
inlinestatic |
status_t CLOCK_InitFirc | ( | const scg_firc_config_t * | config | ) |
This function enables the SCG fast IRC clock according to the configuration.
config | Pointer to the configuration structure. |
kStatus_Success | FIRC is initialized. |
kStatus_SCG_Busy | FIRC has been enabled and is used by the system clock. |
kStatus_ReadOnly | FIRC control register is locked. |
status_t CLOCK_DeinitFirc | ( | void | ) |
This function disables the SCG fast IRC.
kStatus_Success | FIRC is deinitialized. |
kStatus_SCG_Busy | FIRC is used by the system clock. |
kStatus_ReadOnly | FIRC control register is locked. |
|
inlinestatic |
asyncClk | Which asynchronous clock to configure. |
divider | The divider value to set. |
uint32_t CLOCK_GetFircFreq | ( | void | ) |
uint32_t CLOCK_GetFircAsyncFreq | ( | scg_async_clk_t | type | ) |
type | The asynchronous clock type. |
|
inlinestatic |
|
inlinestatic |
uint32_t CLOCK_GetRtcOscFreq | ( | void | ) |
|
inlinestatic |
|
inlinestatic |
This function sets the RTC OSC monitor mode. The mode can be disabled. It can generate an interrupt when the error is disabled, or reset when the error is detected.
mode | Monitor mode to set. |
|
inlinestatic |
volatile uint32_t g_xtal0Freq |
The XTAL0/EXTAL0 (OSC0/SYSOSC) 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 only one core needs to set up the OSC0/SYSOSC using CLOCK_InitSysOsc. All other cores need to call the CLOCK_SetXtal0Freq to get a valid clock frequency.
volatile uint32_t g_xtal32Freq |
The XTAL32/EXTAL32 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.