aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--embassy-stm32/src/usart/mod.rs25
1 files changed, 23 insertions, 2 deletions
diff --git a/embassy-stm32/src/usart/mod.rs b/embassy-stm32/src/usart/mod.rs
index c97efbf0a..1ba182e21 100644
--- a/embassy-stm32/src/usart/mod.rs
+++ b/embassy-stm32/src/usart/mod.rs
@@ -116,6 +116,10 @@ pub struct Config {
116 /// but will effectively disable noise detection. 116 /// but will effectively disable noise detection.
117 #[cfg(not(usart_v1))] 117 #[cfg(not(usart_v1))]
118 pub assume_noise_free: bool, 118 pub assume_noise_free: bool,
119
120 /// Set this to true to swap the RX and TX pins.
121 #[cfg(any(usart_v3, usart_v4))]
122 pub swap_rx_tx: bool,
119} 123}
120 124
121impl Default for Config { 125impl Default for Config {
@@ -129,6 +133,8 @@ impl Default for Config {
129 detect_previous_overrun: false, 133 detect_previous_overrun: false,
130 #[cfg(not(usart_v1))] 134 #[cfg(not(usart_v1))]
131 assume_noise_free: false, 135 assume_noise_free: false,
136 #[cfg(any(usart_v3, usart_v4))]
137 swap_rx_tx: false,
132 } 138 }
133 } 139 }
134} 140}
@@ -688,8 +694,20 @@ impl<'d, T: BasicInstance, TxDma, RxDma> Uart<'d, T, TxDma, RxDma> {
688 694
689 let r = T::regs(); 695 let r = T::regs();
690 696
691 rx.set_as_af(rx.af_num(), AFType::Input); 697 #[allow(unused_variables)]
692 tx.set_as_af(tx.af_num(), AFType::OutputPushPull); 698 let swap_rx_tx = false;
699
700 #[cfg(any(usart_v3, usart_v4))]
701 let swap_rx_tx = config.swap_rx_tx;
702
703 if swap_rx_tx {
704 let (rx, tx) = (tx, rx);
705 rx.set_as_af(rx.af_num(), AFType::Input);
706 tx.set_as_af(tx.af_num(), AFType::OutputPushPull);
707 } else {
708 rx.set_as_af(rx.af_num(), AFType::Input);
709 tx.set_as_af(tx.af_num(), AFType::OutputPushPull);
710 }
693 711
694 configure(r, &config, T::frequency(), T::KIND, true, true); 712 configure(r, &config, T::frequency(), T::KIND, true, true);
695 713
@@ -847,6 +865,9 @@ fn configure(r: Regs, config: &Config, pclk_freq: Hertz, kind: Kind, enable_rx:
847 StopBits::STOP1P5 => vals::Stop::STOP1P5, 865 StopBits::STOP1P5 => vals::Stop::STOP1P5,
848 StopBits::STOP2 => vals::Stop::STOP2, 866 StopBits::STOP2 => vals::Stop::STOP2,
849 }); 867 });
868
869 #[cfg(any(usart_v3, usart_v4))]
870 w.set_swap(config.swap_rx_tx);
850 }); 871 });
851 r.cr1().write(|w| { 872 r.cr1().write(|w| {
852 // enable uart 873 // enable uart