CMU - Clock Management Unit

Description

Clock management unit (CMU) Peripheral API.

This module contains functions for the CMU peripheral of Silicon Labs 32-bit MCUs and SoCs. The CMU module controls oscillators, clocks gates, clock multiplexers, pre-scalers, calibration modules and wait-states.

Data Structures

struct CMU_LFXOInit_TypeDef
LFXO initialization structure.
struct CMU_HFXOInit_TypeDef
HFXO initialization structure.

Functions

void CMU_UpdateWaitStates (uint32_t freq, int vscale)
Configure various wait states to switch to a certain frequency and a certain voltage scale.
void syncReg (uint32_t mask)
Wait for an ongoing sync of register(s) to low-frequency domain to complete.
CMU_AUXHFRCOBand_TypeDef CMU_AUXHFRCOBandGet (void)
Get the AUXHFRCO band in use.
void CMU_AUXHFRCOBandSet ( CMU_AUXHFRCOBand_TypeDef band)
Set the AUXHFRCO band and the tuning value based on the value in the calibration table made during production.
uint32_t CMU_Calibrate (uint32_t HFCycles, CMU_Osc_TypeDef reference)
Calibrate the clock.
void CMU_CalibrateConfig (uint32_t downCycles, CMU_Osc_TypeDef downSel, CMU_Osc_TypeDef upSel)
Configure the clock calibration.
uint32_t CMU_CalibrateCountGet (void)
Get the calibration count register.
CMU_ClkDiv_TypeDef CMU_ClockDivGet ( CMU_Clock_TypeDef clock)
Get the clock divisor/prescaler.
void CMU_ClockDivSet ( CMU_Clock_TypeDef clock, CMU_ClkDiv_TypeDef div)
Set the clock divisor/prescaler.
void CMU_ClockEnable ( CMU_Clock_TypeDef clock, bool enable)
Enable/disable a clock.
uint32_t CMU_ClockFreqGet ( CMU_Clock_TypeDef clock)
Get the clock frequency for a clock point.
CMU_Select_TypeDef CMU_ClockSelectGet ( CMU_Clock_TypeDef clock)
Get the currently selected reference clock used for a clock branch.
void CMU_ClockSelectSet ( CMU_Clock_TypeDef clock, CMU_Select_TypeDef ref)
Select the reference clock/oscillator used for a clock branch.
uint16_t CMU_LF_ClockPrecisionGet ( CMU_Clock_TypeDef clock)
Gets the precision (in PPM) of the specified low frequency clock branch.
void CMU_FreezeEnable (bool enable)
CMU low frequency register synchronization freeze control.
CMU_HFRCOBand_TypeDef CMU_HFRCOBandGet (void)
Get HFRCO band in use.
void CMU_HFRCOBandSet ( CMU_HFRCOBand_TypeDef band)
Set HFRCO band and the tuning value based on the value in the calibration table made during production.
uint32_t CMU_HFRCOStartupDelayGet (void)
Get the HFRCO startup delay.
void CMU_HFRCOStartupDelaySet (uint32_t delay)
Set the HFRCO startup delay.
void CMU_HFXOInit (const CMU_HFXOInit_TypeDef *hfxoInit)
Set HFXO control registers.
uint32_t CMU_LCDClkFDIVGet (void)
Get the LCD framerate divisor (FDIV) setting.
void CMU_LCDClkFDIVSet (uint32_t div)
Set the LCD framerate divisor (FDIV) setting.
void CMU_LFXOInit (const CMU_LFXOInit_TypeDef *lfxoInit)
Set LFXO control registers.
void CMU_LFXOPrecisionSet (uint16_t precision)
Sets LFXO's crystal precision, in PPM.
void CMU_OscillatorEnable ( CMU_Osc_TypeDef osc, bool enable, bool wait)
Enable/disable oscillator.
uint32_t CMU_OscillatorTuningGet ( CMU_Osc_TypeDef osc)
Get the oscillator frequency tuning setting.
void CMU_OscillatorTuningSet ( CMU_Osc_TypeDef osc, uint32_t val)
Set the oscillator frequency tuning control.
bool CMU_PCNTClockExternalGet (unsigned int instance)
Determine if the currently selected PCNTn clock used is external or LFBCLK.
void CMU_PCNTClockExternalSet (unsigned int instance, bool external)
Select the PCNTn clock.
void CMU_CalibrateCont (bool enable)
Configure continuous calibration mode.
void CMU_CalibrateStart (void)
Start calibration.
void CMU_CalibrateStop (void)
Stop the calibration counters.
uint32_t CMU_DivToLog2 ( CMU_ClkDiv_TypeDef div)
Convert dividend to logarithmic value.
void CMU_IntClear (uint32_t flags)
Clear one or more pending CMU interrupts.
void CMU_IntDisable (uint32_t flags)
Disable one or more CMU interrupts.
void CMU_IntEnable (uint32_t flags)
Enable one or more CMU interrupts.
uint32_t CMU_IntGet (void)
Get pending CMU interrupts.
uint32_t CMU_IntGetEnabled (void)
Get enabled and pending CMU interrupt flags.
void CMU_IntSet (uint32_t flags)
Set one or more pending CMU interrupts.
void CMU_Lock (void)
Lock the CMU to protect some of its registers against unintended modification.
uint32_t CMU_Log2ToDiv (uint32_t log2)
Convert logarithm of 2 prescaler to division factor.
void CMU_Unlock (void)
Unlock the CMU so that writing to locked registers again is possible.

