JSAPI for STM32F0xx MCU  1.10
JSAPI_CLOCK Class Reference

MCU clock system. More...

#include <jsapi.h>

Public Member Functions

_Bool SetSystemClock (unsigned hsi_mhz, _Bool hsi_div2, unsigned hse_mhz, _Bool hse_bypass, unsigned pll_mhz, unsigned flash_ws)
 Initialize the system clock. Automatically set WAIT STATE to 1 if the SYSCLK is > 24 MHz. More...
 
_Bool SetSystemClock (unsigned hsi_mhz, _Bool hsi_div2, unsigned hse_mhz, _Bool hse_bypass, unsigned pll_mhz)
 
unsigned GetSysClkFreq (void)
 Return the SYSCLK frequency. More...
 
enum CLOCK_SRC GetCurrentClockSource (void)
 Return the current clock source. More...
 
void RCC_GetClocksFreq (JSAPI_ClocksTypeDef *RCC_Clocks)
 Get the frequencies of various clocks in the system. More...
 
void GetClockFactors (int *ahbdiv, int *apbdiv, int *timmul)
 Get the divide factors for various clocks. Null pointers can be passed if they are "don't care". More...
 
int SetClockFactors (int ahbdiv, int apbdiv)
 Set the various clock dividers. More...
 
void SetMCO (enum MCO_SOURCE source, unsigned div_factor, struct JSAPI_GPIO *port, unsigned pin_no, unsigned af)
 Set the MCO source. More...
 

Detailed Description

MCU clock system.

Member Function Documentation

void JSAPI_CLOCK::GetClockFactors ( int *  ahbdiv,
int *  apbdiv,
int *  timmul 
)

Get the divide factors for various clocks. Null pointers can be passed if they are "don't care".

Parameters
ahbdivdivfactor SYSCLK -> HCLK
apbdivdivfactor HCLK -> APBCLK/PCLK
timmul1x or 2x PCLK
enum CLOCK_SRC JSAPI_CLOCK::GetCurrentClockSource ( void  )

Return the current clock source.

Returns
one of the "enum CLOCK_SRC" values.
unsigned JSAPI_CLOCK::GetSysClkFreq ( void  )

Return the SYSCLK frequency.

Returns
SYSCLK frequency.
void JSAPI_CLOCK::RCC_GetClocksFreq ( JSAPI_ClocksTypeDef RCC_Clocks)

Get the frequencies of various clocks in the system.

Parameters
[out]RCC_Clocksstructure to store the clock frequencies.
int JSAPI_CLOCK::SetClockFactors ( int  ahbdiv,
int  apbdiv 
)

Set the various clock dividers.

Parameters
ahbdivdivfactor SYSCLK -> HCLK. [1-512], must be a power of 2.
apbdivdivfactor HCLK -> APBCLK. [1-16], must be a power of 2.
void JSAPI_CLOCK::SetMCO ( enum MCO_SOURCE  source,
unsigned  div_factor,
struct JSAPI_GPIO port,
unsigned  pin_no,
unsigned  af 
)

Set the MCO source.

Parameters
sourceone of the "enum MCO_SOURCE" values.
div_factor1, 2, 4, 8, ... 128 (power of 2)
portGPIO port of the MCO
pin_nopin number of the MCO
afalternate function code to set the GPIO/pin to generate the MCO
_Bool JSAPI_CLOCK::SetSystemClock ( unsigned  hsi_mhz,
_Bool  hsi_div2,
unsigned  hse_mhz,
_Bool  hse_bypass,
unsigned  pll_mhz,
unsigned  flash_ws 
)

Initialize the system clock. Automatically set WAIT STATE to 1 if the SYSCLK is > 24 MHz.

Parameters
hsi_mhzif nonzero, then the internal 8Mhz clock is used, unless hse_mhz is nonzero.
hsi_div2divide HSI by 2 for PLL. Note: not all F0xx includes the DIV2 circuitry. For example, F030x4, F030x6, F030x8 have DIV2, but F030xC, F070x6, F070xB do NOT. please check the reference manual careful on this aspect. You MUST specify this parameter for your target correctly.
hse_mhzif nonzero, then the parameter is always used as the HSE clock, and hsi_mhz is ignored.
hse_bypassset to nonzero if hardward HSE bypass is used.
pll_mhzthe desired clock speed using the PLL. If zero, then PLL is not used. The actual achieveable PLL MHz may be less.
flash_wsflash wait state, dependent on the HCLK. If the HCLK (SYSCLK / AHB prescaler) > 24 Mhz, then it should be set to 1.

The documentation for this class was generated from the following file: