diff options
| author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2022-10-26 10:18:44 +0000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2022-10-26 10:18:44 +0000 |
| commit | 1b249ca72d67a4ff8491b9b548be4afe8c7c2db0 (patch) | |
| tree | d1edd1c57253e56c4e0f1b68fd27a6227e2a4c7c | |
| parent | 71cc6833e11ff37a131db6724d9f05b63f556aa2 (diff) | |
| parent | 66611a80caea216241d58cc3b848fe55b8865b49 (diff) | |
Merge #987
987: (embassy-stm32): uart flowcontrol r=Dirbaio a=MathiasKoch
Add RTS & CTS flow control to stm32 UARTs
Co-authored-by: Mathias <[email protected]>
| -rw-r--r-- | embassy-stm32/src/usart/mod.rs | 41 |
1 files changed, 39 insertions, 2 deletions
diff --git a/embassy-stm32/src/usart/mod.rs b/embassy-stm32/src/usart/mod.rs index a152a0c15..3f5b99523 100644 --- a/embassy-stm32/src/usart/mod.rs +++ b/embassy-stm32/src/usart/mod.rs | |||
| @@ -222,10 +222,48 @@ impl<'d, T: BasicInstance, TxDma, RxDma> Uart<'d, T, TxDma, RxDma> { | |||
| 222 | rx_dma: impl Peripheral<P = RxDma> + 'd, | 222 | rx_dma: impl Peripheral<P = RxDma> + 'd, |
| 223 | config: Config, | 223 | config: Config, |
| 224 | ) -> Self { | 224 | ) -> Self { |
| 225 | into_ref!(_inner, rx, tx, tx_dma, rx_dma); | 225 | T::enable(); |
| 226 | T::reset(); | ||
| 227 | |||
| 228 | Self::new_inner(_inner, rx, tx, tx_dma, rx_dma, config) | ||
| 229 | } | ||
| 230 | |||
| 231 | pub fn new_with_rtscts( | ||
| 232 | _inner: impl Peripheral<P = T> + 'd, | ||
| 233 | rx: impl Peripheral<P = impl RxPin<T>> + 'd, | ||
| 234 | tx: impl Peripheral<P = impl TxPin<T>> + 'd, | ||
| 235 | rts: impl Peripheral<P = impl RtsPin<T>> + 'd, | ||
| 236 | cts: impl Peripheral<P = impl CtsPin<T>> + 'd, | ||
| 237 | tx_dma: impl Peripheral<P = TxDma> + 'd, | ||
| 238 | rx_dma: impl Peripheral<P = RxDma> + 'd, | ||
| 239 | config: Config, | ||
| 240 | ) -> Self { | ||
| 241 | into_ref!(cts, rts); | ||
| 226 | 242 | ||
| 227 | T::enable(); | 243 | T::enable(); |
| 228 | T::reset(); | 244 | T::reset(); |
| 245 | |||
| 246 | unsafe { | ||
| 247 | rts.set_as_af(rts.af_num(), AFType::OutputPushPull); | ||
| 248 | cts.set_as_af(cts.af_num(), AFType::Input); | ||
| 249 | T::regs().cr3().write(|w| { | ||
| 250 | w.set_rtse(true); | ||
| 251 | w.set_ctse(true); | ||
| 252 | }); | ||
| 253 | } | ||
| 254 | Self::new_inner(_inner, rx, tx, tx_dma, rx_dma, config) | ||
| 255 | } | ||
| 256 | |||
| 257 | fn new_inner( | ||
| 258 | _inner: impl Peripheral<P = T> + 'd, | ||
| 259 | rx: impl Peripheral<P = impl RxPin<T>> + 'd, | ||
| 260 | tx: impl Peripheral<P = impl TxPin<T>> + 'd, | ||
| 261 | tx_dma: impl Peripheral<P = TxDma> + 'd, | ||
| 262 | rx_dma: impl Peripheral<P = RxDma> + 'd, | ||
| 263 | config: Config, | ||
| 264 | ) -> Self { | ||
| 265 | into_ref!(_inner, rx, tx, tx_dma, rx_dma); | ||
| 266 | |||
| 229 | let pclk_freq = T::frequency(); | 267 | let pclk_freq = T::frequency(); |
| 230 | 268 | ||
| 231 | // TODO: better calculation, including error checking and OVER8 if possible. | 269 | // TODO: better calculation, including error checking and OVER8 if possible. |
| @@ -238,7 +276,6 @@ impl<'d, T: BasicInstance, TxDma, RxDma> Uart<'d, T, TxDma, RxDma> { | |||
| 238 | tx.set_as_af(tx.af_num(), AFType::OutputPushPull); | 276 | tx.set_as_af(tx.af_num(), AFType::OutputPushPull); |
| 239 | 277 | ||
| 240 | r.cr2().write(|_w| {}); | 278 | r.cr2().write(|_w| {}); |
| 241 | r.cr3().write(|_w| {}); | ||
| 242 | r.brr().write_value(regs::Brr(div)); | 279 | r.brr().write_value(regs::Brr(div)); |
| 243 | r.cr1().write(|w| { | 280 | r.cr1().write(|w| { |
| 244 | w.set_ue(true); | 281 | w.set_ue(true); |