Macros

#define cmuClkDiv_1 1
Clock divisors.
#define cmuClkDiv_2 2
Divide clock by 2.
#define cmuClkDiv_4 4
Divide clock by 4.
#define cmuClkDiv_8 8
Divide clock by 8.
#define cmuClkDiv_16 16
Divide clock by 16.
#define cmuClkDiv_32 32
Divide clock by 32.
#define cmuClkDiv_64 64
Divide clock by 64.
#define cmuClkDiv_128 128
Divide clock by 128.
#define cmuClkDiv_256 256
Divide clock by 256.
#define cmuClkDiv_512 512
Divide clock by 512.
#define cmuClkDiv_1024 1024
Divide clock by 1024.
#define cmuClkDiv_2048 2048
Divide clock by 2048.
#define cmuClkDiv_4096 4096
Divide clock by 4096.
#define cmuClkDiv_8192 8192
Divide clock by 8192.
#define cmuClkDiv_16384 16384
Divide clock by 16384.
#define cmuClkDiv_32768 32768
Divide clock by 32768.
#define CMU_LFXOINIT_DEFAULT
Default LFXO initialization values.
#define CMU_LFXOINIT_EXTERNAL_CLOCK
Default LFXO initialization for external clock.
#define CMU_HFXOINIT_DEFAULT
Default HFXO initialization values for Platform 1 devices.
#define CMU_HFXOINIT_EXTERNAL_CLOCK
Default HFXO initialization for external clock.

Typedefs

typedef uint32_t CMU_ClkDiv_TypeDef
Clock divider configuration.

Enumerations

