STM8L15x Standard Peripherals Drivers: System clock configuration functions

STM8L15x/16x Standard Peripherals Drivers

STM8L15x Standard Peripherals Drivers

System clock configuration functions

System clock configuration functions. More...

Functions

uint32_t CLK_GetClockFreq (void)
 Returns the frequencies of different the SYSCLK.
CLK_SYSCLKSource_TypeDef CLK_GetSYSCLKSource (void)
 Returns the clock source used as system clock.
void CLK_SYSCLKDivConfig (CLK_SYSCLKDiv_TypeDef CLK_SYSCLKDiv)
 Configures the System clock (SYSCLK) dividers.
void CLK_SYSCLKSourceConfig (CLK_SYSCLKSource_TypeDef CLK_SYSCLKSource)
 Configures the system clock (SYSCLK).
void CLK_SYSCLKSourceSwitchCmd (FunctionalState NewState)
 Enables or disables the clock switch execution.

Detailed Description

System clock configuration functions.

 ===============================================================================
                    System clock configuration functions
 ===============================================================================  

  This section provides functions allowing to configure the System clock.
  
  1. Several clock sources can be used to drive the System clock (SYSCLK): HSI,
     HSE, LSI and LSE.
     You can use "CLK_GetClocksFreq()" function to retrieve the frequencies of these clocks.  

@note All the peripheral clocks are derived from the System clock (SYSCLK) except:
       - BEEP: the Beeper clock can be derived either from a LSE or LSI clock sources. 
          You have to use CLK_BEEPClockConfig() function to configure this clock. 
       - RTC: the RTC clock can be derived either from the LSI, LSE, HSI or HSE clock
          divided by 1 to 64. You have to use CLK_RTCClockConfig() functions to 
          configure this clock.
       - LCD : LCD clock is the RTC Clock divided by 2. 
       - IWDG clock which is always the LSI clock.
       
  2. The maximum frequency of the SYSCLK is 16 MHz.


Function Documentation

uint32_t CLK_GetClockFreq ( void  )

Returns the frequencies of different the SYSCLK.

Note:
The system frequency computed by this function is not the real frequency in the chip. It is calculated based on the predefined constant and the selected clock source:
If SYSCLK source is HSI, function returns values based on HSI_VALUE(*)
If SYSCLK source is HSE, function returns values based on HSE_VALUE(**)
If SYSCLK source is LSE, function returns values based on LSE_VALUE(***)
If SYSCLK source is LSI, function returns values based on LSI_VALUE(****)
(*) HSI_VALUE is a constant defined in stm8l15x.h file (default value 16 MHz) but the real value may vary depending on the variations in voltage and temperature.
(**) HSE_VALUE is a constant defined in stm8l15x.h file (default value 16 MHz), user has to ensure that HSE_VALUE is same as the real frequency of the crystal used. Otherwise, this function may have wrong result.
(***) LSI_VALUE is a constant defined in stm8l15x.h file (default value 38 KHz) but the real value may vary depending on the variations in voltage and temperature.
(****) LSE_VALUE is a constant defined in stm8l15x.h file (default value 32,768 KHz), user has to ensure that LSE_VALUE is same as the real frequency of the crystal used. Otherwise, this function may have wrong result.
The result of this function could be not correct when using fractional value for HSE crystal.
Parameters:
None
Note:
This function can be used by the user application to compute the baudrate for the communication peripherals or configure other parameters.
Each time SYSCLK clock changes, this function must be called to update the returned value. Otherwise, any configuration based on this function will be incorrect.
Return values:
SystemClock frequency value

Definition at line 472 of file stm8l15x_clk.c.

References CLK, CLK_CKDIVR_CKM, CLK_SYSCLKSource_HSE, CLK_SYSCLKSource_HSI, CLK_SYSCLKSource_LSI, HSE_VALUE, HSI_VALUE, LSE_VALUE, LSI_VALUE, and SYSDivFactor.

Referenced by I2C_Init(), and USART_Init().

CLK_SYSCLKSource_TypeDef CLK_GetSYSCLKSource ( void  )

Returns the clock source used as system clock.

Parameters:
None
Return values:
Clockused as System clock (SYSCLK) source. The returned value can be one of the following:
  • CLK_SYSCLKSource_HSI: HSI used as system clock
  • CLK_SYSCLKSource_LSI: LSI used as system clock
  • CLK_SYSCLKSource_HSE: HSE used as system clock
  • CLK_SYSCLKSource_LSE: LSE used as system clock

Definition at line 429 of file stm8l15x_clk.c.

References CLK.

void CLK_SYSCLKDivConfig ( CLK_SYSCLKDiv_TypeDef  CLK_SYSCLKDiv)

Configures the System clock (SYSCLK) dividers.

Parameters:
CLK_SYSCLKDiv: Specifies the system clock divider to apply. This parameter can be one of the following values:
  • CLK_SYSCLKDiv_1
  • CLK_SYSCLKDiv_2
  • CLK_SYSCLKDiv_4
  • CLK_SYSCLKDiv_8
  • CLK_SYSCLKDiv_16
  • CLK_SYSCLKDiv_64
  • CLK_SYSCLKDiv_128
Return values:
None

Definition at line 522 of file stm8l15x_clk.c.

References CLK, and IS_CLK_SYSTEM_DIVIDER.

void CLK_SYSCLKSourceConfig ( CLK_SYSCLKSource_TypeDef  CLK_SYSCLKSource)

Configures the system clock (SYSCLK).

Note:
The HSI is used (enabled by hardware) as system clock source after startup from Reset, wake-up from Halt and active Halt modes, or in case of failure of the HSE used as system clock (if the Clock Security System CSS is enabled).
A switch from one clock source to another occurs only if the target clock source is ready (clock stable after startup delay or PLL locked). You can use CLK_GetSYSCLKSource() function to know which clock is currently used as system clock source.
Parameters:
CLK_SYSCLKSource,:specifies the clock source used as system clock. This parameter can be one of the following values:
  • CLK_SYSCLKSource_HSI: HSI selected as system clock source
  • CLK_SYSCLKSource_HSE: HSE selected as system clock source
  • CLK_SYSCLKSource_LSI: LSI selected as system clock source
  • CLK_SYSCLKSource_LSE: LSE selected as system clock source
Return values:
None

Definition at line 410 of file stm8l15x_clk.c.

References CLK, and IS_CLK_SOURCE.

void CLK_SYSCLKSourceSwitchCmd ( FunctionalState  NewState)

Enables or disables the clock switch execution.

Parameters:
NewState: new state of clock switch, value accepted ENABLE, DISABLE.
Return values:
None

Definition at line 535 of file stm8l15x_clk.c.

References CLK, CLK_SWCR_SWEN, DISABLE, and IS_FUNCTIONAL_STATE.

STM8S Firmware Library: Overview

 

 

 

For complete documentation on STM8L15x 8-bit microcontrollers platform visit www.st.com