aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2023-09-26 00:14:52 +0200
committerDario Nieuwenhuis <[email protected]>2023-09-26 00:19:27 +0200
commit5d8817d1095589e1916a92adc9db3feb1a3b91b5 (patch)
tree8a797018cd769884a165d7d80fea8582d682fa3f
parentc79a84a98a92bb3f1280b4a7657936fcd827a0e0 (diff)
stm32/usart: return error instead of panicking on bad baudrate.
-rw-r--r--embassy-stm32/src/usart/buffered.rs26
-rw-r--r--embassy-stm32/src/usart/mod.rs87
-rw-r--r--embassy-stm32/src/usart/ringbuffered.rs6
-rw-r--r--examples/stm32f3/src/bin/usart_dma.rs2
-rw-r--r--examples/stm32f4/src/bin/usart.rs2
-rw-r--r--examples/stm32f4/src/bin/usart_buffered.rs2
-rw-r--r--examples/stm32f4/src/bin/usart_dma.rs2
-rw-r--r--examples/stm32f7/src/bin/usart_dma.rs2
-rw-r--r--examples/stm32h5/src/bin/usart.rs2
-rw-r--r--examples/stm32h5/src/bin/usart_dma.rs2
-rw-r--r--examples/stm32h5/src/bin/usart_split.rs2
-rw-r--r--examples/stm32h7/src/bin/usart.rs2
-rw-r--r--examples/stm32h7/src/bin/usart_dma.rs2
-rw-r--r--examples/stm32h7/src/bin/usart_split.rs2
-rw-r--r--examples/stm32l0/src/bin/usart_dma.rs2
-rw-r--r--examples/stm32l0/src/bin/usart_irq.rs8
-rw-r--r--examples/stm32l4/src/bin/usart.rs2
-rw-r--r--examples/stm32l4/src/bin/usart_dma.rs2
-rw-r--r--examples/stm32wl/src/bin/uart_async.rs4
-rw-r--r--tests/stm32/src/bin/usart.rs6
-rw-r--r--tests/stm32/src/bin/usart_dma.rs2
-rw-r--r--tests/stm32/src/bin/usart_rx_ringbuffered.rs2
22 files changed, 94 insertions, 75 deletions
diff --git a/embassy-stm32/src/usart/buffered.rs b/embassy-stm32/src/usart/buffered.rs
index 323d83818..e2d6e42af 100644
--- a/embassy-stm32/src/usart/buffered.rs
+++ b/embassy-stm32/src/usart/buffered.rs
@@ -118,7 +118,7 @@ impl<'d, T: BasicInstance> SetConfig for BufferedUart<'d, T> {
118 type Config = Config; 118 type Config = Config;
119 119
120 fn set_config(&mut self, config: &Self::Config) { 120 fn set_config(&mut self, config: &Self::Config) {
121 self.set_config(config) 121 unwrap!(self.set_config(config))
122 } 122 }
123} 123}
124 124
@@ -126,7 +126,7 @@ impl<'d, T: BasicInstance> SetConfig for BufferedUartRx<'d, T> {
126 type Config = Config; 126 type Config = Config;
127 127
128 fn set_config(&mut self, config: &Self::Config) { 128 fn set_config(&mut self, config: &Self::Config) {
129 self.set_config(config) 129 unwrap!(self.set_config(config))
130 } 130 }
131} 131}
132 132
@@ -134,7 +134,7 @@ impl<'d, T: BasicInstance> SetConfig for BufferedUartTx<'d, T> {
134 type Config = Config; 134 type Config = Config;
135 135
136 fn set_config(&mut self, config: &Self::Config) { 136 fn set_config(&mut self, config: &Self::Config) {
137 self.set_config(config) 137 unwrap!(self.set_config(config))
138 } 138 }
139} 139}
140 140
@@ -147,7 +147,7 @@ impl<'d, T: BasicInstance> BufferedUart<'d, T> {
147 tx_buffer: &'d mut [u8], 147 tx_buffer: &'d mut [u8],
148 rx_buffer: &'d mut [u8], 148 rx_buffer: &'d mut [u8],
149 config: Config, 149 config: Config,
150 ) -> BufferedUart<'d, T> { 150 ) -> Result<Self, ConfigError> {
151 // UartRx and UartTx have one refcount ea. 151 // UartRx and UartTx have one refcount ea.
152 T::enable(); 152 T::enable();
153 T::enable(); 153 T::enable();
@@ -166,7 +166,7 @@ impl<'d, T: BasicInstance> BufferedUart<'d, T> {
166 tx_buffer: &'d mut [u8], 166 tx_buffer: &'d mut [u8],
167 rx_buffer: &'d mut [u8], 167 rx_buffer: &'d mut [u8],
168 config: Config, 168 config: Config,
169 ) -> BufferedUart<'d, T> { 169 ) -> Result<Self, ConfigError> {
170 into_ref!(cts, rts); 170 into_ref!(cts, rts);
171 171
172 // UartRx and UartTx have one refcount ea. 172 // UartRx and UartTx have one refcount ea.
@@ -194,7 +194,7 @@ impl<'d, T: BasicInstance> BufferedUart<'d, T> {
194 tx_buffer: &'d mut [u8], 194 tx_buffer: &'d mut [u8],
195 rx_buffer: &'d mut [u8], 195 rx_buffer: &'d mut [u8],
196 config: Config, 196 config: Config,
197 ) -> BufferedUart<'d, T> { 197 ) -> Result<Self, ConfigError> {
198 into_ref!(de); 198 into_ref!(de);
199 199
200 // UartRx and UartTx have one refcount ea. 200 // UartRx and UartTx have one refcount ea.
@@ -217,7 +217,7 @@ impl<'d, T: BasicInstance> BufferedUart<'d, T> {
217 tx_buffer: &'d mut [u8], 217 tx_buffer: &'d mut [u8],
218 rx_buffer: &'d mut [u8], 218 rx_buffer: &'d mut [u8],
219 config: Config, 219 config: Config,
220 ) -> BufferedUart<'d, T> { 220 ) -> Result<Self, ConfigError> {
221 into_ref!(_peri, rx, tx); 221 into_ref!(_peri, rx, tx);
222 222
223 let state = T::buffered_state(); 223 let state = T::buffered_state();
@@ -230,7 +230,7 @@ impl<'d, T: BasicInstance> BufferedUart<'d, T> {
230 rx.set_as_af(rx.af_num(), AFType::Input); 230 rx.set_as_af(rx.af_num(), AFType::Input);
231 tx.set_as_af(tx.af_num(), AFType::OutputPushPull); 231 tx.set_as_af(tx.af_num(), AFType::OutputPushPull);
232 232
233 configure(r, &config, T::frequency(), T::KIND, true, true); 233 configure(r, &config, T::frequency(), T::KIND, true, true)?;
234 234
235 r.cr1().modify(|w| { 235 r.cr1().modify(|w| {
236 #[cfg(lpuart_v2)] 236 #[cfg(lpuart_v2)]
@@ -243,17 +243,17 @@ impl<'d, T: BasicInstance> BufferedUart<'d, T> {
243 T::Interrupt::unpend(); 243 T::Interrupt::unpend();
244 unsafe { T::Interrupt::enable() }; 244 unsafe { T::Interrupt::enable() };
245 245
246 Self { 246 Ok(Self {
247 rx: BufferedUartRx { phantom: PhantomData }, 247 rx: BufferedUartRx { phantom: PhantomData },
248 tx: BufferedUartTx { phantom: PhantomData }, 248 tx: BufferedUartTx { phantom: PhantomData },
249 } 249 })
250 } 250 }
251 251
252 pub fn split(self) -> (BufferedUartTx<'d, T>, BufferedUartRx<'d, T>) { 252 pub fn split(self) -> (BufferedUartTx<'d, T>, BufferedUartRx<'d, T>) {
253 (self.tx, self.rx) 253 (self.tx, self.rx)
254 } 254 }
255 255
256 pub fn set_config(&mut self, config: &Config) { 256 pub fn set_config(&mut self, config: &Config) -> Result<(), ConfigError> {
257 reconfigure::<T>(config) 257 reconfigure::<T>(config)
258 } 258 }
259} 259}
@@ -333,7 +333,7 @@ impl<'d, T: BasicInstance> BufferedUartRx<'d, T> {
333 } 333 }
334 } 334 }
335 335
336 pub fn set_config(&mut self, config: &Config) { 336 pub fn set_config(&mut self, config: &Config) -> Result<(), ConfigError> {
337 reconfigure::<T>(config) 337 reconfigure::<T>(config)
338 } 338 }
339} 339}
@@ -407,7 +407,7 @@ impl<'d, T: BasicInstance> BufferedUartTx<'d, T> {
407 } 407 }
408 } 408 }
409 409
410 pub fn set_config(&mut self, config: &Config) { 410 pub fn set_config(&mut self, config: &Config) -> Result<(), ConfigError> {
411 reconfigure::<T>(config) 411 reconfigure::<T>(config)
412 } 412 }
413} 413}
diff --git a/embassy-stm32/src/usart/mod.rs b/embassy-stm32/src/usart/mod.rs
index ff02d0a63..45580fe30 100644
--- a/embassy-stm32/src/usart/mod.rs
+++ b/embassy-stm32/src/usart/mod.rs
@@ -13,11 +13,10 @@ use futures::future::{select, Either};
13use crate::dma::{NoDma, Transfer}; 13use crate::dma::{NoDma, Transfer};
14use crate::gpio::sealed::AFType; 14use crate::gpio::sealed::AFType;
15use crate::interrupt::typelevel::Interrupt; 15use crate::interrupt::typelevel::Interrupt;
16#[cfg(not(any(usart_v1, usart_v2)))]
17#[allow(unused_imports)] 16#[allow(unused_imports)]
17#[cfg(not(any(usart_v1, usart_v2)))]
18use crate::pac::usart::regs::Isr as Sr; 18use crate::pac::usart::regs::Isr as Sr;
19#[cfg(any(usart_v1, usart_v2))] 19#[cfg(any(usart_v1, usart_v2))]
20#[allow(unused_imports)]
21use crate::pac::usart::regs::Sr; 20use crate::pac::usart::regs::Sr;
22#[cfg(not(any(usart_v1, usart_v2)))] 21#[cfg(not(any(usart_v1, usart_v2)))]
23use crate::pac::usart::Lpuart as Regs; 22use crate::pac::usart::Lpuart as Regs;
@@ -76,12 +75,14 @@ impl<T: BasicInstance> interrupt::typelevel::Handler<T::Interrupt> for Interrupt
76} 75}
77 76
78#[derive(Clone, Copy, PartialEq, Eq, Debug)] 77#[derive(Clone, Copy, PartialEq, Eq, Debug)]
78#[cfg_attr(feature = "defmt", derive(defmt::Format))]
79pub enum DataBits { 79pub enum DataBits {
80 DataBits8, 80 DataBits8,
81 DataBits9, 81 DataBits9,
82} 82}
83 83
84#[derive(Clone, Copy, PartialEq, Eq, Debug)] 84#[derive(Clone, Copy, PartialEq, Eq, Debug)]
85#[cfg_attr(feature = "defmt", derive(defmt::Format))]
85pub enum Parity { 86pub enum Parity {
86 ParityNone, 87 ParityNone,
87 ParityEven, 88 ParityEven,
@@ -89,6 +90,7 @@ pub enum Parity {
89} 90}
90 91
91#[derive(Clone, Copy, PartialEq, Eq, Debug)] 92#[derive(Clone, Copy, PartialEq, Eq, Debug)]
93#[cfg_attr(feature = "defmt", derive(defmt::Format))]
92pub enum StopBits { 94pub enum StopBits {
93 #[doc = "1 stop bit"] 95 #[doc = "1 stop bit"]
94 STOP1, 96 STOP1,
@@ -102,6 +104,14 @@ pub enum StopBits {
102 104
103#[non_exhaustive] 105#[non_exhaustive]
104#[derive(Clone, Copy, PartialEq, Eq, Debug)] 106#[derive(Clone, Copy, PartialEq, Eq, Debug)]
107#[cfg_attr(feature = "defmt", derive(defmt::Format))]
108pub enum ConfigError {
109 BaudrateTooLow,
110 BaudrateTooHigh,
111}
112
113#[non_exhaustive]
114#[derive(Clone, Copy, PartialEq, Eq, Debug)]
105pub struct Config { 115pub struct Config {
106 pub baudrate: u32, 116 pub baudrate: u32,
107 pub data_bits: DataBits, 117 pub data_bits: DataBits,
@@ -173,8 +183,8 @@ impl<'d, T: BasicInstance, TxDma, RxDma> SetConfig for Uart<'d, T, TxDma, RxDma>
173 type Config = Config; 183 type Config = Config;
174 184
175 fn set_config(&mut self, config: &Self::Config) { 185 fn set_config(&mut self, config: &Self::Config) {
176 self.tx.set_config(config); 186 unwrap!(self.tx.set_config(config));
177 self.rx.set_config(config); 187 unwrap!(self.rx.set_config(config));
178 } 188 }
179} 189}
180 190
@@ -187,7 +197,7 @@ impl<'d, T: BasicInstance, TxDma> SetConfig for UartTx<'d, T, TxDma> {
187 type Config = Config; 197 type Config = Config;
188 198
189 fn set_config(&mut self, config: &Self::Config) { 199 fn set_config(&mut self, config: &Self::Config) {
190 self.set_config(config); 200 unwrap!(self.set_config(config));
191 } 201 }
192} 202}
193 203
@@ -203,7 +213,7 @@ impl<'d, T: BasicInstance, RxDma> SetConfig for UartRx<'d, T, RxDma> {
203 type Config = Config; 213 type Config = Config;
204 214
205 fn set_config(&mut self, config: &Self::Config) { 215 fn set_config(&mut self, config: &Self::Config) {
206 self.set_config(config); 216 unwrap!(self.set_config(config));
207 } 217 }
208} 218}
209 219
@@ -214,7 +224,7 @@ impl<'d, T: BasicInstance, TxDma> UartTx<'d, T, TxDma> {
214 tx: impl Peripheral<P = impl TxPin<T>> + 'd, 224 tx: impl Peripheral<P = impl TxPin<T>> + 'd,
215 tx_dma: impl Peripheral<P = TxDma> + 'd, 225 tx_dma: impl Peripheral<P = TxDma> + 'd,
216 config: Config, 226 config: Config,
217 ) -> Self { 227 ) -> Result<Self, ConfigError> {
218 T::enable(); 228 T::enable();
219 T::reset(); 229 T::reset();
220 230
@@ -227,7 +237,7 @@ impl<'d, T: BasicInstance, TxDma> UartTx<'d, T, TxDma> {
227 cts: impl Peripheral<P = impl CtsPin<T>> + 'd, 237 cts: impl Peripheral<P = impl CtsPin<T>> + 'd,
228 tx_dma: impl Peripheral<P = TxDma> + 'd, 238 tx_dma: impl Peripheral<P = TxDma> + 'd,
229 config: Config, 239 config: Config,
230 ) -> Self { 240 ) -> Result<Self, ConfigError> {
231 into_ref!(cts); 241 into_ref!(cts);
232 242
233 T::enable(); 243 T::enable();
@@ -245,25 +255,25 @@ impl<'d, T: BasicInstance, TxDma> UartTx<'d, T, TxDma> {
245 tx: impl Peripheral<P = impl TxPin<T>> + 'd, 255 tx: impl Peripheral<P = impl TxPin<T>> + 'd,
246 tx_dma: impl Peripheral<P = TxDma> + 'd, 256 tx_dma: impl Peripheral<P = TxDma> + 'd,
247 config: Config, 257 config: Config,
248 ) -> Self { 258 ) -> Result<Self, ConfigError> {
249 into_ref!(_peri, tx, tx_dma); 259 into_ref!(_peri, tx, tx_dma);
250 260
251 let r = T::regs(); 261 let r = T::regs();
252 262
253 tx.set_as_af(tx.af_num(), AFType::OutputPushPull); 263 tx.set_as_af(tx.af_num(), AFType::OutputPushPull);
254 264
255 configure(r, &config, T::frequency(), T::KIND, false, true); 265 configure(r, &config, T::frequency(), T::KIND, false, true)?;
256 266
257 // create state once! 267 // create state once!
258 let _s = T::state(); 268 let _s = T::state();
259 269
260 Self { 270 Ok(Self {
261 tx_dma, 271 tx_dma,
262 phantom: PhantomData, 272 phantom: PhantomData,
263 } 273 })
264 } 274 }
265 275
266 pub fn set_config(&mut self, config: &Config) { 276 pub fn set_config(&mut self, config: &Config) -> Result<(), ConfigError> {
267 reconfigure::<T>(config) 277 reconfigure::<T>(config)
268 } 278 }
269 279
@@ -307,7 +317,7 @@ impl<'d, T: BasicInstance, RxDma> UartRx<'d, T, RxDma> {
307 rx: impl Peripheral<P = impl RxPin<T>> + 'd, 317 rx: impl Peripheral<P = impl RxPin<T>> + 'd,
308 rx_dma: impl Peripheral<P = RxDma> + 'd, 318 rx_dma: impl Peripheral<P = RxDma> + 'd,
309 config: Config, 319 config: Config,
310 ) -> Self { 320 ) -> Result<Self, ConfigError> {
311 T::enable(); 321 T::enable();
312 T::reset(); 322 T::reset();
313 323
@@ -321,7 +331,7 @@ impl<'d, T: BasicInstance, RxDma> UartRx<'d, T, RxDma> {
321 rts: impl Peripheral<P = impl RtsPin<T>> + 'd, 331 rts: impl Peripheral<P = impl RtsPin<T>> + 'd,
322 rx_dma: impl Peripheral<P = RxDma> + 'd, 332 rx_dma: impl Peripheral<P = RxDma> + 'd,
323 config: Config, 333 config: Config,
324 ) -> Self { 334 ) -> Result<Self, ConfigError> {
325 into_ref!(rts); 335 into_ref!(rts);
326 336
327 T::enable(); 337 T::enable();
@@ -340,14 +350,14 @@ impl<'d, T: BasicInstance, RxDma> UartRx<'d, T, RxDma> {
340 rx: impl Peripheral<P = impl RxPin<T>> + 'd, 350 rx: impl Peripheral<P = impl RxPin<T>> + 'd,
341 rx_dma: impl Peripheral<P = RxDma> + 'd, 351 rx_dma: impl Peripheral<P = RxDma> + 'd,
342 config: Config, 352 config: Config,
343 ) -> Self { 353 ) -> Result<Self, ConfigError> {
344 into_ref!(peri, rx, rx_dma); 354 into_ref!(peri, rx, rx_dma);
345 355
346 let r = T::regs(); 356 let r = T::regs();
347 357
348 rx.set_as_af(rx.af_num(), AFType::Input); 358 rx.set_as_af(rx.af_num(), AFType::Input);
349 359
350 configure(r, &config, T::frequency(), T::KIND, true, false); 360 configure(r, &config, T::frequency(), T::KIND, true, false)?;
351 361
352 T::Interrupt::unpend(); 362 T::Interrupt::unpend();
353 unsafe { T::Interrupt::enable() }; 363 unsafe { T::Interrupt::enable() };
@@ -355,16 +365,16 @@ impl<'d, T: BasicInstance, RxDma> UartRx<'d, T, RxDma> {
355 // create state once! 365 // create state once!
356 let _s = T::state(); 366 let _s = T::state();
357 367
358 Self { 368 Ok(Self {
359 _peri: peri, 369 _peri: peri,
360 rx_dma, 370 rx_dma,
361 detect_previous_overrun: config.detect_previous_overrun, 371 detect_previous_overrun: config.detect_previous_overrun,
362 #[cfg(any(usart_v1, usart_v2))] 372 #[cfg(any(usart_v1, usart_v2))]
363 buffered_sr: stm32_metapac::usart::regs::Sr(0), 373 buffered_sr: stm32_metapac::usart::regs::Sr(0),
364 } 374 })
365 } 375 }
366 376
367 pub fn set_config(&mut self, config: &Config) { 377 pub fn set_config(&mut self, config: &Config) -> Result<(), ConfigError> {
368 reconfigure::<T>(config) 378 reconfigure::<T>(config)
369 } 379 }
370 380
@@ -680,7 +690,7 @@ impl<'d, T: BasicInstance, TxDma, RxDma> Uart<'d, T, TxDma, RxDma> {
680 tx_dma: impl Peripheral<P = TxDma> + 'd, 690 tx_dma: impl Peripheral<P = TxDma> + 'd,
681 rx_dma: impl Peripheral<P = RxDma> + 'd, 691 rx_dma: impl Peripheral<P = RxDma> + 'd,
682 config: Config, 692 config: Config,
683 ) -> Self { 693 ) -> Result<Self, ConfigError> {
684 // UartRx and UartTx have one refcount ea. 694 // UartRx and UartTx have one refcount ea.
685 T::enable(); 695 T::enable();
686 T::enable(); 696 T::enable();
@@ -699,7 +709,7 @@ impl<'d, T: BasicInstance, TxDma, RxDma> Uart<'d, T, TxDma, RxDma> {
699 tx_dma: impl Peripheral<P = TxDma> + 'd, 709 tx_dma: impl Peripheral<P = TxDma> + 'd,
700 rx_dma: impl Peripheral<P = RxDma> + 'd, 710 rx_dma: impl Peripheral<P = RxDma> + 'd,
701 config: Config, 711 config: Config,
702 ) -> Self { 712 ) -> Result<Self, ConfigError> {
703 into_ref!(cts, rts); 713 into_ref!(cts, rts);
704 714
705 // UartRx and UartTx have one refcount ea. 715 // UartRx and UartTx have one refcount ea.
@@ -726,7 +736,7 @@ impl<'d, T: BasicInstance, TxDma, RxDma> Uart<'d, T, TxDma, RxDma> {
726 tx_dma: impl Peripheral<P = TxDma> + 'd, 736 tx_dma: impl Peripheral<P = TxDma> + 'd,
727 rx_dma: impl Peripheral<P = RxDma> + 'd, 737 rx_dma: impl Peripheral<P = RxDma> + 'd,
728 config: Config, 738 config: Config,
729 ) -> Self { 739 ) -> Result<Self, ConfigError> {
730 into_ref!(de); 740 into_ref!(de);
731 741
732 // UartRx and UartTx have one refcount ea. 742 // UartRx and UartTx have one refcount ea.
@@ -748,7 +758,7 @@ impl<'d, T: BasicInstance, TxDma, RxDma> Uart<'d, T, TxDma, RxDma> {
748 tx_dma: impl Peripheral<P = TxDma> + 'd, 758 tx_dma: impl Peripheral<P = TxDma> + 'd,
749 rx_dma: impl Peripheral<P = RxDma> + 'd, 759 rx_dma: impl Peripheral<P = RxDma> + 'd,
750 config: Config, 760 config: Config,
751 ) -> Self { 761 ) -> Result<Self, ConfigError> {
752 into_ref!(peri, rx, tx, tx_dma, rx_dma); 762 into_ref!(peri, rx, tx, tx_dma, rx_dma);
753 763
754 let r = T::regs(); 764 let r = T::regs();
@@ -770,7 +780,7 @@ impl<'d, T: BasicInstance, TxDma, RxDma> Uart<'d, T, TxDma, RxDma> {
770 } 780 }
771 } 781 }
772 782
773 configure(r, &config, T::frequency(), T::KIND, true, true); 783 configure(r, &config, T::frequency(), T::KIND, true, true)?;
774 784
775 T::Interrupt::unpend(); 785 T::Interrupt::unpend();
776 unsafe { T::Interrupt::enable() }; 786 unsafe { T::Interrupt::enable() };
@@ -778,7 +788,7 @@ impl<'d, T: BasicInstance, TxDma, RxDma> Uart<'d, T, TxDma, RxDma> {
778 // create state once! 788 // create state once!
779 let _s = T::state(); 789 let _s = T::state();
780 790
781 Self { 791 Ok(Self {
782 tx: UartTx { 792 tx: UartTx {
783 tx_dma, 793 tx_dma,
784 phantom: PhantomData, 794 phantom: PhantomData,
@@ -790,10 +800,10 @@ impl<'d, T: BasicInstance, TxDma, RxDma> Uart<'d, T, TxDma, RxDma> {
790 #[cfg(any(usart_v1, usart_v2))] 800 #[cfg(any(usart_v1, usart_v2))]
791 buffered_sr: stm32_metapac::usart::regs::Sr(0), 801 buffered_sr: stm32_metapac::usart::regs::Sr(0),
792 }, 802 },
793 } 803 })
794 } 804 }
795 805
796 pub fn set_config(&mut self, config: &Config) { 806 pub fn set_config(&mut self, config: &Config) -> Result<(), ConfigError> {
797 reconfigure::<T>(config) 807 reconfigure::<T>(config)
798 } 808 }
799 809
@@ -842,18 +852,27 @@ impl<'d, T: BasicInstance, TxDma, RxDma> Uart<'d, T, TxDma, RxDma> {
842 } 852 }
843} 853}
844 854
845fn reconfigure<T: BasicInstance>(config: &Config) { 855fn reconfigure<T: BasicInstance>(config: &Config) -> Result<(), ConfigError> {
846 T::Interrupt::disable(); 856 T::Interrupt::disable();
847 let r = T::regs(); 857 let r = T::regs();
848 858
849 let cr = r.cr1().read(); 859 let cr = r.cr1().read();
850 configure(r, config, T::frequency(), T::KIND, cr.re(), cr.te()); 860 configure(r, config, T::frequency(), T::KIND, cr.re(), cr.te())?;
851 861
852 T::Interrupt::unpend(); 862 T::Interrupt::unpend();
853 unsafe { T::Interrupt::enable() }; 863 unsafe { T::Interrupt::enable() };
864
865 Ok(())
854} 866}
855 867
856fn configure(r: Regs, config: &Config, pclk_freq: Hertz, kind: Kind, enable_rx: bool, enable_tx: bool) { 868fn configure(
869 r: Regs,
870 config: &Config,
871 pclk_freq: Hertz,
872 kind: Kind,
873 enable_rx: bool,
874 enable_tx: bool,
875) -> Result<(), ConfigError> {
857 if !enable_rx && !enable_tx { 876 if !enable_rx && !enable_tx {
858 panic!("USART: At least one of RX or TX should be enabled"); 877 panic!("USART: At least one of RX or TX should be enabled");
859 } 878 }
@@ -921,7 +940,7 @@ fn configure(r: Regs, config: &Config, pclk_freq: Hertz, kind: Kind, enable_rx:
921 found_brr = Some(brr); 940 found_brr = Some(brr);
922 break; 941 break;
923 } 942 }
924 panic!("USART: baudrate too high"); 943 return Err(ConfigError::BaudrateTooHigh);
925 } 944 }
926 945
927 if brr < brr_max { 946 if brr < brr_max {
@@ -933,7 +952,7 @@ fn configure(r: Regs, config: &Config, pclk_freq: Hertz, kind: Kind, enable_rx:
933 } 952 }
934 } 953 }
935 954
936 let brr = found_brr.expect("USART: baudrate too low"); 955 let brr = found_brr.ok_or(ConfigError::BaudrateTooLow)?;
937 956
938 #[cfg(not(usart_v1))] 957 #[cfg(not(usart_v1))]
939 let oversampling = if over8 { "8 bit" } else { "16 bit" }; 958 let oversampling = if over8 { "8 bit" } else { "16 bit" };
@@ -985,6 +1004,8 @@ fn configure(r: Regs, config: &Config, pclk_freq: Hertz, kind: Kind, enable_rx:
985 r.cr3().modify(|w| { 1004 r.cr3().modify(|w| {
986 w.set_onebit(config.assume_noise_free); 1005 w.set_onebit(config.assume_noise_free);
987 }); 1006 });
1007
1008 Ok(())
988} 1009}
989 1010
990mod eh02 { 1011mod eh02 {
diff --git a/embassy-stm32/src/usart/ringbuffered.rs b/embassy-stm32/src/usart/ringbuffered.rs
index eed5ef5d6..347aae7c9 100644
--- a/embassy-stm32/src/usart/ringbuffered.rs
+++ b/embassy-stm32/src/usart/ringbuffered.rs
@@ -7,7 +7,7 @@ use embassy_embedded_hal::SetConfig;
7use embassy_hal_internal::PeripheralRef; 7use embassy_hal_internal::PeripheralRef;
8use futures::future::{select, Either}; 8use futures::future::{select, Either};
9 9
10use super::{clear_interrupt_flags, rdr, reconfigure, sr, BasicInstance, Config, Error, UartRx}; 10use super::{clear_interrupt_flags, rdr, reconfigure, sr, BasicInstance, Config, ConfigError, Error, UartRx};
11use crate::dma::ReadableRingBuffer; 11use crate::dma::ReadableRingBuffer;
12use crate::usart::{Regs, Sr}; 12use crate::usart::{Regs, Sr};
13 13
@@ -20,7 +20,7 @@ impl<'d, T: BasicInstance, RxDma: super::RxDma<T>> SetConfig for RingBufferedUar
20 type Config = Config; 20 type Config = Config;
21 21
22 fn set_config(&mut self, config: &Self::Config) { 22 fn set_config(&mut self, config: &Self::Config) {
23 self.set_config(config); 23 unwrap!(self.set_config(config));
24 } 24 }
25} 25}
26 26
@@ -63,7 +63,7 @@ impl<'d, T: BasicInstance, RxDma: super::RxDma<T>> RingBufferedUartRx<'d, T, RxD
63 Err(err) 63 Err(err)
64 } 64 }
65 65
66 pub fn set_config(&mut self, config: &Config) { 66 pub fn set_config(&mut self, config: &Config) -> Result<(), ConfigError> {
67 self.teardown_uart(); 67 self.teardown_uart();
68 reconfigure::<T>(config) 68 reconfigure::<T>(config)
69 } 69 }
diff --git a/examples/stm32f3/src/bin/usart_dma.rs b/examples/stm32f3/src/bin/usart_dma.rs
index 85f01a69e..ce8c212ae 100644
--- a/examples/stm32f3/src/bin/usart_dma.rs
+++ b/examples/stm32f3/src/bin/usart_dma.rs
@@ -22,7 +22,7 @@ async fn main(_spawner: Spawner) {
22 info!("Hello World!"); 22 info!("Hello World!");
23 23
24 let config = Config::default(); 24 let config = Config::default();
25 let mut usart = Uart::new(p.USART1, p.PE1, p.PE0, Irqs, p.DMA1_CH4, NoDma, config); 25 let mut usart = Uart::new(p.USART1, p.PE1, p.PE0, Irqs, p.DMA1_CH4, NoDma, config).unwrap();
26 26
27 for n in 0u32.. { 27 for n in 0u32.. {
28 let mut s: String<128> = String::new(); 28 let mut s: String<128> = String::new();
diff --git a/examples/stm32f4/src/bin/usart.rs b/examples/stm32f4/src/bin/usart.rs
index 7680fe845..45e94715f 100644
--- a/examples/stm32f4/src/bin/usart.rs
+++ b/examples/stm32f4/src/bin/usart.rs
@@ -20,7 +20,7 @@ fn main() -> ! {
20 let p = embassy_stm32::init(Default::default()); 20 let p = embassy_stm32::init(Default::default());
21 21
22 let config = Config::default(); 22 let config = Config::default();
23 let mut usart = Uart::new(p.USART3, p.PD9, p.PD8, Irqs, NoDma, NoDma, config); 23 let mut usart = Uart::new(p.USART3, p.PD9, p.PD8, Irqs, NoDma, NoDma, config).unwrap();
24 24
25 unwrap!(usart.blocking_write(b"Hello Embassy World!\r\n")); 25 unwrap!(usart.blocking_write(b"Hello Embassy World!\r\n"));
26 info!("wrote Hello, starting echo"); 26 info!("wrote Hello, starting echo");
diff --git a/examples/stm32f4/src/bin/usart_buffered.rs b/examples/stm32f4/src/bin/usart_buffered.rs
index c0a64d94b..71abc2893 100644
--- a/examples/stm32f4/src/bin/usart_buffered.rs
+++ b/examples/stm32f4/src/bin/usart_buffered.rs
@@ -22,7 +22,7 @@ async fn main(_spawner: Spawner) {
22 22
23 let mut tx_buf = [0u8; 32]; 23 let mut tx_buf = [0u8; 32];
24 let mut rx_buf = [0u8; 32]; 24 let mut rx_buf = [0u8; 32];
25 let mut buf_usart = BufferedUart::new(p.USART3, Irqs, p.PD9, p.PD8, &mut tx_buf, &mut rx_buf, config); 25 let mut buf_usart = BufferedUart::new(p.USART3, Irqs, p.PD9, p.PD8, &mut tx_buf, &mut rx_buf, config).unwrap();
26 26
27 loop { 27 loop {
28 let buf = buf_usart.fill_buf().await.unwrap(); 28 let buf = buf_usart.fill_buf().await.unwrap();
diff --git a/examples/stm32f4/src/bin/usart_dma.rs b/examples/stm32f4/src/bin/usart_dma.rs
index 3408ec370..dca25a78c 100644
--- a/examples/stm32f4/src/bin/usart_dma.rs
+++ b/examples/stm32f4/src/bin/usart_dma.rs
@@ -22,7 +22,7 @@ async fn main(_spawner: Spawner) {
22 info!("Hello World!"); 22 info!("Hello World!");
23 23
24 let config = Config::default(); 24 let config = Config::default();
25 let mut usart = Uart::new(p.USART3, p.PD9, p.PD8, Irqs, p.DMA1_CH3, NoDma, config); 25 let mut usart = Uart::new(p.USART3, p.PD9, p.PD8, Irqs, p.DMA1_CH3, NoDma, config).unwrap();
26 26
27 for n in 0u32.. { 27 for n in 0u32.. {
28 let mut s: String<128> = String::new(); 28 let mut s: String<128> = String::new();
diff --git a/examples/stm32f7/src/bin/usart_dma.rs b/examples/stm32f7/src/bin/usart_dma.rs
index 4700287a7..ba064081e 100644
--- a/examples/stm32f7/src/bin/usart_dma.rs
+++ b/examples/stm32f7/src/bin/usart_dma.rs
@@ -20,7 +20,7 @@ bind_interrupts!(struct Irqs {
20async fn main(_spawner: Spawner) { 20async fn main(_spawner: Spawner) {
21 let p = embassy_stm32::init(Default::default()); 21 let p = embassy_stm32::init(Default::default());
22 let config = Config::default(); 22 let config = Config::default();
23 let mut usart = Uart::new(p.UART7, p.PA8, p.PA15, Irqs, p.DMA1_CH1, NoDma, config); 23 let mut usart = Uart::new(p.UART7, p.PA8, p.PA15, Irqs, p.DMA1_CH1, NoDma, config).unwrap();
24 24
25 for n in 0u32.. { 25 for n in 0u32.. {
26 let mut s: String<128> = String::new(); 26 let mut s: String<128> = String::new();
diff --git a/examples/stm32h5/src/bin/usart.rs b/examples/stm32h5/src/bin/usart.rs
index 0abb94abb..db04d4e55 100644
--- a/examples/stm32h5/src/bin/usart.rs
+++ b/examples/stm32h5/src/bin/usart.rs
@@ -20,7 +20,7 @@ async fn main_task() {
20 let p = embassy_stm32::init(Default::default()); 20 let p = embassy_stm32::init(Default::default());
21 21
22 let config = Config::default(); 22 let config = Config::default();
23 let mut usart = Uart::new(p.UART7, p.PF6, p.PF7, Irqs, NoDma, NoDma, config); 23 let mut usart = Uart::new(p.UART7, p.PF6, p.PF7, Irqs, NoDma, NoDma, config).unwrap();
24 24
25 unwrap!(usart.blocking_write(b"Hello Embassy World!\r\n")); 25 unwrap!(usart.blocking_write(b"Hello Embassy World!\r\n"));
26 info!("wrote Hello, starting echo"); 26 info!("wrote Hello, starting echo");
diff --git a/examples/stm32h5/src/bin/usart_dma.rs b/examples/stm32h5/src/bin/usart_dma.rs
index 48264f884..bafe50839 100644
--- a/examples/stm32h5/src/bin/usart_dma.rs
+++ b/examples/stm32h5/src/bin/usart_dma.rs
@@ -23,7 +23,7 @@ async fn main_task() {
23 let p = embassy_stm32::init(Default::default()); 23 let p = embassy_stm32::init(Default::default());
24 24
25 let config = Config::default(); 25 let config = Config::default();
26 let mut usart = Uart::new(p.UART7, p.PF6, p.PF7, Irqs, p.GPDMA1_CH0, NoDma, config); 26 let mut usart = Uart::new(p.UART7, p.PF6, p.PF7, Irqs, p.GPDMA1_CH0, NoDma, config).unwrap();
27 27
28 for n in 0u32.. { 28 for n in 0u32.. {
29 let mut s: String<128> = String::new(); 29 let mut s: String<128> = String::new();
diff --git a/examples/stm32h5/src/bin/usart_split.rs b/examples/stm32h5/src/bin/usart_split.rs
index a6b2e690b..d9037c014 100644
--- a/examples/stm32h5/src/bin/usart_split.rs
+++ b/examples/stm32h5/src/bin/usart_split.rs
@@ -36,7 +36,7 @@ async fn main(spawner: Spawner) -> ! {
36 info!("Hello World!"); 36 info!("Hello World!");
37 37
38 let config = Config::default(); 38 let config = Config::default();
39 let mut usart = Uart::new(p.UART7, p.PF6, p.PF7, Irqs, p.GPDMA1_CH0, p.GPDMA1_CH1, config); 39 let mut usart = Uart::new(p.UART7, p.PF6, p.PF7, Irqs, p.GPDMA1_CH0, p.GPDMA1_CH1, config).unwrap();
40 unwrap!(usart.blocking_write(b"Type 8 chars to echo!\r\n")); 40 unwrap!(usart.blocking_write(b"Type 8 chars to echo!\r\n"));
41 41
42 let (mut tx, rx) = usart.split(); 42 let (mut tx, rx) = usart.split();
diff --git a/examples/stm32h7/src/bin/usart.rs b/examples/stm32h7/src/bin/usart.rs
index 0abb94abb..db04d4e55 100644
--- a/examples/stm32h7/src/bin/usart.rs
+++ b/examples/stm32h7/src/bin/usart.rs
@@ -20,7 +20,7 @@ async fn main_task() {
20 let p = embassy_stm32::init(Default::default()); 20 let p = embassy_stm32::init(Default::default());
21 21
22 let config = Config::default(); 22 let config = Config::default();
23 let mut usart = Uart::new(p.UART7, p.PF6, p.PF7, Irqs, NoDma, NoDma, config); 23 let mut usart = Uart::new(p.UART7, p.PF6, p.PF7, Irqs, NoDma, NoDma, config).unwrap();
24 24
25 unwrap!(usart.blocking_write(b"Hello Embassy World!\r\n")); 25 unwrap!(usart.blocking_write(b"Hello Embassy World!\r\n"));
26 info!("wrote Hello, starting echo"); 26 info!("wrote Hello, starting echo");
diff --git a/examples/stm32h7/src/bin/usart_dma.rs b/examples/stm32h7/src/bin/usart_dma.rs
index f1fe7fce6..249050fd1 100644
--- a/examples/stm32h7/src/bin/usart_dma.rs
+++ b/examples/stm32h7/src/bin/usart_dma.rs
@@ -23,7 +23,7 @@ async fn main_task() {
23 let p = embassy_stm32::init(Default::default()); 23 let p = embassy_stm32::init(Default::default());
24 24
25 let config = Config::default(); 25 let config = Config::default();
26 let mut usart = Uart::new(p.UART7, p.PF6, p.PF7, Irqs, p.DMA1_CH0, NoDma, config); 26 let mut usart = Uart::new(p.UART7, p.PF6, p.PF7, Irqs, p.DMA1_CH0, NoDma, config).unwrap();
27 27
28 for n in 0u32.. { 28 for n in 0u32.. {
29 let mut s: String<128> = String::new(); 29 let mut s: String<128> = String::new();
diff --git a/examples/stm32h7/src/bin/usart_split.rs b/examples/stm32h7/src/bin/usart_split.rs
index aa0753450..61c9f1954 100644
--- a/examples/stm32h7/src/bin/usart_split.rs
+++ b/examples/stm32h7/src/bin/usart_split.rs
@@ -36,7 +36,7 @@ async fn main(spawner: Spawner) -> ! {
36 info!("Hello World!"); 36 info!("Hello World!");
37 37
38 let config = Config::default(); 38 let config = Config::default();
39 let mut usart = Uart::new(p.UART7, p.PF6, p.PF7, Irqs, p.DMA1_CH0, p.DMA1_CH1, config); 39 let mut usart = Uart::new(p.UART7, p.PF6, p.PF7, Irqs, p.DMA1_CH0, p.DMA1_CH1, config).unwrap();
40 unwrap!(usart.blocking_write(b"Type 8 chars to echo!\r\n")); 40 unwrap!(usart.blocking_write(b"Type 8 chars to echo!\r\n"));
41 41
42 let (mut tx, rx) = usart.split(); 42 let (mut tx, rx) = usart.split();
diff --git a/examples/stm32l0/src/bin/usart_dma.rs b/examples/stm32l0/src/bin/usart_dma.rs
index eae8f3452..62c9b5595 100644
--- a/examples/stm32l0/src/bin/usart_dma.rs
+++ b/examples/stm32l0/src/bin/usart_dma.rs
@@ -15,7 +15,7 @@ bind_interrupts!(struct Irqs {
15#[embassy_executor::main] 15#[embassy_executor::main]
16async fn main(_spawner: Spawner) { 16async fn main(_spawner: Spawner) {
17 let p = embassy_stm32::init(Default::default()); 17 let p = embassy_stm32::init(Default::default());
18 let mut usart = Uart::new(p.USART1, p.PB7, p.PB6, Irqs, p.DMA1_CH2, p.DMA1_CH3, Config::default()); 18 let mut usart = Uart::new(p.USART1, p.PB7, p.PB6, Irqs, p.DMA1_CH2, p.DMA1_CH3, Config::default()).unwrap();
19 19
20 usart.write(b"Hello Embassy World!\r\n").await.unwrap(); 20 usart.write(b"Hello Embassy World!\r\n").await.unwrap();
21 info!("wrote Hello, starting echo"); 21 info!("wrote Hello, starting echo");
diff --git a/examples/stm32l0/src/bin/usart_irq.rs b/examples/stm32l0/src/bin/usart_irq.rs
index f5dabcc42..5107a1a0a 100644
--- a/examples/stm32l0/src/bin/usart_irq.rs
+++ b/examples/stm32l0/src/bin/usart_irq.rs
@@ -18,13 +18,11 @@ async fn main(_spawner: Spawner) {
18 let p = embassy_stm32::init(Default::default()); 18 let p = embassy_stm32::init(Default::default());
19 info!("Hi!"); 19 info!("Hi!");
20 20
21 static mut TX_BUFFER: [u8; 8] = [0; 8];
22 static mut RX_BUFFER: [u8; 256] = [0; 256];
23
24 let mut config = Config::default(); 21 let mut config = Config::default();
25 config.baudrate = 9600; 22 config.baudrate = 9600;
26 23 let mut tx_buf = [0u8; 256];
27 let mut usart = unsafe { BufferedUart::new(p.USART2, Irqs, p.PA3, p.PA2, &mut TX_BUFFER, &mut RX_BUFFER, config) }; 24 let mut rx_buf = [0u8; 256];
25 let mut usart = BufferedUart::new(p.USART2, Irqs, p.PA3, p.PA2, &mut tx_buf, &mut rx_buf, config).unwrap();
28 26
29 usart.write_all(b"Hello Embassy World!\r\n").await.unwrap(); 27 usart.write_all(b"Hello Embassy World!\r\n").await.unwrap();
30 info!("wrote Hello, starting echo"); 28 info!("wrote Hello, starting echo");
diff --git a/examples/stm32l4/src/bin/usart.rs b/examples/stm32l4/src/bin/usart.rs
index beb5ec558..f4da6b5ae 100644
--- a/examples/stm32l4/src/bin/usart.rs
+++ b/examples/stm32l4/src/bin/usart.rs
@@ -19,7 +19,7 @@ fn main() -> ! {
19 let p = embassy_stm32::init(Default::default()); 19 let p = embassy_stm32::init(Default::default());
20 20
21 let config = Config::default(); 21 let config = Config::default();
22 let mut usart = Uart::new(p.UART4, p.PA1, p.PA0, Irqs, NoDma, NoDma, config); 22 let mut usart = Uart::new(p.UART4, p.PA1, p.PA0, Irqs, NoDma, NoDma, config).unwrap();
23 23
24 unwrap!(usart.blocking_write(b"Hello Embassy World!\r\n")); 24 unwrap!(usart.blocking_write(b"Hello Embassy World!\r\n"));
25 info!("wrote Hello, starting echo"); 25 info!("wrote Hello, starting echo");
diff --git a/examples/stm32l4/src/bin/usart_dma.rs b/examples/stm32l4/src/bin/usart_dma.rs
index b7d4cb01e..2f3b2a0f0 100644
--- a/examples/stm32l4/src/bin/usart_dma.rs
+++ b/examples/stm32l4/src/bin/usart_dma.rs
@@ -22,7 +22,7 @@ async fn main(_spawner: Spawner) {
22 info!("Hello World!"); 22 info!("Hello World!");
23 23
24 let config = Config::default(); 24 let config = Config::default();
25 let mut usart = Uart::new(p.UART4, p.PA1, p.PA0, Irqs, p.DMA1_CH3, NoDma, config); 25 let mut usart = Uart::new(p.UART4, p.PA1, p.PA0, Irqs, p.DMA1_CH3, NoDma, config).unwrap();
26 26
27 for n in 0u32.. { 27 for n in 0u32.. {
28 let mut s: String<128> = String::new(); 28 let mut s: String<128> = String::new();
diff --git a/examples/stm32wl/src/bin/uart_async.rs b/examples/stm32wl/src/bin/uart_async.rs
index 07b0f9d2c..2c9b7c691 100644
--- a/examples/stm32wl/src/bin/uart_async.rs
+++ b/examples/stm32wl/src/bin/uart_async.rs
@@ -33,10 +33,10 @@ async fn main(_spawner: Spawner) {
33 config2.baudrate = 9600; 33 config2.baudrate = 9600;
34 34
35 //RX/TX connected to USB/UART Bridge on LoRa-E5 mini v1.0 35 //RX/TX connected to USB/UART Bridge on LoRa-E5 mini v1.0
36 let mut usart1 = Uart::new(p.USART1, p.PB7, p.PB6, Irqs, p.DMA1_CH3, p.DMA1_CH4, config1); 36 let mut usart1 = Uart::new(p.USART1, p.PB7, p.PB6, Irqs, p.DMA1_CH3, p.DMA1_CH4, config1).unwrap();
37 37
38 //RX1/TX1 (LPUART) on LoRa-E5 mini v1.0 38 //RX1/TX1 (LPUART) on LoRa-E5 mini v1.0
39 let mut usart2 = Uart::new(p.LPUART1, p.PC0, p.PC1, Irqs, p.DMA1_CH5, p.DMA1_CH6, config2); 39 let mut usart2 = Uart::new(p.LPUART1, p.PC0, p.PC1, Irqs, p.DMA1_CH5, p.DMA1_CH6, config2).unwrap();
40 40
41 unwrap!(usart1.write(b"Hello Embassy World!\r\n").await); 41 unwrap!(usart1.write(b"Hello Embassy World!\r\n").await);
42 unwrap!(usart2.write(b"Hello Embassy World!\r\n").await); 42 unwrap!(usart2.write(b"Hello Embassy World!\r\n").await);
diff --git a/tests/stm32/src/bin/usart.rs b/tests/stm32/src/bin/usart.rs
index e789e543d..fece2fb3e 100644
--- a/tests/stm32/src/bin/usart.rs
+++ b/tests/stm32/src/bin/usart.rs
@@ -25,7 +25,7 @@ async fn main(_spawner: Spawner) {
25 25
26 { 26 {
27 let config = Config::default(); 27 let config = Config::default();
28 let mut usart = Uart::new(&mut usart, &mut rx, &mut tx, irq, NoDma, NoDma, config); 28 let mut usart = Uart::new(&mut usart, &mut rx, &mut tx, irq, NoDma, NoDma, config).unwrap();
29 29
30 // We can't send too many bytes, they have to fit in the FIFO. 30 // We can't send too many bytes, they have to fit in the FIFO.
31 // This is because we aren't sending+receiving at the same time. 31 // This is because we aren't sending+receiving at the same time.
@@ -41,7 +41,7 @@ async fn main(_spawner: Spawner) {
41 // Test error handling with with an overflow error 41 // Test error handling with with an overflow error
42 { 42 {
43 let config = Config::default(); 43 let config = Config::default();
44 let mut usart = Uart::new(&mut usart, &mut rx, &mut tx, irq, NoDma, NoDma, config); 44 let mut usart = Uart::new(&mut usart, &mut rx, &mut tx, irq, NoDma, NoDma, config).unwrap();
45 45
46 // Send enough bytes to fill the RX FIFOs off all USART versions. 46 // Send enough bytes to fill the RX FIFOs off all USART versions.
47 let data = [0xC0, 0xDE, 0x12, 0x23, 0x34]; 47 let data = [0xC0, 0xDE, 0x12, 0x23, 0x34];
@@ -75,7 +75,7 @@ async fn main(_spawner: Spawner) {
75 75
76 let mut config = Config::default(); 76 let mut config = Config::default();
77 config.baudrate = baudrate; 77 config.baudrate = baudrate;
78 let mut usart = Uart::new(&mut usart, &mut rx, &mut tx, irq, NoDma, NoDma, config); 78 let mut usart = Uart::new(&mut usart, &mut rx, &mut tx, irq, NoDma, NoDma, config).unwrap();
79 79
80 let n = (baudrate as usize / 100).max(64); 80 let n = (baudrate as usize / 100).max(64);
81 81
diff --git a/tests/stm32/src/bin/usart_dma.rs b/tests/stm32/src/bin/usart_dma.rs
index f203ebb56..1421f6605 100644
--- a/tests/stm32/src/bin/usart_dma.rs
+++ b/tests/stm32/src/bin/usart_dma.rs
@@ -25,7 +25,7 @@ async fn main(_spawner: Spawner) {
25 let irq = irqs!(UART); 25 let irq = irqs!(UART);
26 26
27 let config = Config::default(); 27 let config = Config::default();
28 let usart = Uart::new(usart, rx, tx, irq, tx_dma, rx_dma, config); 28 let usart = Uart::new(usart, rx, tx, irq, tx_dma, rx_dma, config).unwrap();
29 29
30 const LEN: usize = 128; 30 const LEN: usize = 128;
31 let mut tx_buf = [0; LEN]; 31 let mut tx_buf = [0; LEN];
diff --git a/tests/stm32/src/bin/usart_rx_ringbuffered.rs b/tests/stm32/src/bin/usart_rx_ringbuffered.rs
index fdbeb9f6a..1ee7e596d 100644
--- a/tests/stm32/src/bin/usart_rx_ringbuffered.rs
+++ b/tests/stm32/src/bin/usart_rx_ringbuffered.rs
@@ -40,7 +40,7 @@ async fn main(spawner: Spawner) {
40 config.stop_bits = StopBits::STOP1; 40 config.stop_bits = StopBits::STOP1;
41 config.parity = Parity::ParityNone; 41 config.parity = Parity::ParityNone;
42 42
43 let usart = Uart::new(usart, rx, tx, irq, tx_dma, rx_dma, config); 43 let usart = Uart::new(usart, rx, tx, irq, tx_dma, rx_dma, config).unwrap();
44 let (tx, rx) = usart.split(); 44 let (tx, rx) = usart.split();
45 static mut DMA_BUF: [u8; DMA_BUF_SIZE] = [0; DMA_BUF_SIZE]; 45 static mut DMA_BUF: [u8; DMA_BUF_SIZE] = [0; DMA_BUF_SIZE];
46 let dma_buf = unsafe { DMA_BUF.as_mut() }; 46 let dma_buf = unsafe { DMA_BUF.as_mut() };