aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2024-09-10 21:33:27 +0000
committerGitHub <[email protected]>2024-09-10 21:33:27 +0000
commit609b1b0355f36e4ea45e54f0b824a234d41430a5 (patch)
tree2f35773ca34bf24134267f9921beb5f7e0e1a364
parent8f3478193de1efe35b476c1c795fac0ec2374a7c (diff)
parent22f4459ae28fe7e299f775f95952132d3c3dffa2 (diff)
Merge pull request #3286 from trnila/stm32_usart_break
stm32/usart: sending break character
-rw-r--r--embassy-stm32/src/usart/buffered.rs14
-rw-r--r--embassy-stm32/src/usart/mod.rs25
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)))]
13use super::DePin; 13use super::DePin;
14use super::{ 14use 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};
18use crate::gpio::{AfType, AnyPin, OutputType, Pull, SealedPin as _, Speed}; 18use crate::gpio::{AfType, AnyPin, OutputType, Pull, SealedPin as _, Speed};
19use crate::interrupt::{self, InterruptExt}; 19use 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
364impl<'d> BufferedUartRx<'d> { 369impl<'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
543impl<'d> Drop for BufferedUartRx<'d> { 553impl<'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
525fn blocking_flush(info: &Info) -> Result<(), Error> { 530fn 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
543pub 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
537impl<'d> UartRx<'d, Async> { 557impl<'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
1370fn reconfigure(info: &Info, kernel_clock: Hertz, config: &Config) -> Result<(), ConfigError> { 1395fn reconfigure(info: &Info, kernel_clock: Hertz, config: &Config) -> Result<(), ConfigError> {