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)
This commit is contained in:
Jan Niehusmann 2021-10-29 21:02:01 +00:00 committed by 9names
parent 73431a847b
commit b1dc9aec8c

View file

@ -221,6 +221,12 @@ impl<D: UartDevice> UartPeripheral<Disabled, D> {
let effective_baudrate = configure_baudrate(&mut device, &config.baudrate, &frequency)?; 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 // Enable the UART, both TX and RX
device.uartcr.write(|w| { device.uartcr.write(|w| {
w.uarten().set_bit(); w.uarten().set_bit();
@ -229,13 +235,6 @@ impl<D: UartDevice> UartPeripheral<Disabled, D> {
w 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| { device.uartdmacr.write(|w| {
w.txdmae().set_bit(); w.txdmae().set_bit();
w.rxdmae().set_bit(); w.rxdmae().set_bit();