hal
Hardware Abstraction Layer
stm32f4_uart_util.c File Reference

Provides common calculations for UART channels. More...

Include dependency graph for stm32f4_uart_util.c:

Functions

uint16_t stm32f4_hal_compute_uart_bd (uint32_t periph_clk, uint32_t baud_rate)
 Calculate the 16 bit register value for a desired baud rate. More...
 

Detailed Description

Provides common calculations for UART channels.

Copyright (c) 2025 Cory McKiel. Licensed under the MIT License. See LICENSE file in the project root.

Function Documentation

◆ stm32f4_hal_compute_uart_bd()

uint16_t stm32f4_hal_compute_uart_bd ( uint32_t  periph_clk,
uint32_t  baud_rate 
)

Calculate the 16 bit register value for a desired baud rate.

The UART channels each have a baud rate register that determines the rate. (USARTX->BRR). This function calculates the correct value given the clock to the peripheral and the desired baud rate.

Parameters
periph_clkThe frequency the peripheral is clocked at in Hz.
baud_rateThe desired baud rate. Some common values: 9600, 19200, 38400, 57600, 115200.
Returns
The value to place directly into the Baud Rate Register (BRR).