diff options
| author | Rasmus Melchior Jacobsen <[email protected]> | 2023-05-19 15:22:32 +0200 |
|---|---|---|
| committer | Rasmus Melchior Jacobsen <[email protected]> | 2023-05-25 17:24:22 +0200 |
| commit | cd6256a924c58ffb645b32f26d60168ca08d2d24 (patch) | |
| tree | 9c509c66d0cdc672968bbfa0fa06d17d2762b617 /embassy-stm32 | |
| parent | 06f5c309c06e61790b24a7bfddad1324741b767f (diff) | |
Add assume_noise_free to usart configuration
Effectively setting cr3.onebit
Diffstat (limited to 'embassy-stm32')
| -rw-r--r-- | embassy-stm32/src/usart/mod.rs | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/embassy-stm32/src/usart/mod.rs b/embassy-stm32/src/usart/mod.rs index 0f3e9412e..cacbced2c 100644 --- a/embassy-stm32/src/usart/mod.rs +++ b/embassy-stm32/src/usart/mod.rs | |||
| @@ -120,6 +120,11 @@ pub struct Config { | |||
| 120 | /// read will abort, the error reported and cleared | 120 | /// read will abort, the error reported and cleared |
| 121 | /// if false, the error is ignored and cleared | 121 | /// if false, the error is ignored and cleared |
| 122 | pub detect_previous_overrun: bool, | 122 | pub detect_previous_overrun: bool, |
| 123 | |||
| 124 | /// Set this to true if the line is considered noise free. | ||
| 125 | /// This will increase the receivers tolerance to clock deviations, | ||
| 126 | /// but will effectively disable noise detection. | ||
| 127 | pub assume_noise_free: bool, | ||
| 123 | } | 128 | } |
| 124 | 129 | ||
| 125 | impl Default for Config { | 130 | impl Default for Config { |
| @@ -131,6 +136,7 @@ impl Default for Config { | |||
| 131 | parity: Parity::ParityNone, | 136 | parity: Parity::ParityNone, |
| 132 | // historical behavior | 137 | // historical behavior |
| 133 | detect_previous_overrun: false, | 138 | detect_previous_overrun: false, |
| 139 | assume_noise_free: false, | ||
| 134 | } | 140 | } |
| 135 | } | 141 | } |
| 136 | } | 142 | } |
| @@ -832,7 +838,13 @@ fn configure(r: Regs, config: &Config, pclk_freq: Hertz, kind: Kind, enable_rx: | |||
| 832 | for &(presc, _presc_val) in &DIVS { | 838 | for &(presc, _presc_val) in &DIVS { |
| 833 | let denom = (config.baudrate * presc as u32) as u64; | 839 | let denom = (config.baudrate * presc as u32) as u64; |
| 834 | let div = (pclk_freq.0 as u64 * mul + (denom / 2)) / denom; | 840 | let div = (pclk_freq.0 as u64 * mul + (denom / 2)) / denom; |
| 835 | trace!("USART: presc={} div={:08x}", presc, div); | 841 | trace!( |
| 842 | "USART: presc={}, div=0x{:08x} (mantissa = {}, fraction = {})", | ||
| 843 | presc, | ||
| 844 | div, | ||
| 845 | div >> 4, | ||
| 846 | div & 0x0F | ||
| 847 | ); | ||
| 836 | 848 | ||
| 837 | if div < brr_min { | 849 | if div < brr_min { |
| 838 | #[cfg(not(usart_v1))] | 850 | #[cfg(not(usart_v1))] |
| @@ -863,6 +875,14 @@ fn configure(r: Regs, config: &Config, pclk_freq: Hertz, kind: Kind, enable_rx: | |||
| 863 | 875 | ||
| 864 | assert!(found, "USART: baudrate too low"); | 876 | assert!(found, "USART: baudrate too low"); |
| 865 | 877 | ||
| 878 | let brr = unsafe { r.brr().read().brr() as u32 }; | ||
| 879 | trace!( | ||
| 880 | "Using {}, desired baudrate: {}, actual baudrate: {}", | ||
| 881 | if over8 { "OVER8" } else { "OVER16" }, | ||
| 882 | config.baudrate, | ||
| 883 | pclk_freq.0 / brr | ||
| 884 | ); | ||
| 885 | |||
| 866 | unsafe { | 886 | unsafe { |
| 867 | r.cr2().write(|w| { | 887 | r.cr2().write(|w| { |
| 868 | w.set_stop(match config.stop_bits { | 888 | w.set_stop(match config.stop_bits { |
| @@ -895,6 +915,10 @@ fn configure(r: Regs, config: &Config, pclk_freq: Hertz, kind: Kind, enable_rx: | |||
| 895 | #[cfg(not(usart_v1))] | 915 | #[cfg(not(usart_v1))] |
| 896 | w.set_over8(vals::Over8(over8 as _)); | 916 | w.set_over8(vals::Over8(over8 as _)); |
| 897 | }); | 917 | }); |
| 918 | |||
| 919 | r.cr3().modify(|w| { | ||
| 920 | w.set_onebit(config.assume_noise_free); | ||
| 921 | }); | ||
| 898 | } | 922 | } |
| 899 | } | 923 | } |
| 900 | 924 | ||
