Core
Loading...
Searching...
No Matches
clock.h File Reference

Core clock library. More...

#include "stm32g4xx_hal.h"
#include <stdbool.h>
#include <stdint.h>

Go to the source code of this file.

Functions

void core_clock_ADC12_init ()
 Set the clocks for ADC1 and ADC2 to SYSCLK and enable them.
 
void core_clock_ADC345_init ()
 Set the clocks for ADC3, ADC4, and ADC5 to SYSCLK and enable them.
 
void core_clock_FDCAN_init (FDCAN_GlobalTypeDef *can)
 Set FDCAN clock to PCLK1 and enable it.
 
bool core_clock_USART_init (USART_TypeDef *usart)
 Set a USART clock to PCLK1 and enable it.
 
bool core_clock_timer_init (TIM_TypeDef *timer)
 Enable a timer clock.
 
bool core_clock_I2C_init (I2C_TypeDef *i2c)
 Set an I2C clock to PCLK1 and enable it.
 
bool core_clock_RTC_init ()
 Enable the external 32.768kHz oscillator and set the RTC clock to it.
 
void core_clock_port_init (GPIO_TypeDef *port)
 Initializes port clock for selected port.
 
uint8_t core_clock_generate_params (uint32_t src_freq, uint32_t target_freq, uint8_t *n, uint8_t *m, uint8_t *r)
 Generate the settings for the N, M, and R dividers from the clock source frequency and the desired output frequency.
 
bool core_clock_init ()
 Initialize the STM32G4's core clocks.
 

Detailed Description

Core clock library.

This core library component is used to initialize peripheral clocks. Generally, it is only necessary to call core_clock_init() from user code. Other clock initialization functions are called by the respective core module init function.

Function Documentation

◆ core_clock_FDCAN_init()

void core_clock_FDCAN_init ( FDCAN_GlobalTypeDef * can)

Set FDCAN clock to PCLK1 and enable it.

Initialize GPIO port clocks corresponding to CAN bus selected

Parameters
canFDCAN module to initialize

◆ core_clock_generate_params()

uint8_t core_clock_generate_params ( uint32_t src_freq,
uint32_t target_freq,
uint8_t * n,
uint8_t * m,
uint8_t * r )

Generate the settings for the N, M, and R dividers from the clock source frequency and the desired output frequency.

Parameters
src_freqFrequency of the clock source of the PLL, in kilohertz
target_freqDesired frequency of the R output of the PLL, in kilohertz
nLocation where the setting of the N divider is stored
mLocation where the setting of the M divider is stored
rLocation where the setting of the R divider is stored
Note
The algorithm used here will try to maximize the frequency of the VCO output. Thus, in certain cases, the algorithm will not find an exact setting, even if one exists.
Return values
0if the desired setting is outside of the frequency range of the VCO
1otherwise

◆ core_clock_I2C_init()

bool core_clock_I2C_init ( I2C_TypeDef * i2c)

Set an I2C clock to PCLK1 and enable it.

Parameters
i2cI2C module to initialize
Return values
1if i2c_num is a valid I2C module
0otherwise

◆ core_clock_init()

bool core_clock_init ( )

Initialize the STM32G4's core clocks.

The SYSCLK frequency will be set to CORE_CLOCK_SYSCLK_FREQ, which is given in kilohertz and defined in core_config.h. This function is generally called immediately after HAL_Init() in the user code.

Return values
1on success
0otherwise

◆ core_clock_port_init()

void core_clock_port_init ( GPIO_TypeDef * port)

Initializes port clock for selected port.

Parameters
portPort to initialize clock for

◆ core_clock_RTC_init()

bool core_clock_RTC_init ( )

Enable the external 32.768kHz oscillator and set the RTC clock to it.

Return values
1

◆ core_clock_timer_init()

bool core_clock_timer_init ( TIM_TypeDef * timer)

Enable a timer clock.

Parameters
timerTimer to initialize (TIM2 through TIM7)
Return values
1if timer is a supported timer module
0otherwise

◆ core_clock_USART_init()

bool core_clock_USART_init ( USART_TypeDef * usart)

Set a USART clock to PCLK1 and enable it.

Parameters
usartUSART module to initialize
Return values
1if usart_num is a valid USART module
0otherwise