Skip to content

Commit e7e7aec

Browse files
committed
pbio/drv/uart_stm32_ll_irq: Fix setting baud at runtime.
We change it while UART is on in the lump driver.
1 parent 763c662 commit e7e7aec

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

‎lib/pbio/drv/uart/uart_stm32_ll_irq.c‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,15 @@ void pbdrv_uart_set_baud_rate(pbdrv_uart_dev_t *uart, uint32_t baud) {
242242
}
243243
}
244244

245+
// PRESC (and BRR) must only be written while the USART is disabled, or
246+
// the hardware may silently ignore the write. This matters here because,
247+
// unlike the initial configuration in pbdrv_uart_init(), this function
248+
// can be called again later while the USART is already enabled and
249+
// actively receiving (e.g. switching baud rate mid-handshake).
250+
LL_USART_Disable(USARTx);
245251
LL_USART_SetBaudRate(USARTx, periphclk, prescaler, LL_USART_OVERSAMPLING_16, baud);
246252
LL_USART_SetPrescaler(USARTx, prescaler);
253+
LL_USART_Enable(USARTx);
247254
}
248255
#else
249256
#error "unsupported MCU for btstack_stm32_hal_set_baudrate()"

0 commit comments

Comments
 (0)