From 188ee59ba656d5fd47f5a13f978cd064752d3b75 Mon Sep 17 00:00:00 2001 From: Andres Vahter Date: Mon, 23 Oct 2023 22:40:24 +0300 Subject: [PATCH] stm32: fix setting uart databits --- embassy-stm32/src/usart/mod.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/embassy-stm32/src/usart/mod.rs b/embassy-stm32/src/usart/mod.rs index 09d5a59d..8c4df375 100644 --- a/embassy-stm32/src/usart/mod.rs +++ b/embassy-stm32/src/usart/mod.rs @@ -910,6 +910,11 @@ fn configure( brr + rounding } + // UART must be disabled during configuration. + r.cr1().modify(|w| { + w.set_ue(false); + }); + #[cfg(not(usart_v1))] let mut over8 = false; let mut found_brr = None; @@ -977,10 +982,9 @@ fn configure( // enable receiver w.set_re(enable_rx); // configure word size - w.set_m0(if config.parity != Parity::ParityNone { - vals::M0::BIT9 - } else { - vals::M0::BIT8 + w.set_m0(match config.data_bits { + DataBits::DataBits8 => vals::M0::BIT8, + DataBits::DataBits9 => vals::M0::BIT9, }); // configure parity w.set_pce(config.parity != Parity::ParityNone);