NavHAL 0.1.0
NAVRobotec's architecture-agnostic HAL for embedded systems.
Loading...
Searching...
No Matches
clock.c File Reference

Cortex-M4 (STM32F4) Clock HAL Implementation. More...

#include "core/cortex-m4/clock.h"
#include "core/cortex-m4/flash_reg.h"
#include "core/cortex-m4/rcc_reg.h"
#include <stdint.h>
Include dependency graph for clock.c:

Functions

void _toggle_hse_clock (uint8_t state)
 Initialize system clocks based on the provided configuration.
void _toggle_hsi_clock (uint8_t state)
void _toggle_pll_clock (uint8_t state)
void hal_clock_init (hal_clock_config_t *cfg, hal_pll_config_t *pll_cfg)
 Initialize the system clock.
uint32_t hal_clock_get_sysclk (void)
 Get the current system clock frequency in Hz.
uint32_t hal_clock_get_ahbclk (void)
 Get the current AHB clock frequency.
uint32_t hal_clock_get_apb1clk (void)
 Get the current APB1 clock frequency.
uint32_t hal_clock_get_apb2clk (void)
 Get the current APB2 clock frequency.

Detailed Description

Cortex-M4 (STM32F4) Clock HAL Implementation.

Provides functions to initialize and retrieve clock frequencies including SYSCLK, AHB, APB1, and APB2 clocks.

This implementation supports HSI, HSE, and PLL clock sources.

Author
Ashutosh Vishwakarma
Date
2025-07-21

Function Documentation

◆ _toggle_hse_clock()

void _toggle_hse_clock ( uint8_t state)

Initialize system clocks based on the provided configuration.

Enables and waits for the selected clock source (HSI, HSE, or PLL). If PLL is selected, configures PLL parameters and switches system clock source to PLL output.

Parameters
cfgPointer to clock configuration structure specifying source.
pll_cfgPointer to PLL configuration structure (used if source is PLL).

◆ _toggle_hsi_clock()

void _toggle_hsi_clock ( uint8_t state)

◆ _toggle_pll_clock()

void _toggle_pll_clock ( uint8_t state)

◆ hal_clock_get_ahbclk()

uint32_t hal_clock_get_ahbclk ( void )

Get the current AHB clock frequency.

Get the AHB bus clock frequency.

Calculated as SYSCLK divided by AHB prescaler.

Returns
AHB bus clock frequency in Hertz.

◆ hal_clock_get_apb1clk()

uint32_t hal_clock_get_apb1clk ( void )

Get the current APB1 clock frequency.

Get the APB1 bus clock frequency.

Calculated as SYSCLK divided by APB1 prescaler.

Returns
APB1 bus clock frequency in Hertz.

◆ hal_clock_get_apb2clk()

uint32_t hal_clock_get_apb2clk ( void )

Get the current APB2 clock frequency.

Get the APB2 bus clock frequency.

Calculated as SYSCLK divided by APB2 prescaler.

Returns
APB2 bus clock frequency in Hertz.

◆ hal_clock_get_sysclk()

uint32_t hal_clock_get_sysclk ( void )

Get the current system clock frequency in Hz.

Get the system clock frequency (SYSCLK).

Detects the current SYSCLK source and calculates frequency based on configured clock source and PLL parameters.

Returns
SYSCLK frequency in Hertz.

◆ hal_clock_init()

void hal_clock_init ( hal_clock_config_t * cfg,
hal_pll_config_t * pll_cfg )

Initialize the system clock.

Parameters
cfgPointer to the main clock configuration structure.
pll_cfgPointer to the PLL configuration structure.
Note
This function must be called before using other peripheral clocks.