aboutsummaryrefslogtreecommitdiff
path: root/embassy-stm32/src/usart
diff options
context:
space:
mode:
authorTobias Naumann <[email protected]>2025-03-31 16:48:13 +0200
committerTobias Naumann <[email protected]>2025-03-31 16:48:13 +0200
commitc29fc3532b34633b2234c26a7e41e8ba6d628e7f (patch)
tree667bc74b504a65592c805fd3f66197bd2126801f /embassy-stm32/src/usart
parent14d079ae84ac28ce860015ad6ca8d040edf3f065 (diff)
parent4d9b41714da77d82811f39bd6feabe161e93552c (diff)
Merge branch 'main' into fix/ringbuffered-error-handling to resolve merge conflicts
Diffstat (limited to 'embassy-stm32/src/usart')
-rw-r--r--embassy-stm32/src/usart/buffered.rs82
-rw-r--r--embassy-stm32/src/usart/mod.rs172
-rw-r--r--embassy-stm32/src/usart/ringbuffered.rs6
3 files changed, 130 insertions, 130 deletions
diff --git a/embassy-stm32/src/usart/buffered.rs b/embassy-stm32/src/usart/buffered.rs
index 7fa9ee08e..b1640b6dc 100644
--- a/embassy-stm32/src/usart/buffered.rs
+++ b/embassy-stm32/src/usart/buffered.rs
@@ -6,7 +6,7 @@ use core::task::Poll;
6 6
7use embassy_embedded_hal::SetConfig; 7use embassy_embedded_hal::SetConfig;
8use embassy_hal_internal::atomic_ring_buffer::RingBuffer; 8use embassy_hal_internal::atomic_ring_buffer::RingBuffer;
9use embassy_hal_internal::{Peripheral, PeripheralRef}; 9use embassy_hal_internal::Peri;
10use embassy_sync::waitqueue::AtomicWaker; 10use embassy_sync::waitqueue::AtomicWaker;
11 11
12#[cfg(not(any(usart_v1, usart_v2)))] 12#[cfg(not(any(usart_v1, usart_v2)))]
@@ -159,9 +159,9 @@ pub struct BufferedUartTx<'d> {
159 info: &'static Info, 159 info: &'static Info,
160 state: &'static State, 160 state: &'static State,
161 kernel_clock: Hertz, 161 kernel_clock: Hertz,
162 tx: Option<PeripheralRef<'d, AnyPin>>, 162 tx: Option<Peri<'d, AnyPin>>,
163 cts: Option<PeripheralRef<'d, AnyPin>>, 163 cts: Option<Peri<'d, AnyPin>>,
164 de: Option<PeripheralRef<'d, AnyPin>>, 164 de: Option<Peri<'d, AnyPin>>,
165 is_borrowed: bool, 165 is_borrowed: bool,
166} 166}
167 167
@@ -172,8 +172,8 @@ pub struct BufferedUartRx<'d> {
172 info: &'static Info, 172 info: &'static Info,
173 state: &'static State, 173 state: &'static State,
174 kernel_clock: Hertz, 174 kernel_clock: Hertz,
175 rx: Option<PeripheralRef<'d, AnyPin>>, 175 rx: Option<Peri<'d, AnyPin>>,
176 rts: Option<PeripheralRef<'d, AnyPin>>, 176 rts: Option<Peri<'d, AnyPin>>,
177 is_borrowed: bool, 177 is_borrowed: bool,
178} 178}
179 179
@@ -207,10 +207,10 @@ impl<'d> SetConfig for BufferedUartTx<'d> {
207impl<'d> BufferedUart<'d> { 207impl<'d> BufferedUart<'d> {
208 /// Create a new bidirectional buffered UART driver 208 /// Create a new bidirectional buffered UART driver
209 pub fn new<T: Instance>( 209 pub fn new<T: Instance>(
210 peri: impl Peripheral<P = T> + 'd, 210 peri: Peri<'d, T>,
211 _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, 211 _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd,
212 rx: impl Peripheral<P = impl RxPin<T>> + 'd, 212 rx: Peri<'d, impl RxPin<T>>,
213 tx: impl Peripheral<P = impl TxPin<T>> + 'd, 213 tx: Peri<'d, impl TxPin<T>>,
214 tx_buffer: &'d mut [u8], 214 tx_buffer: &'d mut [u8],
215 rx_buffer: &'d mut [u8], 215 rx_buffer: &'d mut [u8],
216 config: Config, 216 config: Config,
@@ -230,12 +230,12 @@ impl<'d> BufferedUart<'d> {
230 230
231 /// Create a new bidirectional buffered UART driver with request-to-send and clear-to-send pins 231 /// Create a new bidirectional buffered UART driver with request-to-send and clear-to-send pins
232 pub fn new_with_rtscts<T: Instance>( 232 pub fn new_with_rtscts<T: Instance>(
233 peri: impl Peripheral<P = T> + 'd, 233 peri: Peri<'d, T>,
234 _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, 234 _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd,
235 rx: impl Peripheral<P = impl RxPin<T>> + 'd, 235 rx: Peri<'d, impl RxPin<T>>,
236 tx: impl Peripheral<P = impl TxPin<T>> + 'd, 236 tx: Peri<'d, impl TxPin<T>>,
237 rts: impl Peripheral<P = impl RtsPin<T>> + 'd, 237 rts: Peri<'d, impl RtsPin<T>>,
238 cts: impl Peripheral<P = impl CtsPin<T>> + 'd, 238 cts: Peri<'d, impl CtsPin<T>>,
239 tx_buffer: &'d mut [u8], 239 tx_buffer: &'d mut [u8],
240 rx_buffer: &'d mut [u8], 240 rx_buffer: &'d mut [u8],
241 config: Config, 241 config: Config,
@@ -255,11 +255,11 @@ impl<'d> BufferedUart<'d> {
255 255
256 /// Create a new bidirectional buffered UART driver with only the RTS pin as the DE pin 256 /// Create a new bidirectional buffered UART driver with only the RTS pin as the DE pin
257 pub fn new_with_rts_as_de<T: Instance>( 257 pub fn new_with_rts_as_de<T: Instance>(
258 peri: impl Peripheral<P = T> + 'd, 258 peri: Peri<'d, T>,
259 _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, 259 _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd,
260 rx: impl Peripheral<P = impl RxPin<T>> + 'd, 260 rx: Peri<'d, impl RxPin<T>>,
261 tx: impl Peripheral<P = impl TxPin<T>> + 'd, 261 tx: Peri<'d, impl TxPin<T>>,
262 rts: impl Peripheral<P = impl RtsPin<T>> + 'd, 262 rts: Peri<'d, impl RtsPin<T>>,
263 tx_buffer: &'d mut [u8], 263 tx_buffer: &'d mut [u8],
264 rx_buffer: &'d mut [u8], 264 rx_buffer: &'d mut [u8],
265 config: Config, 265 config: Config,
@@ -279,11 +279,11 @@ impl<'d> BufferedUart<'d> {
279 279
280 /// Create a new bidirectional buffered UART driver with only the request-to-send pin 280 /// Create a new bidirectional buffered UART driver with only the request-to-send pin
281 pub fn new_with_rts<T: Instance>( 281 pub fn new_with_rts<T: Instance>(
282 peri: impl Peripheral<P = T> + 'd, 282 peri: Peri<'d, T>,
283 _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, 283 _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd,
284 rx: impl Peripheral<P = impl RxPin<T>> + 'd, 284 rx: Peri<'d, impl RxPin<T>>,
285 tx: impl Peripheral<P = impl TxPin<T>> + 'd, 285 tx: Peri<'d, impl TxPin<T>>,
286 rts: impl Peripheral<P = impl RtsPin<T>> + 'd, 286 rts: Peri<'d, impl RtsPin<T>>,
287 tx_buffer: &'d mut [u8], 287 tx_buffer: &'d mut [u8],
288 rx_buffer: &'d mut [u8], 288 rx_buffer: &'d mut [u8],
289 config: Config, 289 config: Config,
@@ -304,11 +304,11 @@ impl<'d> BufferedUart<'d> {
304 /// Create a new bidirectional buffered UART driver with a driver-enable pin 304 /// Create a new bidirectional buffered UART driver with a driver-enable pin
305 #[cfg(not(any(usart_v1, usart_v2)))] 305 #[cfg(not(any(usart_v1, usart_v2)))]
306 pub fn new_with_de<T: Instance>( 306 pub fn new_with_de<T: Instance>(
307 peri: impl Peripheral<P = T> + 'd, 307 peri: Peri<'d, T>,
308 _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, 308 _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd,
309 rx: impl Peripheral<P = impl RxPin<T>> + 'd, 309 rx: Peri<'d, impl RxPin<T>>,
310 tx: impl Peripheral<P = impl TxPin<T>> + 'd, 310 tx: Peri<'d, impl TxPin<T>>,
311 de: impl Peripheral<P = impl DePin<T>> + 'd, 311 de: Peri<'d, impl DePin<T>>,
312 tx_buffer: &'d mut [u8], 312 tx_buffer: &'d mut [u8],
313 rx_buffer: &'d mut [u8], 313 rx_buffer: &'d mut [u8],
314 config: Config, 314 config: Config,
@@ -339,8 +339,8 @@ impl<'d> BufferedUart<'d> {
339 /// on the line must be managed by software (for instance by using a centralized arbiter). 339 /// on the line must be managed by software (for instance by using a centralized arbiter).
340 #[doc(alias("HDSEL"))] 340 #[doc(alias("HDSEL"))]
341 pub fn new_half_duplex<T: Instance>( 341 pub fn new_half_duplex<T: Instance>(
342 peri: impl Peripheral<P = T> + 'd, 342 peri: Peri<'d, T>,
343 tx: impl Peripheral<P = impl TxPin<T>> + 'd, 343 tx: Peri<'d, impl TxPin<T>>,
344 _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, 344 _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd,
345 tx_buffer: &'d mut [u8], 345 tx_buffer: &'d mut [u8],
346 rx_buffer: &'d mut [u8], 346 rx_buffer: &'d mut [u8],
@@ -379,8 +379,8 @@ impl<'d> BufferedUart<'d> {
379 #[cfg(not(any(usart_v1, usart_v2)))] 379 #[cfg(not(any(usart_v1, usart_v2)))]
380 #[doc(alias("HDSEL"))] 380 #[doc(alias("HDSEL"))]
381 pub fn new_half_duplex_on_rx<T: Instance>( 381 pub fn new_half_duplex_on_rx<T: Instance>(
382 peri: impl Peripheral<P = T> + 'd, 382 peri: Peri<'d, T>,
383 rx: impl Peripheral<P = impl RxPin<T>> + 'd, 383 rx: Peri<'d, impl RxPin<T>>,
384 _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, 384 _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd,
385 tx_buffer: &'d mut [u8], 385 tx_buffer: &'d mut [u8],
386 rx_buffer: &'d mut [u8], 386 rx_buffer: &'d mut [u8],
@@ -405,12 +405,12 @@ impl<'d> BufferedUart<'d> {
405 } 405 }
406 406
407 fn new_inner<T: Instance>( 407 fn new_inner<T: Instance>(
408 _peri: impl Peripheral<P = T> + 'd, 408 _peri: Peri<'d, T>,
409 rx: Option<PeripheralRef<'d, AnyPin>>, 409 rx: Option<Peri<'d, AnyPin>>,
410 tx: Option<PeripheralRef<'d, AnyPin>>, 410 tx: Option<Peri<'d, AnyPin>>,
411 rts: Option<PeripheralRef<'d, AnyPin>>, 411 rts: Option<Peri<'d, AnyPin>>,
412 cts: Option<PeripheralRef<'d, AnyPin>>, 412 cts: Option<Peri<'d, AnyPin>>,
413 de: Option<PeripheralRef<'d, AnyPin>>, 413 de: Option<Peri<'d, AnyPin>>,
414 tx_buffer: &'d mut [u8], 414 tx_buffer: &'d mut [u8],
415 rx_buffer: &'d mut [u8], 415 rx_buffer: &'d mut [u8],
416 config: Config, 416 config: Config,
@@ -505,17 +505,17 @@ impl<'d> BufferedUart<'d> {
505 info: self.tx.info, 505 info: self.tx.info,
506 state: self.tx.state, 506 state: self.tx.state,
507 kernel_clock: self.tx.kernel_clock, 507 kernel_clock: self.tx.kernel_clock,
508 tx: self.tx.tx.as_mut().map(PeripheralRef::reborrow), 508 tx: self.tx.tx.as_mut().map(Peri::reborrow),
509 cts: self.tx.cts.as_mut().map(PeripheralRef::reborrow), 509 cts: self.tx.cts.as_mut().map(Peri::reborrow),
510 de: self.tx.de.as_mut().map(PeripheralRef::reborrow), 510 de: self.tx.de.as_mut().map(Peri::reborrow),
511 is_borrowed: true, 511 is_borrowed: true,
512 }, 512 },
513 BufferedUartRx { 513 BufferedUartRx {
514 info: self.rx.info, 514 info: self.rx.info,
515 state: self.rx.state, 515 state: self.rx.state,
516 kernel_clock: self.rx.kernel_clock, 516 kernel_clock: self.rx.kernel_clock,
517 rx: self.rx.rx.as_mut().map(PeripheralRef::reborrow), 517 rx: self.rx.rx.as_mut().map(Peri::reborrow),
518 rts: self.rx.rts.as_mut().map(PeripheralRef::reborrow), 518 rts: self.rx.rts.as_mut().map(Peri::reborrow),
519 is_borrowed: true, 519 is_borrowed: true,
520 }, 520 },
521 ) 521 )
diff --git a/embassy-stm32/src/usart/mod.rs b/embassy-stm32/src/usart/mod.rs
index 803a5d579..5b7f8dc26 100644
--- a/embassy-stm32/src/usart/mod.rs
+++ b/embassy-stm32/src/usart/mod.rs
@@ -9,7 +9,7 @@ use core::task::Poll;
9 9
10use embassy_embedded_hal::SetConfig; 10use embassy_embedded_hal::SetConfig;
11use embassy_hal_internal::drop::OnDrop; 11use embassy_hal_internal::drop::OnDrop;
12use embassy_hal_internal::PeripheralRef; 12use embassy_hal_internal::PeripheralType;
13use embassy_sync::waitqueue::AtomicWaker; 13use embassy_sync::waitqueue::AtomicWaker;
14use futures_util::future::{select, Either}; 14use futures_util::future::{select, Either};
15 15
@@ -25,7 +25,7 @@ use crate::pac::usart::Usart as Regs;
25use crate::pac::usart::{regs, vals}; 25use crate::pac::usart::{regs, vals};
26use crate::rcc::{RccInfo, SealedRccPeripheral}; 26use crate::rcc::{RccInfo, SealedRccPeripheral};
27use crate::time::Hertz; 27use crate::time::Hertz;
28use crate::Peripheral; 28use crate::Peri;
29 29
30/// Interrupt handler. 30/// Interrupt handler.
31pub struct InterruptHandler<T: Instance> { 31pub struct InterruptHandler<T: Instance> {
@@ -343,9 +343,9 @@ pub struct UartTx<'d, M: Mode> {
343 info: &'static Info, 343 info: &'static Info,
344 state: &'static State, 344 state: &'static State,
345 kernel_clock: Hertz, 345 kernel_clock: Hertz,
346 tx: Option<PeripheralRef<'d, AnyPin>>, 346 tx: Option<Peri<'d, AnyPin>>,
347 cts: Option<PeripheralRef<'d, AnyPin>>, 347 cts: Option<Peri<'d, AnyPin>>,
348 de: Option<PeripheralRef<'d, AnyPin>>, 348 de: Option<Peri<'d, AnyPin>>,
349 tx_dma: Option<ChannelAndRequest<'d>>, 349 tx_dma: Option<ChannelAndRequest<'d>>,
350 duplex: Duplex, 350 duplex: Duplex,
351 _phantom: PhantomData<M>, 351 _phantom: PhantomData<M>,
@@ -393,8 +393,8 @@ pub struct UartRx<'d, M: Mode> {
393 info: &'static Info, 393 info: &'static Info,
394 state: &'static State, 394 state: &'static State,
395 kernel_clock: Hertz, 395 kernel_clock: Hertz,
396 rx: Option<PeripheralRef<'d, AnyPin>>, 396 rx: Option<Peri<'d, AnyPin>>,
397 rts: Option<PeripheralRef<'d, AnyPin>>, 397 rts: Option<Peri<'d, AnyPin>>,
398 rx_dma: Option<ChannelAndRequest<'d>>, 398 rx_dma: Option<ChannelAndRequest<'d>>,
399 detect_previous_overrun: bool, 399 detect_previous_overrun: bool,
400 #[cfg(any(usart_v1, usart_v2))] 400 #[cfg(any(usart_v1, usart_v2))]
@@ -414,9 +414,9 @@ impl<'d, M: Mode> SetConfig for UartRx<'d, M> {
414impl<'d> UartTx<'d, Async> { 414impl<'d> UartTx<'d, Async> {
415 /// Useful if you only want Uart Tx. It saves 1 pin and consumes a little less power. 415 /// Useful if you only want Uart Tx. It saves 1 pin and consumes a little less power.
416 pub fn new<T: Instance>( 416 pub fn new<T: Instance>(
417 peri: impl Peripheral<P = T> + 'd, 417 peri: Peri<'d, T>,
418 tx: impl Peripheral<P = impl TxPin<T>> + 'd, 418 tx: Peri<'d, impl TxPin<T>>,
419 tx_dma: impl Peripheral<P = impl TxDma<T>> + 'd, 419 tx_dma: Peri<'d, impl TxDma<T>>,
420 config: Config, 420 config: Config,
421 ) -> Result<Self, ConfigError> { 421 ) -> Result<Self, ConfigError> {
422 Self::new_inner( 422 Self::new_inner(
@@ -430,10 +430,10 @@ impl<'d> UartTx<'d, Async> {
430 430
431 /// Create a new tx-only UART with a clear-to-send pin 431 /// Create a new tx-only UART with a clear-to-send pin
432 pub fn new_with_cts<T: Instance>( 432 pub fn new_with_cts<T: Instance>(
433 peri: impl Peripheral<P = T> + 'd, 433 peri: Peri<'d, T>,
434 tx: impl Peripheral<P = impl TxPin<T>> + 'd, 434 tx: Peri<'d, impl TxPin<T>>,
435 cts: impl Peripheral<P = impl CtsPin<T>> + 'd, 435 cts: Peri<'d, impl CtsPin<T>>,
436 tx_dma: impl Peripheral<P = impl TxDma<T>> + 'd, 436 tx_dma: Peri<'d, impl TxDma<T>>,
437 config: Config, 437 config: Config,
438 ) -> Result<Self, ConfigError> { 438 ) -> Result<Self, ConfigError> {
439 Self::new_inner( 439 Self::new_inner(
@@ -473,8 +473,8 @@ impl<'d> UartTx<'d, Blocking> {
473 /// 473 ///
474 /// Useful if you only want Uart Tx. It saves 1 pin and consumes a little less power. 474 /// Useful if you only want Uart Tx. It saves 1 pin and consumes a little less power.
475 pub fn new_blocking<T: Instance>( 475 pub fn new_blocking<T: Instance>(
476 peri: impl Peripheral<P = T> + 'd, 476 peri: Peri<'d, T>,
477 tx: impl Peripheral<P = impl TxPin<T>> + 'd, 477 tx: Peri<'d, impl TxPin<T>>,
478 config: Config, 478 config: Config,
479 ) -> Result<Self, ConfigError> { 479 ) -> Result<Self, ConfigError> {
480 Self::new_inner( 480 Self::new_inner(
@@ -488,9 +488,9 @@ impl<'d> UartTx<'d, Blocking> {
488 488
489 /// Create a new blocking tx-only UART with a clear-to-send pin 489 /// Create a new blocking tx-only UART with a clear-to-send pin
490 pub fn new_blocking_with_cts<T: Instance>( 490 pub fn new_blocking_with_cts<T: Instance>(
491 peri: impl Peripheral<P = T> + 'd, 491 peri: Peri<'d, T>,
492 tx: impl Peripheral<P = impl TxPin<T>> + 'd, 492 tx: Peri<'d, impl TxPin<T>>,
493 cts: impl Peripheral<P = impl CtsPin<T>> + 'd, 493 cts: Peri<'d, impl CtsPin<T>>,
494 config: Config, 494 config: Config,
495 ) -> Result<Self, ConfigError> { 495 ) -> Result<Self, ConfigError> {
496 Self::new_inner( 496 Self::new_inner(
@@ -505,9 +505,9 @@ impl<'d> UartTx<'d, Blocking> {
505 505
506impl<'d, M: Mode> UartTx<'d, M> { 506impl<'d, M: Mode> UartTx<'d, M> {
507 fn new_inner<T: Instance>( 507 fn new_inner<T: Instance>(
508 _peri: impl Peripheral<P = T> + 'd, 508 _peri: Peri<'d, T>,
509 tx: Option<PeripheralRef<'d, AnyPin>>, 509 tx: Option<Peri<'d, AnyPin>>,
510 cts: Option<PeripheralRef<'d, AnyPin>>, 510 cts: Option<Peri<'d, AnyPin>>,
511 tx_dma: Option<ChannelAndRequest<'d>>, 511 tx_dma: Option<ChannelAndRequest<'d>>,
512 config: Config, 512 config: Config,
513 ) -> Result<Self, ConfigError> { 513 ) -> Result<Self, ConfigError> {
@@ -645,10 +645,10 @@ impl<'d> UartRx<'d, Async> {
645 /// 645 ///
646 /// Useful if you only want Uart Rx. It saves 1 pin and consumes a little less power. 646 /// Useful if you only want Uart Rx. It saves 1 pin and consumes a little less power.
647 pub fn new<T: Instance>( 647 pub fn new<T: Instance>(
648 peri: impl Peripheral<P = T> + 'd, 648 peri: Peri<'d, T>,
649 _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, 649 _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd,
650 rx: impl Peripheral<P = impl RxPin<T>> + 'd, 650 rx: Peri<'d, impl RxPin<T>>,
651 rx_dma: impl Peripheral<P = impl RxDma<T>> + 'd, 651 rx_dma: Peri<'d, impl RxDma<T>>,
652 config: Config, 652 config: Config,
653 ) -> Result<Self, ConfigError> { 653 ) -> Result<Self, ConfigError> {
654 Self::new_inner( 654 Self::new_inner(
@@ -662,11 +662,11 @@ impl<'d> UartRx<'d, Async> {
662 662
663 /// Create a new rx-only UART with a request-to-send pin 663 /// Create a new rx-only UART with a request-to-send pin
664 pub fn new_with_rts<T: Instance>( 664 pub fn new_with_rts<T: Instance>(
665 peri: impl Peripheral<P = T> + 'd, 665 peri: Peri<'d, T>,
666 _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, 666 _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd,
667 rx: impl Peripheral<P = impl RxPin<T>> + 'd, 667 rx: Peri<'d, impl RxPin<T>>,
668 rts: impl Peripheral<P = impl RtsPin<T>> + 'd, 668 rts: Peri<'d, impl RtsPin<T>>,
669 rx_dma: impl Peripheral<P = impl RxDma<T>> + 'd, 669 rx_dma: Peri<'d, impl RxDma<T>>,
670 config: Config, 670 config: Config,
671 ) -> Result<Self, ConfigError> { 671 ) -> Result<Self, ConfigError> {
672 Self::new_inner( 672 Self::new_inner(
@@ -903,8 +903,8 @@ impl<'d> UartRx<'d, Blocking> {
903 /// 903 ///
904 /// Useful if you only want Uart Rx. It saves 1 pin and consumes a little less power. 904 /// Useful if you only want Uart Rx. It saves 1 pin and consumes a little less power.
905 pub fn new_blocking<T: Instance>( 905 pub fn new_blocking<T: Instance>(
906 peri: impl Peripheral<P = T> + 'd, 906 peri: Peri<'d, T>,
907 rx: impl Peripheral<P = impl RxPin<T>> + 'd, 907 rx: Peri<'d, impl RxPin<T>>,
908 config: Config, 908 config: Config,
909 ) -> Result<Self, ConfigError> { 909 ) -> Result<Self, ConfigError> {
910 Self::new_inner(peri, new_pin!(rx, AfType::input(config.rx_pull)), None, None, config) 910 Self::new_inner(peri, new_pin!(rx, AfType::input(config.rx_pull)), None, None, config)
@@ -912,9 +912,9 @@ impl<'d> UartRx<'d, Blocking> {
912 912
913 /// Create a new rx-only UART with a request-to-send pin 913 /// Create a new rx-only UART with a request-to-send pin
914 pub fn new_blocking_with_rts<T: Instance>( 914 pub fn new_blocking_with_rts<T: Instance>(
915 peri: impl Peripheral<P = T> + 'd, 915 peri: Peri<'d, T>,
916 rx: impl Peripheral<P = impl RxPin<T>> + 'd, 916 rx: Peri<'d, impl RxPin<T>>,
917 rts: impl Peripheral<P = impl RtsPin<T>> + 'd, 917 rts: Peri<'d, impl RtsPin<T>>,
918 config: Config, 918 config: Config,
919 ) -> Result<Self, ConfigError> { 919 ) -> Result<Self, ConfigError> {
920 Self::new_inner( 920 Self::new_inner(
@@ -929,9 +929,9 @@ impl<'d> UartRx<'d, Blocking> {
929 929
930impl<'d, M: Mode> UartRx<'d, M> { 930impl<'d, M: Mode> UartRx<'d, M> {
931 fn new_inner<T: Instance>( 931 fn new_inner<T: Instance>(
932 _peri: impl Peripheral<P = T> + 'd, 932 _peri: Peri<'d, T>,
933 rx: Option<PeripheralRef<'d, AnyPin>>, 933 rx: Option<Peri<'d, AnyPin>>,
934 rts: Option<PeripheralRef<'d, AnyPin>>, 934 rts: Option<Peri<'d, AnyPin>>,
935 rx_dma: Option<ChannelAndRequest<'d>>, 935 rx_dma: Option<ChannelAndRequest<'d>>,
936 config: Config, 936 config: Config,
937 ) -> Result<Self, ConfigError> { 937 ) -> Result<Self, ConfigError> {
@@ -1099,12 +1099,12 @@ fn drop_tx_rx(info: &Info, state: &State) {
1099impl<'d> Uart<'d, Async> { 1099impl<'d> Uart<'d, Async> {
1100 /// Create a new bidirectional UART 1100 /// Create a new bidirectional UART
1101 pub fn new<T: Instance>( 1101 pub fn new<T: Instance>(
1102 peri: impl Peripheral<P = T> + 'd, 1102 peri: Peri<'d, T>,
1103 rx: impl Peripheral<P = impl RxPin<T>> + 'd, 1103 rx: Peri<'d, impl RxPin<T>>,
1104 tx: impl Peripheral<P = impl TxPin<T>> + 'd, 1104 tx: Peri<'d, impl TxPin<T>>,
1105 _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, 1105 _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd,
1106 tx_dma: impl Peripheral<P = impl TxDma<T>> + 'd, 1106 tx_dma: Peri<'d, impl TxDma<T>>,
1107 rx_dma: impl Peripheral<P = impl RxDma<T>> + 'd, 1107 rx_dma: Peri<'d, impl RxDma<T>>,
1108 config: Config, 1108 config: Config,
1109 ) -> Result<Self, ConfigError> { 1109 ) -> Result<Self, ConfigError> {
1110 Self::new_inner( 1110 Self::new_inner(
@@ -1122,14 +1122,14 @@ impl<'d> Uart<'d, Async> {
1122 1122
1123 /// Create a new bidirectional UART with request-to-send and clear-to-send pins 1123 /// Create a new bidirectional UART with request-to-send and clear-to-send pins
1124 pub fn new_with_rtscts<T: Instance>( 1124 pub fn new_with_rtscts<T: Instance>(
1125 peri: impl Peripheral<P = T> + 'd, 1125 peri: Peri<'d, T>,
1126 rx: impl Peripheral<P = impl RxPin<T>> + 'd, 1126 rx: Peri<'d, impl RxPin<T>>,
1127 tx: impl Peripheral<P = impl TxPin<T>> + 'd, 1127 tx: Peri<'d, impl TxPin<T>>,
1128 _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, 1128 _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd,
1129 rts: impl Peripheral<P = impl RtsPin<T>> + 'd, 1129 rts: Peri<'d, impl RtsPin<T>>,
1130 cts: impl Peripheral<P = impl CtsPin<T>> + 'd, 1130 cts: Peri<'d, impl CtsPin<T>>,
1131 tx_dma: impl Peripheral<P = impl TxDma<T>> + 'd, 1131 tx_dma: Peri<'d, impl TxDma<T>>,
1132 rx_dma: impl Peripheral<P = impl RxDma<T>> + 'd, 1132 rx_dma: Peri<'d, impl RxDma<T>>,
1133 config: Config, 1133 config: Config,
1134 ) -> Result<Self, ConfigError> { 1134 ) -> Result<Self, ConfigError> {
1135 Self::new_inner( 1135 Self::new_inner(
@@ -1148,13 +1148,13 @@ impl<'d> Uart<'d, Async> {
1148 #[cfg(not(any(usart_v1, usart_v2)))] 1148 #[cfg(not(any(usart_v1, usart_v2)))]
1149 /// Create a new bidirectional UART with a driver-enable pin 1149 /// Create a new bidirectional UART with a driver-enable pin
1150 pub fn new_with_de<T: Instance>( 1150 pub fn new_with_de<T: Instance>(
1151 peri: impl Peripheral<P = T> + 'd, 1151 peri: Peri<'d, T>,
1152 rx: impl Peripheral<P = impl RxPin<T>> + 'd, 1152 rx: Peri<'d, impl RxPin<T>>,
1153 tx: impl Peripheral<P = impl TxPin<T>> + 'd, 1153 tx: Peri<'d, impl TxPin<T>>,
1154 _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, 1154 _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd,
1155 de: impl Peripheral<P = impl DePin<T>> + 'd, 1155 de: Peri<'d, impl DePin<T>>,
1156 tx_dma: impl Peripheral<P = impl TxDma<T>> + 'd, 1156 tx_dma: Peri<'d, impl TxDma<T>>,
1157 rx_dma: impl Peripheral<P = impl RxDma<T>> + 'd, 1157 rx_dma: Peri<'d, impl RxDma<T>>,
1158 config: Config, 1158 config: Config,
1159 ) -> Result<Self, ConfigError> { 1159 ) -> Result<Self, ConfigError> {
1160 Self::new_inner( 1160 Self::new_inner(
@@ -1183,11 +1183,11 @@ impl<'d> Uart<'d, Async> {
1183 /// on the line must be managed by software (for instance by using a centralized arbiter). 1183 /// on the line must be managed by software (for instance by using a centralized arbiter).
1184 #[doc(alias("HDSEL"))] 1184 #[doc(alias("HDSEL"))]
1185 pub fn new_half_duplex<T: Instance>( 1185 pub fn new_half_duplex<T: Instance>(
1186 peri: impl Peripheral<P = T> + 'd, 1186 peri: Peri<'d, T>,
1187 tx: impl Peripheral<P = impl TxPin<T>> + 'd, 1187 tx: Peri<'d, impl TxPin<T>>,
1188 _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, 1188 _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd,
1189 tx_dma: impl Peripheral<P = impl TxDma<T>> + 'd, 1189 tx_dma: Peri<'d, impl TxDma<T>>,
1190 rx_dma: impl Peripheral<P = impl RxDma<T>> + 'd, 1190 rx_dma: Peri<'d, impl RxDma<T>>,
1191 mut config: Config, 1191 mut config: Config,
1192 readback: HalfDuplexReadback, 1192 readback: HalfDuplexReadback,
1193 half_duplex: HalfDuplexConfig, 1193 half_duplex: HalfDuplexConfig,
@@ -1223,11 +1223,11 @@ impl<'d> Uart<'d, Async> {
1223 #[cfg(not(any(usart_v1, usart_v2)))] 1223 #[cfg(not(any(usart_v1, usart_v2)))]
1224 #[doc(alias("HDSEL"))] 1224 #[doc(alias("HDSEL"))]
1225 pub fn new_half_duplex_on_rx<T: Instance>( 1225 pub fn new_half_duplex_on_rx<T: Instance>(
1226 peri: impl Peripheral<P = T> + 'd, 1226 peri: Peri<'d, T>,
1227 rx: impl Peripheral<P = impl RxPin<T>> + 'd, 1227 rx: Peri<'d, impl RxPin<T>>,
1228 _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, 1228 _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd,
1229 tx_dma: impl Peripheral<P = impl TxDma<T>> + 'd, 1229 tx_dma: Peri<'d, impl TxDma<T>>,
1230 rx_dma: impl Peripheral<P = impl RxDma<T>> + 'd, 1230 rx_dma: Peri<'d, impl RxDma<T>>,
1231 mut config: Config, 1231 mut config: Config,
1232 readback: HalfDuplexReadback, 1232 readback: HalfDuplexReadback,
1233 half_duplex: HalfDuplexConfig, 1233 half_duplex: HalfDuplexConfig,
@@ -1272,9 +1272,9 @@ impl<'d> Uart<'d, Async> {
1272impl<'d> Uart<'d, Blocking> { 1272impl<'d> Uart<'d, Blocking> {
1273 /// Create a new blocking bidirectional UART. 1273 /// Create a new blocking bidirectional UART.
1274 pub fn new_blocking<T: Instance>( 1274 pub fn new_blocking<T: Instance>(
1275 peri: impl Peripheral<P = T> + 'd, 1275 peri: Peri<'d, T>,
1276 rx: impl Peripheral<P = impl RxPin<T>> + 'd, 1276 rx: Peri<'d, impl RxPin<T>>,
1277 tx: impl Peripheral<P = impl TxPin<T>> + 'd, 1277 tx: Peri<'d, impl TxPin<T>>,
1278 config: Config, 1278 config: Config,
1279 ) -> Result<Self, ConfigError> { 1279 ) -> Result<Self, ConfigError> {
1280 Self::new_inner( 1280 Self::new_inner(
@@ -1292,11 +1292,11 @@ impl<'d> Uart<'d, Blocking> {
1292 1292
1293 /// Create a new bidirectional UART with request-to-send and clear-to-send pins 1293 /// Create a new bidirectional UART with request-to-send and clear-to-send pins
1294 pub fn new_blocking_with_rtscts<T: Instance>( 1294 pub fn new_blocking_with_rtscts<T: Instance>(
1295 peri: impl Peripheral<P = T> + 'd, 1295 peri: Peri<'d, T>,
1296 rx: impl Peripheral<P = impl RxPin<T>> + 'd, 1296 rx: Peri<'d, impl RxPin<T>>,
1297 tx: impl Peripheral<P = impl TxPin<T>> + 'd, 1297 tx: Peri<'d, impl TxPin<T>>,
1298 rts: impl Peripheral<P = impl RtsPin<T>> + 'd, 1298 rts: Peri<'d, impl RtsPin<T>>,
1299 cts: impl Peripheral<P = impl CtsPin<T>> + 'd, 1299 cts: Peri<'d, impl CtsPin<T>>,
1300 config: Config, 1300 config: Config,
1301 ) -> Result<Self, ConfigError> { 1301 ) -> Result<Self, ConfigError> {
1302 Self::new_inner( 1302 Self::new_inner(
@@ -1315,10 +1315,10 @@ impl<'d> Uart<'d, Blocking> {
1315 #[cfg(not(any(usart_v1, usart_v2)))] 1315 #[cfg(not(any(usart_v1, usart_v2)))]
1316 /// Create a new bidirectional UART with a driver-enable pin 1316 /// Create a new bidirectional UART with a driver-enable pin
1317 pub fn new_blocking_with_de<T: Instance>( 1317 pub fn new_blocking_with_de<T: Instance>(
1318 peri: impl Peripheral<P = T> + 'd, 1318 peri: Peri<'d, T>,
1319 rx: impl Peripheral<P = impl RxPin<T>> + 'd, 1319 rx: Peri<'d, impl RxPin<T>>,
1320 tx: impl Peripheral<P = impl TxPin<T>> + 'd, 1320 tx: Peri<'d, impl TxPin<T>>,
1321 de: impl Peripheral<P = impl DePin<T>> + 'd, 1321 de: Peri<'d, impl DePin<T>>,
1322 config: Config, 1322 config: Config,
1323 ) -> Result<Self, ConfigError> { 1323 ) -> Result<Self, ConfigError> {
1324 Self::new_inner( 1324 Self::new_inner(
@@ -1346,8 +1346,8 @@ impl<'d> Uart<'d, Blocking> {
1346 /// on the line must be managed by software (for instance by using a centralized arbiter). 1346 /// on the line must be managed by software (for instance by using a centralized arbiter).
1347 #[doc(alias("HDSEL"))] 1347 #[doc(alias("HDSEL"))]
1348 pub fn new_blocking_half_duplex<T: Instance>( 1348 pub fn new_blocking_half_duplex<T: Instance>(
1349 peri: impl Peripheral<P = T> + 'd, 1349 peri: Peri<'d, T>,
1350 tx: impl Peripheral<P = impl TxPin<T>> + 'd, 1350 tx: Peri<'d, impl TxPin<T>>,
1351 mut config: Config, 1351 mut config: Config,
1352 readback: HalfDuplexReadback, 1352 readback: HalfDuplexReadback,
1353 half_duplex: HalfDuplexConfig, 1353 half_duplex: HalfDuplexConfig,
@@ -1383,8 +1383,8 @@ impl<'d> Uart<'d, Blocking> {
1383 #[cfg(not(any(usart_v1, usart_v2)))] 1383 #[cfg(not(any(usart_v1, usart_v2)))]
1384 #[doc(alias("HDSEL"))] 1384 #[doc(alias("HDSEL"))]
1385 pub fn new_blocking_half_duplex_on_rx<T: Instance>( 1385 pub fn new_blocking_half_duplex_on_rx<T: Instance>(
1386 peri: impl Peripheral<P = T> + 'd, 1386 peri: Peri<'d, T>,
1387 rx: impl Peripheral<P = impl RxPin<T>> + 'd, 1387 rx: Peri<'d, impl RxPin<T>>,
1388 mut config: Config, 1388 mut config: Config,
1389 readback: HalfDuplexReadback, 1389 readback: HalfDuplexReadback,
1390 half_duplex: HalfDuplexConfig, 1390 half_duplex: HalfDuplexConfig,
@@ -1408,12 +1408,12 @@ impl<'d> Uart<'d, Blocking> {
1408 1408
1409impl<'d, M: Mode> Uart<'d, M> { 1409impl<'d, M: Mode> Uart<'d, M> {
1410 fn new_inner<T: Instance>( 1410 fn new_inner<T: Instance>(
1411 _peri: impl Peripheral<P = T> + 'd, 1411 _peri: Peri<'d, T>,
1412 rx: Option<PeripheralRef<'d, AnyPin>>, 1412 rx: Option<Peri<'d, AnyPin>>,
1413 tx: Option<PeripheralRef<'d, AnyPin>>, 1413 tx: Option<Peri<'d, AnyPin>>,
1414 rts: Option<PeripheralRef<'d, AnyPin>>, 1414 rts: Option<Peri<'d, AnyPin>>,
1415 cts: Option<PeripheralRef<'d, AnyPin>>, 1415 cts: Option<Peri<'d, AnyPin>>,
1416 de: Option<PeripheralRef<'d, AnyPin>>, 1416 de: Option<Peri<'d, AnyPin>>,
1417 tx_dma: Option<ChannelAndRequest<'d>>, 1417 tx_dma: Option<ChannelAndRequest<'d>>,
1418 rx_dma: Option<ChannelAndRequest<'d>>, 1418 rx_dma: Option<ChannelAndRequest<'d>>,
1419 config: Config, 1419 config: Config,
@@ -2045,7 +2045,7 @@ pub(crate) trait SealedInstance: crate::rcc::RccPeripheral {
2045 2045
2046/// USART peripheral instance trait. 2046/// USART peripheral instance trait.
2047#[allow(private_bounds)] 2047#[allow(private_bounds)]
2048pub trait Instance: Peripheral<P = Self> + SealedInstance + 'static + Send { 2048pub trait Instance: SealedInstance + PeripheralType + 'static + Send {
2049 /// Interrupt for this peripheral. 2049 /// Interrupt for this peripheral.
2050 type Interrupt: interrupt::typelevel::Interrupt; 2050 type Interrupt: interrupt::typelevel::Interrupt;
2051} 2051}
diff --git a/embassy-stm32/src/usart/ringbuffered.rs b/embassy-stm32/src/usart/ringbuffered.rs
index 69423c940..8e42d5917 100644
--- a/embassy-stm32/src/usart/ringbuffered.rs
+++ b/embassy-stm32/src/usart/ringbuffered.rs
@@ -4,7 +4,6 @@ use core::sync::atomic::{compiler_fence, Ordering};
4use core::task::Poll; 4use core::task::Poll;
5 5
6use embassy_embedded_hal::SetConfig; 6use embassy_embedded_hal::SetConfig;
7use embassy_hal_internal::PeripheralRef;
8use embedded_io_async::ReadReady; 7use embedded_io_async::ReadReady;
9use futures_util::future::{select, Either}; 8use futures_util::future::{select, Either};
10 9
@@ -14,6 +13,7 @@ use crate::gpio::{AnyPin, SealedPin as _};
14use crate::mode::Async; 13use crate::mode::Async;
15use crate::time::Hertz; 14use crate::time::Hertz;
16use crate::usart::Regs; 15use crate::usart::Regs;
16use crate::Peri;
17 17
18/// Rx-only Ring-buffered UART Driver 18/// Rx-only Ring-buffered UART Driver
19/// 19///
@@ -22,8 +22,8 @@ pub struct RingBufferedUartRx<'d> {
22 info: &'static Info, 22 info: &'static Info,
23 state: &'static State, 23 state: &'static State,
24 kernel_clock: Hertz, 24 kernel_clock: Hertz,
25 rx: Option<PeripheralRef<'d, AnyPin>>, 25 rx: Option<Peri<'d, AnyPin>>,
26 rts: Option<PeripheralRef<'d, AnyPin>>, 26 rts: Option<Peri<'d, AnyPin>>,
27 ring_buf: ReadableRingBuffer<'d, u8>, 27 ring_buf: ReadableRingBuffer<'d, u8>,
28} 28}
29 29