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 <damien@micropython.org>
This commit is contained in:
Damien George 2021-04-13 23:56:37 +10:00
parent 25c029ce9f
commit 2ac09c2694

View File

@ -711,16 +711,11 @@ uint32_t uart_get_source_freq(pyb_uart_obj_t *self) {
} }
uint32_t uart_get_baudrate(pyb_uart_obj_t *self) { uint32_t uart_get_baudrate(pyb_uart_obj_t *self) {
// This formula assumes UART_OVERSAMPLING_16 return LL_USART_GetBaudRate(self->uartx, uart_get_source_freq(self),
uint32_t source_freq = uart_get_source_freq(self); #if defined(STM32H7) || defined(STM32WB)
#if defined(LPUART1) self->uartx->PRESC,
if (self->uart_id == PYB_LPUART_1) { #endif
return source_freq / (self->uartx->BRR >> 8); LL_USART_OVERSAMPLING_16);
} else
#endif
{
return source_freq / self->uartx->BRR;
}
} }
void uart_set_baudrate(pyb_uart_obj_t *self, uint32_t baudrate) { void uart_set_baudrate(pyb_uart_obj_t *self, uint32_t baudrate) {