aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndres Vahter <[email protected]>2024-01-09 09:25:10 +0200
committerDario Nieuwenhuis <[email protected]>2024-01-20 00:15:39 +0100
commit17d6e4eefeb9bdc9d7c3776afb815298be5b468c (patch)
tree370d32a9f834d587866958a87e91c0a0d14826be
parentec47e931acbc4a4b1a9f0781e9317f1e680427eb (diff)
stm32 uart: do not wake after sending each byte
usart_v4 uses TC interrupt to see if all bytes are sent out from the FIFO and waker is called from this interrupt. This minimises unnecessary wakeups during sending.
-rw-r--r--embassy-stm32/src/usart/buffered.rs9
1 files changed, 6 insertions, 3 deletions
diff --git a/embassy-stm32/src/usart/buffered.rs b/embassy-stm32/src/usart/buffered.rs
index e050f8e0f..211091c38 100644
--- a/embassy-stm32/src/usart/buffered.rs
+++ b/embassy-stm32/src/usart/buffered.rs
@@ -62,8 +62,8 @@ impl<T: BasicInstance> interrupt::typelevel::Handler<T::Interrupt> for Interrupt
62 state.rx_waker.wake(); 62 state.rx_waker.wake();
63 } 63 }
64 64
65 // With `usart_v4` hardware FIFO is enabled, making `state.tx_buf` 65 // With `usart_v4` hardware FIFO is enabled, making `state.tx_buf` insufficient
66 // insufficient to determine if all bytes are sent out. 66 // to determine if all bytes are sent out.
67 // Transmission complete (TC) interrupt here indicates that all bytes are pushed out from the FIFO. 67 // Transmission complete (TC) interrupt here indicates that all bytes are pushed out from the FIFO.
68 #[cfg(usart_v4)] 68 #[cfg(usart_v4)]
69 if sr_val.tc() { 69 if sr_val.tc() {
@@ -90,9 +90,12 @@ impl<T: BasicInstance> interrupt::typelevel::Handler<T::Interrupt> for Interrupt
90 90
91 tdr(r).write_volatile(buf[0].into()); 91 tdr(r).write_volatile(buf[0].into());
92 tx_reader.pop_done(1); 92 tx_reader.pop_done(1);
93
94 // Notice that in case of `usart_v4` waker is called when TC interrupt happens.
95 #[cfg(not(usart_v4))]
93 state.tx_waker.wake(); 96 state.tx_waker.wake();
94 } else { 97 } else {
95 // Disable interrupt until we have something to transmit again 98 // Disable interrupt until we have something to transmit again.
96 r.cr1().modify(|w| { 99 r.cr1().modify(|w| {
97 w.set_txeie(false); 100 w.set_txeie(false);
98 }); 101 });