From b7ea90d4cbcc3c718d2bc7d68015cb220cf50897 Mon Sep 17 00:00:00 2001 From: robert-hh Date: Wed, 8 Mar 2023 20:59:24 +0100 Subject: [PATCH] rp2/machine_uart: Fix setting of UART LCR parameters. Prior to this change, setting of UART parameters like parity, stop bits or data bits did not work correctly. As suggested by @iabdalkader, adding __DSB() fixes the problem, making sure that changes to the UART LCR_H register are seen by the peripheral. Note: the FIFO is already enabled in the call to uart_init(), so the call to uart_set_fifo_enabled() is not required, but kept for visibility. Fixes issue #10976. --- ports/rp2/machine_uart.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ports/rp2/machine_uart.c b/ports/rp2/machine_uart.c index e4881cd4f1173..09870e78f0d73 100644 --- a/ports/rp2/machine_uart.c +++ b/ports/rp2/machine_uart.c @@ -336,7 +336,9 @@ STATIC void machine_uart_init_helper(machine_uart_obj_t *self, size_t n_args, co uart_init(self->uart, self->baudrate); uart_set_format(self->uart, self->bits, self->stop, self->parity); + __DSB(); // make sure UARTLCR_H register is written to uart_set_fifo_enabled(self->uart, true); + __DSB(); // make sure UARTLCR_H register is written to gpio_set_function(self->tx, GPIO_FUNC_UART); gpio_set_function(self->rx, GPIO_FUNC_UART); if (self->invert & UART_INVERT_RX) {