enum CMU_HFRCOBand_TypeDef {
cmuHFRCOBand_1MHz = _CMU_HFRCOCTRL_BAND_1MHZ,
cmuHFRCOBand_7MHz = _CMU_HFRCOCTRL_BAND_7MHZ,
cmuHFRCOBand_11MHz = _CMU_HFRCOCTRL_BAND_11MHZ,
cmuHFRCOBand_14MHz = _CMU_HFRCOCTRL_BAND_14MHZ,
cmuHFRCOBand_21MHz = _CMU_HFRCOCTRL_BAND_21MHZ,
cmuHFRCOBand_28MHz = _CMU_HFRCOCTRL_BAND_28MHZ
}
High-frequency system RCO bands.
enum CMU_AUXHFRCOBand_TypeDef {
cmuAUXHFRCOBand_1MHz = _CMU_AUXHFRCOCTRL_BAND_1MHZ,
cmuAUXHFRCOBand_7MHz = _CMU_AUXHFRCOCTRL_BAND_7MHZ,
cmuAUXHFRCOBand_11MHz = _CMU_AUXHFRCOCTRL_BAND_11MHZ,
cmuAUXHFRCOBand_14MHz = _CMU_AUXHFRCOCTRL_BAND_14MHZ,
cmuAUXHFRCOBand_21MHz = _CMU_AUXHFRCOCTRL_BAND_21MHZ,
cmuAUXHFRCOBand_28MHz = _CMU_AUXHFRCOCTRL_BAND_28MHZ
}
AUX high-frequency RCO bands.
enum CMU_Clock_TypeDef {
cmuClock_HF ,
cmuClock_DBG ,
cmuClock_AUX ,
cmuClock_HFPER ,
cmuClock_USART0 ,
cmuClock_USART1 ,
cmuClock_USART2 ,
cmuClock_UART0 ,
cmuClock_UART1 ,
cmuClock_TIMER0 ,
cmuClock_TIMER1 ,
cmuClock_TIMER2 ,
cmuClock_TIMER3 ,
cmuClock_ACMP0 ,
cmuClock_ACMP1 ,
cmuClock_PRS ,
cmuClock_DAC0 ,
cmuClock_GPIO ,
cmuClock_VCMP ,
cmuClock_ADC0 ,
cmuClock_I2C0 ,
cmuClock_I2C1 ,
cmuClock_CORE ,
cmuClock_AES ,
cmuClock_DMA ,
cmuClock_HFLE ,
cmuClock_EBI ,
cmuClock_USB ,
cmuClock_LFA ,
cmuClock_RTC ,
cmuClock_LETIMER0 ,
cmuClock_LCDpre ,
cmuClock_LCD ,
cmuClock_PCNT0 ,
cmuClock_PCNT1 ,
cmuClock_PCNT2 ,
cmuClock_LESENSE ,
cmuClock_LFB ,
cmuClock_LEUART0 ,
cmuClock_LEUART1
}
Clock points in CMU.
enum CMU_Osc_TypeDef {
cmuOsc_LFXO ,
cmuOsc_LFRCO ,
cmuOsc_HFXO ,
cmuOsc_HFRCO ,
cmuOsc_AUXHFRCO ,
cmuOsc_ULFRCO
}
Oscillator types.
enum CMU_OscMode_TypeDef {
cmuOscMode_Crystal ,
cmuOscMode_AcCoupled ,
cmuOscMode_External
}
Oscillator modes.
enum CMU_Select_TypeDef {
cmuSelect_Error ,
cmuSelect_Disabled ,
cmuSelect_LFXO ,
cmuSelect_LFRCO ,
cmuSelect_HFXO ,
cmuSelect_HFRCO ,
cmuSelect_HFCLKLE ,
cmuSelect_AUXHFRCO ,
cmuSelect_HFSRCCLK ,
cmuSelect_HFCLK ,
cmuSelect_ULFRCO
}
Selectable clock sources.
enum CMU_LFXOBoost_TypeDef {
cmuLfxoBoost70 = 0x0,
cmuLfxoBoost100 = 0x2
}
LFXO Boost values.

Function Documentation

CMU_UpdateWaitStates()

void CMU_UpdateWaitStates ( uint32_t freq,
int vscale
)

Configure various wait states to switch to a certain frequency and a certain voltage scale.

This function will set up the necessary flash, bus, and RAM wait states. Updating the wait state configuration must be done before increasing the clock frequency and it must be done after decreasing the clock frequency. Updating the wait state configuration must be done before core voltage is decreased and it must be done after a core voltage is increased.

Parameters
[in] freq The core clock frequency to configure wait-states.
[in] vscale The voltage scale to configure wait-states. Expected values are 0 or 2, higher number is lower voltage.
  • 0 = 1.2 V (VSCALE2)
  • 2 = 1.0 V (VSCALE0)

syncReg()

void syncReg ( uint32_t mask )
inline

Wait for an ongoing sync of register(s) to low-frequency domain to complete.

Parameters
[in] mask A bitmask corresponding to SYNCBUSY register defined bits, indicating registers that must complete any ongoing synchronization.

CMU_AUXHFRCOBandGet()

