diff --git a/embassy-stm32/build.rs b/embassy-stm32/build.rs index a4709f4c..ddfa97b2 100644 --- a/embassy-stm32/build.rs +++ b/embassy-stm32/build.rs @@ -244,11 +244,13 @@ fn main() { (("usart", "CTS"), quote!(crate::usart::CtsPin)), (("usart", "RTS"), quote!(crate::usart::RtsPin)), (("usart", "CK"), quote!(crate::usart::CkPin)), + (("usart", "DE"), quote!(crate::usart::DePin)), (("lpuart", "TX"), quote!(crate::usart::TxPin)), (("lpuart", "RX"), quote!(crate::usart::RxPin)), (("lpuart", "CTS"), quote!(crate::usart::CtsPin)), (("lpuart", "RTS"), quote!(crate::usart::RtsPin)), (("lpuart", "CK"), quote!(crate::usart::CkPin)), + (("lpuart", "DE"), quote!(crate::usart::DePin)), (("spi", "SCK"), quote!(crate::spi::SckPin)), (("spi", "MOSI"), quote!(crate::spi::MosiPin)), (("spi", "MISO"), quote!(crate::spi::MisoPin)), diff --git a/embassy-stm32/src/usart/buffered.rs b/embassy-stm32/src/usart/buffered.rs index d024bedc..874af1d7 100644 --- a/embassy-stm32/src/usart/buffered.rs +++ b/embassy-stm32/src/usart/buffered.rs @@ -89,6 +89,33 @@ impl<'d, T: BasicInstance> BufferedUart<'d, T> { Self::new_inner(state, peri, rx, tx, irq, tx_buffer, rx_buffer, config) } + #[cfg(not(usart_v1))] + pub fn new_with_de( + state: &'d mut State<'d, T>, + peri: impl Peripheral
+ 'd, + rx: impl Peripheral
> + 'd, + tx: impl Peripheral
> + 'd, + irq: impl Peripheral
+ 'd, + de: impl Peripheral
> + 'd, + tx_buffer: &'d mut [u8], + rx_buffer: &'d mut [u8], + config: Config, + ) -> BufferedUart<'d, T> { + into_ref!(de); + + T::enable(); + T::reset(); + + unsafe { + de.set_as_af(de.af_num(), AFType::OutputPushPull); + T::regs().cr3().write(|w| { + w.set_dem(true); + }); + } + + Self::new_inner(state, peri, rx, tx, irq, tx_buffer, rx_buffer, config) + } + fn new_inner( state: &'d mut State<'d, T>, _peri: impl Peripheral
+ 'd, diff --git a/embassy-stm32/src/usart/mod.rs b/embassy-stm32/src/usart/mod.rs index aea054a4..ea75361f 100644 --- a/embassy-stm32/src/usart/mod.rs +++ b/embassy-stm32/src/usart/mod.rs @@ -646,6 +646,31 @@ impl<'d, T: BasicInstance, TxDma, RxDma> Uart<'d, T, TxDma, RxDma> { Self::new_inner(peri, rx, tx, irq, tx_dma, rx_dma, config) } + #[cfg(not(usart_v1))] + pub fn new_with_de( + peri: impl Peripheral
+ 'd, + rx: impl Peripheral
> + 'd, + tx: impl Peripheral
> + 'd, + irq: impl Peripheral
+ 'd, + de: impl Peripheral
> + 'd, + tx_dma: impl Peripheral
+ 'd, + rx_dma: impl Peripheral
+ 'd, + config: Config, + ) -> Self { + into_ref!(de); + + T::enable(); + T::reset(); + + unsafe { + de.set_as_af(de.af_num(), AFType::OutputPushPull); + T::regs().cr3().write(|w| { + w.set_dem(true); + }); + } + Self::new_inner(peri, rx, tx, irq, tx_dma, rx_dma, config) + } + fn new_inner( peri: impl Peripheral
+ 'd, rx: impl Peripheral
> + 'd, @@ -1040,6 +1065,7 @@ pin_trait!(TxPin, BasicInstance); pin_trait!(CtsPin, BasicInstance); pin_trait!(RtsPin, BasicInstance); pin_trait!(CkPin, BasicInstance); +pin_trait!(DePin, BasicInstance); dma_trait!(TxDma, BasicInstance); dma_trait!(RxDma, BasicInstance);