From 8e00dd00cbc42cd341eaabc6df0f0a4f815b64bb Mon Sep 17 00:00:00 2001 From: ALTracer <11005378+ALTracer@users.noreply.github.com> Date: Thu, 22 Aug 2024 07:15:39 +0300 Subject: [PATCH] stm32: usart: extend LPUART clock range --- lib/stm32/common/usart_common_all.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/stm32/common/usart_common_all.c b/lib/stm32/common/usart_common_all.c index cfbdc74ab3..40c80e505b 100644 --- a/lib/stm32/common/usart_common_all.c +++ b/lib/stm32/common/usart_common_all.c @@ -97,6 +97,9 @@ void usart_set_baudrate(uint32_t usart, uint32_t baud) /*---------------------------------------------------------------------------*/ /** @brief USART Get Baudrate. +Note: For LPUART, baudrates over 2**24 (~16.7 Mbaud) may overflow +the calculation and are therefore not supported by this function. + @param[in] usart unsigned 32 bit. USART block register address base @ref usart_reg_base @returns baud unsigned 32 bit. Baud rate specified in Hz. */ @@ -108,7 +111,8 @@ uint32_t usart_get_baudrate(uint32_t usart) #ifdef LPUART1 if (usart == LPUART1) { - return (256U * clock) / reg_brr; + return (clock / reg_brr) * 256 + + ((clock % reg_brr) * 256) / reg_brr; } #endif