CMU_AUXHFRCOBand_TypeDef CMU_AUXHFRCOBandGet ( void )

Get the AUXHFRCO band in use.

Returns
AUXHFRCO band in use.

CMU_AUXHFRCOBandSet()

void CMU_AUXHFRCOBandSet ( CMU_AUXHFRCOBand_TypeDef band )

Set the AUXHFRCO band and the tuning value based on the value in the calibration table made during production.

Parameters
[in] band AUXHFRCO band to activate.

CMU_Calibrate()

uint32_t CMU_Calibrate ( uint32_t HFCycles,
CMU_Osc_TypeDef reference
)

Calibrate the clock.

Run a calibration for HFCLK against a selectable reference clock. See the reference manual, CMU chapter, for more details.

Note
This function will not return until the calibration measurement is completed.
Parameters
[in] HFCycles The number of HFCLK cycles to run the calibration. Increasing this number increases precision but the calibration will take more time.
[in] reference The reference clock used to compare HFCLK.
Returns
The number of ticks the reference clock after HFCycles ticks on the HF clock.

CMU_CalibrateConfig()

void CMU_CalibrateConfig ( uint32_t downCycles,
CMU_Osc_TypeDef downSel,
CMU_Osc_TypeDef upSel
)

Configure the clock calibration.

Configure a calibration for a selectable clock source against another selectable reference clock. See the reference manual, CMU chapter, for more details.

Note
After configuration, a call to CMU_CalibrateStart() is required and the resulting calibration value can be read out with the CMU_CalibrateCountGet() function call.
Parameters
[in] downCycles The number of downSel clock cycles to run the calibration. Increasing this number increases precision but the calibration will take more time.
[in] downSel The clock, which will be counted down downCycles.
[in] upSel The reference clock; the number of cycles generated by this clock will be counted and added up and the result can be given with the CMU_CalibrateCountGet() function call.

CMU_CalibrateCountGet()

uint32_t CMU_CalibrateCountGet ( void )

Get the calibration count register.

Note
If continuous calibration mode is active, calibration busy will almost always be off and only the value needs to be read. In a normal case, this function call is triggered by the CALRDY interrupt flag.
Returns
The calibration count, the number of UPSEL clocks in the period of DOWNSEL oscillator clock cycles configured by a previous write operation to CMU->CALCNT.

CMU_ClockDivGet()

Get the clock divisor/prescaler.

Parameters
[in] clock A clock point to get the divisor/prescaler for. Notice that not all clock points have a divisor/prescaler. See the CMU overview in the reference manual.
Returns
The current clock point divisor/prescaler. 1 is returned if clock specifies a clock point without a divisor/prescaler.

CMU_ClockDivSet()

void CMU_ClockDivSet ( CMU_Clock_TypeDef clock,
CMU_ClkDiv_TypeDef div
)

Set the clock divisor/prescaler.

Note
If setting an LF clock prescaler, synchronization into the low-frequency domain is required. If the same register is modified before a previous update has completed, this function will stall until the previous synchronization has completed. See CMU_FreezeEnable() for a suggestion on how to reduce the stalling time in some use cases.

HFCLKLE prescaler is automatically modified when peripherals with clock domain HFBUSCLK is chosen based on the maximum HFLE frequency allowed.

Parameters
[in] clock Clock point to set divisor/prescaler for. Notice that not all clock points have a divisor/prescaler. See the CMU overview in the reference manual.
[in] div The clock divisor to use (<= cmuClkDiv_512).

CMU_ClockEnable()

void CMU_ClockEnable ( CMU_Clock_TypeDef clock,
bool enable
)

Enable/disable a clock.

In general, module clocking is disabled after a reset. If a module clock is disabled, the registers of that module are not accessible and reading from such registers may return undefined values. Writing to registers of clock-disabled modules has no effect. Avoid accessing module registers of a module with a disabled clock.

Note
If enabling/disabling an LF clock, synchronization into the low-frequency domain is required. If the same register is modified before a previous update has completed, this function will stall until the previous synchronization has completed. See CMU_FreezeEnable() for a suggestion on how to reduce the stalling time in some use c