diff options
author | Damien George <damien@micropython.org> | 2021-04-13 23:56:37 +1000 |
---|---|---|
committer | Damien George <damien@micropython.org> | 2021-04-13 23:59:01 +1000 |
commit | 2ac09c2694f89b11544f4abf10413c64eeec2b15 (patch) | |
tree | 06abe01ceee796faee14c5f6681c389f11f67421 | |
parent | 25c029ce9fb0c2c313bfbf933e17648c98a33afc (diff) | |
download | micropython-2ac09c2694f89b11544f4abf10413c64eeec2b15.tar.gz micropython-2ac09c2694f89b11544f4abf10413c64eeec2b15.zip |
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>
-rw-r--r-- | ports/stm32/uart.c | 15 |
1 files changed, 5 insertions, 10 deletions
diff --git a/ports/stm32/uart.c b/ports/stm32/uart.c index d40a883c52..36c59cee4a 100644 --- a/ports/stm32/uart.c +++ b/ports/stm32/uart.c @@ -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) { - // This formula assumes UART_OVERSAMPLING_16 - uint32_t source_freq = uart_get_source_freq(self); - #if defined(LPUART1) - if (self->uart_id == PYB_LPUART_1) { - return source_freq / (self->uartx->BRR >> 8); - } else - #endif - { - return source_freq / self->uartx->BRR; - } + return LL_USART_GetBaudRate(self->uartx, uart_get_source_freq(self), + #if defined(STM32H7) || defined(STM32WB) + self->uartx->PRESC, + #endif + LL_USART_OVERSAMPLING_16); } void uart_set_baudrate(pyb_uart_obj_t *self, uint32_t baudrate) { |