From c0addc005bb3859436cb1c2931b41a7065703077 Mon Sep 17 00:00:00 2001 From: Lucas Martins Date: Mon, 21 Oct 2024 14:48:57 -0300 Subject: [PATCH 1/3] add uart permutations usefull for rs485 --- embassy-stm32/src/usart/buffered.rs | 49 +++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/embassy-stm32/src/usart/buffered.rs b/embassy-stm32/src/usart/buffered.rs index 4fbe33b2e..03c0934f9 100644 --- a/embassy-stm32/src/usart/buffered.rs +++ b/embassy-stm32/src/usart/buffered.rs @@ -246,6 +246,55 @@ impl<'d> BufferedUart<'d> { ) } + + /// Create a new bidirectional buffered UART driver with only RTS pin as the DE pin + pub fn new_with_rts_as_de( + peri: impl Peripheral

+ 'd, + _irq: impl interrupt::typelevel::Binding> + 'd, + rx: impl Peripheral

> + 'd, + tx: impl Peripheral

> + 'd, + rts: impl Peripheral

> + 'd, + tx_buffer: &'d mut [u8], + rx_buffer: &'d mut [u8], + config: Config, + ) -> Result { + Self::new_inner( + peri, + new_pin!(rx, AfType::input(Pull::None)), + new_pin!(tx, AfType::output(OutputType::PushPull, Speed::Medium)), + None, + None, + new_pin!(rts, AfType::input(Pull::None)), // RTS mapped used as DE + tx_buffer, + rx_buffer, + config, + ) + } + + /// Create a new bidirectional buffered UART driver with only the request-to-send pin + pub fn new_with_rts( + peri: impl Peripheral

+ 'd, + _irq: impl interrupt::typelevel::Binding> + 'd, + rx: impl Peripheral

> + 'd, + tx: impl Peripheral

> + 'd, + rts: impl Peripheral

> + 'd, + tx_buffer: &'d mut [u8], + rx_buffer: &'d mut [u8], + config: Config, + ) -> Result { + Self::new_inner( + peri, + new_pin!(rx, AfType::input(Pull::None)), + new_pin!(tx, AfType::output(OutputType::PushPull, Speed::Medium)), + new_pin!(rts, AfType::input(Pull::None)), + None, // no RTS + None, // no DE + tx_buffer, + rx_buffer, + config, + ) + } + /// Create a new bidirectional buffered UART driver with a driver-enable pin #[cfg(not(any(usart_v1, usart_v2)))] pub fn new_with_de( From 2c9b528edde491ca1ed02234805212c78e2a6bd7 Mon Sep 17 00:00:00 2001 From: Lucas Martins Date: Mon, 21 Oct 2024 15:06:06 -0300 Subject: [PATCH 2/3] fmt --- embassy-stm32/src/usart/buffered.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/embassy-stm32/src/usart/buffered.rs b/embassy-stm32/src/usart/buffered.rs index 03c0934f9..edaf41be9 100644 --- a/embassy-stm32/src/usart/buffered.rs +++ b/embassy-stm32/src/usart/buffered.rs @@ -246,7 +246,6 @@ impl<'d> BufferedUart<'d> { ) } - /// Create a new bidirectional buffered UART driver with only RTS pin as the DE pin pub fn new_with_rts_as_de( peri: impl Peripheral

+ 'd, From 82772e3a8f36b31052ca46af3947ba253458bef1 Mon Sep 17 00:00:00 2001 From: Lucas Martins Date: Mon, 21 Oct 2024 17:50:05 -0300 Subject: [PATCH 3/3] :memo: fix wrong comment --- embassy-stm32/src/usart/buffered.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/embassy-stm32/src/usart/buffered.rs b/embassy-stm32/src/usart/buffered.rs index edaf41be9..7ba209063 100644 --- a/embassy-stm32/src/usart/buffered.rs +++ b/embassy-stm32/src/usart/buffered.rs @@ -246,7 +246,7 @@ impl<'d> BufferedUart<'d> { ) } - /// Create a new bidirectional buffered UART driver with only RTS pin as the DE pin + /// Create a new bidirectional buffered UART driver with only the RTS pin as the DE pin pub fn new_with_rts_as_de( peri: impl Peripheral

+ 'd, _irq: impl interrupt::typelevel::Binding> + 'd, @@ -286,7 +286,7 @@ impl<'d> BufferedUart<'d> { new_pin!(rx, AfType::input(Pull::None)), new_pin!(tx, AfType::output(OutputType::PushPull, Speed::Medium)), new_pin!(rts, AfType::input(Pull::None)), - None, // no RTS + None, // no CTS None, // no DE tx_buffer, rx_buffer,