diff options
| -rw-r--r-- | embassy-stm32/src/usart/buffered.rs | 14 | ||||
| -rw-r--r-- | embassy-stm32/src/usart/mod.rs | 25 |
2 files changed, 37 insertions, 2 deletions
diff --git a/embassy-stm32/src/usart/buffered.rs b/embassy-stm32/src/usart/buffered.rs index 06cc0e41d..86f56eb7c 100644 --- a/embassy-stm32/src/usart/buffered.rs +++ b/embassy-stm32/src/usart/buffered.rs | |||
| @@ -12,8 +12,8 @@ use embassy_sync::waitqueue::AtomicWaker; | |||
| 12 | #[cfg(not(any(usart_v1, usart_v2)))] | 12 | #[cfg(not(any(usart_v1, usart_v2)))] |
| 13 | use super::DePin; | 13 | use super::DePin; |
| 14 | use super::{ | 14 | use super::{ |
| 15 | clear_interrupt_flags, configure, rdr, reconfigure, sr, tdr, Config, ConfigError, CtsPin, Error, Info, Instance, | 15 | clear_interrupt_flags, configure, rdr, reconfigure, send_break, sr, tdr, Config, ConfigError, CtsPin, Error, Info, |
| 16 | Regs, RtsPin, RxPin, TxPin, | 16 | Instance, Regs, RtsPin, RxPin, TxPin, |
| 17 | }; | 17 | }; |
| 18 | use crate::gpio::{AfType, AnyPin, OutputType, Pull, SealedPin as _, Speed}; | 18 | use crate::gpio::{AfType, AnyPin, OutputType, Pull, SealedPin as _, Speed}; |
| 19 | use crate::interrupt::{self, InterruptExt}; | 19 | use crate::interrupt::{self, InterruptExt}; |
| @@ -359,6 +359,11 @@ impl<'d> BufferedUart<'d> { | |||
| 359 | 359 | ||
| 360 | Ok(()) | 360 | Ok(()) |
| 361 | } | 361 | } |
| 362 | |||
| 363 | /// Send break character | ||
| 364 | pub fn send_break(&self) { | ||
| 365 | self.tx.send_break() | ||
| 366 | } | ||
| 362 | } | 367 | } |
| 363 | 368 | ||
| 364 | impl<'d> BufferedUartRx<'d> { | 369 | impl<'d> BufferedUartRx<'d> { |
| @@ -538,6 +543,11 @@ impl<'d> BufferedUartTx<'d> { | |||
| 538 | 543 | ||
| 539 | Ok(()) | 544 | Ok(()) |
| 540 | } | 545 | } |
| 546 | |||
| 547 | /// Send break character | ||
| 548 | pub fn send_break(&self) { | ||
| 549 | send_break(&self.info.regs); | ||
| 550 | } | ||
| 541 | } | 551 | } |
| 542 | 552 | ||
| 543 | impl<'d> Drop for BufferedUartRx<'d> { | 553 | impl<'d> Drop for BufferedUartRx<'d> { |
diff --git a/embassy-stm32/src/usart/mod.rs b/embassy-stm32/src/usart/mod.rs index 89d92dda2..e7f2f890a 100644 --- a/embassy-stm32/src/usart/mod.rs +++ b/embassy-stm32/src/usart/mod.rs | |||
| @@ -520,6 +520,11 @@ impl<'d, M: Mode> UartTx<'d, M> { | |||
| 520 | pub fn blocking_flush(&mut self) -> Result<(), Error> { | 520 | pub fn blocking_flush(&mut self) -> Result<(), Error> { |
| 521 | blocking_flush(self.info) | 521 | blocking_flush(self.info) |
| 522 | } | 522 | } |
| 523 | |||
| 524 | /// Send break character | ||
| 525 | pub fn send_break(&self) { | ||
| 526 | send_break(&self.info.regs); | ||
| 527 | } | ||
| 523 | } | 528 | } |
| 524 | 529 | ||
| 525 | fn blocking_flush(info: &Info) -> Result<(), Error> { | 530 | fn blocking_flush(info: &Info) -> Result<(), Error> { |
| @@ -534,6 +539,21 @@ fn blocking_flush(info: &Info) -> Result<(), Error> { | |||
| 534 | Ok(()) | 539 | Ok(()) |
| 535 | } | 540 | } |
| 536 | 541 | ||
| 542 | /// Send break character | ||
| 543 | pub fn send_break(regs: &Regs) { | ||
| 544 | // Busy wait until previous break has been sent | ||
| 545 | #[cfg(any(usart_v1, usart_v2))] | ||
| 546 | while regs.cr1().read().sbk() {} | ||
| 547 | #[cfg(any(usart_v3, usart_v4))] | ||
| 548 | while regs.isr().read().sbkf() {} | ||
| 549 | |||
| 550 | // Send break right after completing the current character transmission | ||
| 551 | #[cfg(any(usart_v1, usart_v2))] | ||
| 552 | regs.cr1().modify(|w| w.set_sbk(true)); | ||
| 553 | #[cfg(any(usart_v3, usart_v4))] | ||
| 554 | regs.rqr().write(|w| w.set_sbkrq(true)); | ||
| 555 | } | ||
| 556 | |||
| 537 | impl<'d> UartRx<'d, Async> { | 557 | impl<'d> UartRx<'d, Async> { |
| 538 | /// Create a new rx-only UART with no hardware flow control. | 558 | /// Create a new rx-only UART with no hardware flow control. |
| 539 | /// | 559 | /// |
| @@ -1365,6 +1385,11 @@ impl<'d, M: Mode> Uart<'d, M> { | |||
| 1365 | pub fn split(self) -> (UartTx<'d, M>, UartRx<'d, M>) { | 1385 | pub fn split(self) -> (UartTx<'d, M>, UartRx<'d, M>) { |
| 1366 | (self.tx, self.rx) | 1386 | (self.tx, self.rx) |
| 1367 | } | 1387 | } |
| 1388 | |||
| 1389 | /// Send break character | ||
| 1390 | pub fn send_break(&self) { | ||
| 1391 | self.tx.send_break(); | ||
| 1392 | } | ||
| 1368 | } | 1393 | } |
| 1369 | 1394 | ||
| 1370 | fn reconfigure(info: &Info, kernel_clock: Hertz, config: &Config) -> Result<(), ConfigError> { | 1395 | fn reconfigure(info: &Info, kernel_clock: Hertz, config: &Config) -> Result<(), ConfigError> { |
