From b1dc9aec8c0ff0dc28e70dfde3f672fc50c6bc06 Mon Sep 17 00:00:00 2001 From: Jan Niehusmann Date: Fri, 29 Oct 2021 21:02:01 +0000 Subject: [PATCH] Fix UART init code Set uartlcr_h before enabling the UART. Writing uartlcr_h while the UART is enabled is forbidden by the datasheet. Details can be found here: https://developer.arm.com/documentation/ddi0183/g/programmers-model/register-descriptions/line-control-register--uartlcr-h?lang=en (As referenced from the Datasheet) --- rp2040-hal/src/uart.rs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/rp2040-hal/src/uart.rs b/rp2040-hal/src/uart.rs index 8f57f63..6b46788 100644 --- a/rp2040-hal/src/uart.rs +++ b/rp2040-hal/src/uart.rs @@ -221,6 +221,12 @@ impl UartPeripheral { let effective_baudrate = configure_baudrate(&mut device, &config.baudrate, &frequency)?; + device.uartlcr_h.write(|w| { + w.fen().set_bit(); + set_format(w, &config.data_bits, &config.stop_bits, &config.parity); + w + }); + // Enable the UART, both TX and RX device.uartcr.write(|w| { w.uarten().set_bit(); @@ -229,13 +235,6 @@ impl UartPeripheral { w }); - device.uartlcr_h.write(|w| { - w.fen().set_bit(); - - set_format(w, &config.data_bits, &config.stop_bits, &config.parity); - w - }); - device.uartdmacr.write(|w| { w.txdmae().set_bit(); w.rxdmae().set_bit();