diff options
| author | Andres Vahter <[email protected]> | 2023-10-24 15:57:03 +0300 |
|---|---|---|
| committer | Andres Vahter <[email protected]> | 2023-10-24 15:57:03 +0300 |
| commit | bda99e59ec0f2d31e4f29b8d03fbd44d8e917fdd (patch) | |
| tree | ab1f60803e7c6c8e3fcecae7ef755ceef7dac5a4 | |
| parent | 25c2a9baaa863a42780e70791d6ab9df89f2dd3b (diff) | |
stm32: fix uart parity, add comment why it is so
| -rw-r--r-- | embassy-stm32/src/usart/mod.rs | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/embassy-stm32/src/usart/mod.rs b/embassy-stm32/src/usart/mod.rs index 60b504da1..ea127e7f7 100644 --- a/embassy-stm32/src/usart/mod.rs +++ b/embassy-stm32/src/usart/mod.rs | |||
| @@ -974,6 +974,12 @@ fn configure( | |||
| 974 | #[cfg(any(usart_v3, usart_v4))] | 974 | #[cfg(any(usart_v3, usart_v4))] |
| 975 | w.set_swap(config.swap_rx_tx); | 975 | w.set_swap(config.swap_rx_tx); |
| 976 | }); | 976 | }); |
| 977 | |||
| 978 | #[cfg(not(usart_v1))] | ||
| 979 | r.cr3().modify(|w| { | ||
| 980 | w.set_onebit(config.assume_noise_free); | ||
| 981 | }); | ||
| 982 | |||
| 977 | r.cr1().write(|w| { | 983 | r.cr1().write(|w| { |
| 978 | // enable uart | 984 | // enable uart |
| 979 | w.set_ue(true); | 985 | w.set_ue(true); |
| @@ -982,9 +988,11 @@ fn configure( | |||
| 982 | // enable receiver | 988 | // enable receiver |
| 983 | w.set_re(enable_rx); | 989 | w.set_re(enable_rx); |
| 984 | // configure word size | 990 | // configure word size |
| 985 | w.set_m0(match config.data_bits { | 991 | // if using odd or even parity it must be configured to 9bits |
| 986 | DataBits::DataBits8 => vals::M0::BIT8, | 992 | w.set_m0(if config.parity != Parity::ParityNone { |
| 987 | DataBits::DataBits9 => vals::M0::BIT9, | 993 | vals::M0::BIT9 |
| 994 | } else { | ||
| 995 | vals::M0::BIT8 | ||
| 988 | }); | 996 | }); |
| 989 | // configure parity | 997 | // configure parity |
| 990 | w.set_pce(config.parity != Parity::ParityNone); | 998 | w.set_pce(config.parity != Parity::ParityNone); |
| @@ -999,11 +1007,6 @@ fn configure( | |||
| 999 | w.set_fifoen(true); | 1007 | w.set_fifoen(true); |
| 1000 | }); | 1008 | }); |
| 1001 | 1009 | ||
| 1002 | #[cfg(not(usart_v1))] | ||
| 1003 | r.cr3().modify(|w| { | ||
| 1004 | w.set_onebit(config.assume_noise_free); | ||
| 1005 | }); | ||
| 1006 | |||
| 1007 | Ok(()) | 1010 | Ok(()) |
| 1008 | } | 1011 | } |
| 1009 | 1012 | ||
