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 hal_clock_init (hal_clock_config_t *cfg, hal_pll_config_t *pll_cfg)
 Initialize system clock and bus prescalers.
uint32_t hal_clock_get_sysclk (void)
 Get current system clock (SYSCLK) frequency.
uint32_t hal_clock_get_ahbclk (void)
 Get current AHB bus frequency.
uint32_t hal_clock_get_apb1clk (void)
 Get current APB1 bus frequency.
uint32_t hal_clock_get_apb2clk (void)
 Get current APB2 bus frequency.

Detailed Description

Cortex-M4 (STM32F4) Clock HAL Implementation.

This file provides a hardware abstraction layer for clock configuration on STM32F4 microcontrollers. It includes functions to:

  • Initialize system clock sources (HSI, HSE, PLL)
  • Configure PLL parameters (M, N, P, Q factors)
  • Set AHB/APB bus prescalers
  • Manage flash wait states
  • Retrieve current clock frequencies for all system buses
Note
The implementation assumes an STM32F4xx microcontroller and uses direct register access for maximum performance and minimal overhead.

Function Documentation

◆ hal_clock_get_ahbclk()

uint32_t hal_clock_get_ahbclk ( void )

Get current AHB bus frequency.

Get the AHB bus clock frequency.

Returns
AHB clock frequency in Hz

◆ hal_clock_get_apb1clk()

uint32_t hal_clock_get_apb1clk ( void )

Get current APB1 bus frequency.

Get the APB1 bus clock frequency.

Returns
APB1 clock frequency in Hz

◆ hal_clock_get_apb2clk()

uint32_t hal_clock_get_apb2clk ( void )

Get current APB2 bus frequency.

Get the APB2 bus clock frequency.

Returns
APB2 clock frequency in Hz

◆ hal_clock_get_sysclk()

uint32_t hal_clock_get_sysclk ( void )

Get current system clock (SYSCLK) frequency.

Get the system clock frequency (SYSCLK).

Returns
SYSCLK frequency in Hz

Determines SYSCLK frequency based on current clock source:

  • HSI: Fixed 16 MHz
  • HSE: Fixed 8 MHz
  • PLL: Calculated from PLL configuration registers

◆ hal_clock_init()

void hal_clock_init ( hal_clock_config_t * cfg,
hal_pll_config_t * pll_cfg )

Initialize system clock and bus prescalers.

Initialize the system clock.

Parameters
[in]cfgPointer to clock configuration structure
[in]pll_cfgPointer to PLL configuration structure (required if using PLL)

Configures the complete clock tree including:

  • Clock source selection (HSI/HSE/PLL)
  • PLL configuration (when used)
  • Flash latency settings
  • AHB/APB prescalers
Note
This function will block until clock switches are complete

< Flash Interface base address

< Flash ACR Latency bit position

< Flash ACR Latency bit position