aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--embassy-stm32/src/usart/mod.rs27
1 files changed, 25 insertions, 2 deletions
diff --git a/embassy-stm32/src/usart/mod.rs b/embassy-stm32/src/usart/mod.rs
index c97efbf0a..ea8e525ea 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,22 @@ 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 // Some chips do not have swap_rx_tx bit
692 tx.set_as_af(tx.af_num(), AFType::OutputPushPull); 698 cfg_if::cfg_if! {
699 if #[cfg(any(usart_v3, usart_v4))] {
700 if config.swap_rx_tx {
701 let (rx, tx) = (tx, rx);
702 rx.set_as_af(rx.af_num(), AFType::Input);
703 tx.set_as_af(tx.af_num(), AFType::OutputPushPull);
704 } else {
705 rx.set_as_af(rx.af_num(), AFType::Input);
706 tx.set_as_af(tx.af_num(), AFType::OutputPushPull);
707 }
708 } else {
709 rx.set_as_af(rx.af_num(), AFType::Input);
710 tx.set_as_af(tx.af_num(), AFType::OutputPushPull);
711 }
712 }
693 713
694 configure(r, &config, T::frequency(), T::KIND, true, true); 714 configure(r, &config, T::frequency(), T::KIND, true, true);
695 715
@@ -847,6 +867,9 @@ fn configure(r: Regs, config: &Config, pclk_freq: Hertz, kind: Kind, enable_rx:
847 StopBits::STOP1P5 => vals::Stop::STOP1P5, 867 StopBits::STOP1P5 => vals::Stop::STOP1P5,
848 StopBits::STOP2 => vals::Stop::STOP2, 868 StopBits::STOP2 => vals::Stop::STOP2,
849 }); 869 });
870
871 #[cfg(any(usart_v3, usart_v4))]
872 w.set_swap(config.swap_rx_tx);
850 }); 873 });
851 r.cr1().write(|w| { 874 r.cr1().write(|w| {
852 // enable uart 875 // enable uart