Line data Source code
1 : /** 2 : * @file stm32f4_uart_util.c 3 : * @brief Provides common calculations for UART channels. 4 : * 5 : * Copyright (c) 2025 Cory McKiel. 6 : * Licensed under the MIT License. See LICENSE file in the project root. 7 : */ 8 : #include "stm32f4_uart_util.h" 9 : 10 60 : uint16_t stm32f4_hal_compute_uart_bd(uint32_t periph_clk, uint32_t baud_rate) 11 : { 12 : // Common rounding trick for integers: 13 : // result = (numerator * scale + divisor/2) / divisor; 14 60 : return ((periph_clk + (baud_rate/2U)) / baud_rate); 15 : }