diff options
Diffstat (limited to 'ports/stm32/uart.c')
-rw-r--r-- | ports/stm32/uart.c | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/ports/stm32/uart.c b/ports/stm32/uart.c index b14a18c6d..8091ba05f 100644 --- a/ports/stm32/uart.c +++ b/ports/stm32/uart.c @@ -603,7 +603,7 @@ void uart_attach_to_repl(pyb_uart_obj_t *self, bool attached) { self->attached_to_repl = attached; } -uint32_t uart_get_baudrate(pyb_uart_obj_t *self) { +uint32_t uart_get_source_freq(pyb_uart_obj_t *self) { uint32_t uart_clk = 0; #if defined(STM32F0) @@ -672,10 +672,20 @@ uint32_t uart_get_baudrate(pyb_uart_obj_t *self) { } #endif + return uart_clk; +} + +uint32_t uart_get_baudrate(pyb_uart_obj_t *self) { // This formula assumes UART_OVERSAMPLING_16 - uint32_t baudrate = uart_clk / self->uartx->BRR; + return uart_get_source_freq(self) / self->uartx->BRR; +} - return baudrate; +void uart_set_baudrate(pyb_uart_obj_t *self, uint32_t baudrate) { + LL_USART_SetBaudRate(self->uartx, uart_get_source_freq(self), + #if defined(STM32H7) || defined(STM32WB) + LL_USART_PRESCALER_DIV1, + #endif + LL_USART_OVERSAMPLING_16, baudrate); } mp_uint_t uart_rx_any(pyb_uart_obj_t *self) { |