aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimo Kröger <[email protected]>2021-01-02 22:40:36 +0100
committerTimo Kröger <[email protected]>2021-01-04 22:55:40 +0100
commit9f28c7ab8d96d19a010246318dee1de73b3ed4ee (patch)
tree3758a6a685e596c929100c111f972ef79d25e792
parent39ca8b8dedb3db14f9770f09814ccf92481b6136 (diff)
uarte: Do not spin when stopping a receive future
Spinning on drop() is still required when the future has not been stopped so that DMA finishes before the buffer is released.
-rw-r--r--embassy-nrf/src/uarte.rs19
1 files changed, 15 insertions, 4 deletions
diff --git a/embassy-nrf/src/uarte.rs b/embassy-nrf/src/uarte.rs
index 648298b84..494b92df3 100644
--- a/embassy-nrf/src/uarte.rs
+++ b/embassy-nrf/src/uarte.rs
@@ -313,7 +313,7 @@ where
313{ 313{
314 fn drop(self: &mut Self) { 314 fn drop(self: &mut Self) {
315 if self.uarte.rx_started() { 315 if self.uarte.rx_started() {
316 trace!("stoprx"); 316 trace!("stoprx (drop)");
317 317
318 self.uarte.instance.events_rxstarted.reset(); 318 self.uarte.instance.events_rxstarted.reset();
319 self.uarte 319 self.uarte
@@ -364,9 +364,20 @@ where
364 T: Instance, 364 T: Instance,
365{ 365{
366 /// Stops the ongoing reception and returns the number of bytes received. 366 /// Stops the ongoing reception and returns the number of bytes received.
367 pub async fn stop(self) -> usize { 367 pub async fn stop(mut self) -> usize {
368 drop(self); 368 let len = if self.uarte.rx_started() {
369 let len = T::state().rx_done.wait().await; 369 trace!("stoprx (stop)");
370
371 self.uarte.instance.events_rxstarted.reset();
372 self.uarte
373 .instance
374 .tasks_stoprx
375 .write(|w| unsafe { w.bits(1) });
376 T::state().rx_done.wait().await
377 } else {
378 // Transfer was stopped before it even started. No bytes were sent.
379 0
380 };
370 len as _ 381 len as _
371 } 382 }
372} 383}