Skip to content

Commit 2ac09c2

Browse files
committed
stm32/uart: Use LL_USART_GetBaudRate to compute baudrate.
This function includes the UART prescaler in the calculation (if it has one, eg on H7 and WB MCUs). Signed-off-by: Damien George <[email protected]>
1 parent 25c029c commit 2ac09c2

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

ports/stm32/uart.c

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -711,16 +711,11 @@ uint32_t uart_get_source_freq(pyb_uart_obj_t *self) {
711711
}
712712

713713
uint32_t uart_get_baudrate(pyb_uart_obj_t *self) {
714-
// This formula assumes UART_OVERSAMPLING_16
715-
uint32_t source_freq = uart_get_source_freq(self);
716-
#if defined(LPUART1)
717-
if (self->uart_id == PYB_LPUART_1) {
718-
return source_freq / (self->uartx->BRR >> 8);
719-
} else
720-
#endif
721-
{
722-
return source_freq / self->uartx->BRR;
723-
}
714+
return LL_USART_GetBaudRate(self->uartx, uart_get_source_freq(self),
715+
#if defined(STM32H7) || defined(STM32WB)
716+
self->uartx->PRESC,
717+
#endif
718+
LL_USART_OVERSAMPLING_16);
724719
}
725720

726721
void uart_set_baudrate(pyb_uart_obj_t *self, uint32_t baudrate) {

0 commit comments

Comments
 (0)