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.
This commit is contained in:
Timo Kröger 2021-01-02 22:40:36 +01:00
parent 39ca8b8ded
commit 9f28c7ab8d

View File

@ -313,7 +313,7 @@ where
{
fn drop(self: &mut Self) {
if self.uarte.rx_started() {
trace!("stoprx");
trace!("stoprx (drop)");
self.uarte.instance.events_rxstarted.reset();
self.uarte
@ -364,9 +364,20 @@ where
T: Instance,
{
/// Stops the ongoing reception and returns the number of bytes received.
pub async fn stop(self) -> usize {
drop(self);
let len = T::state().rx_done.wait().await;
pub async fn stop(mut self) -> usize {
let len = if self.uarte.rx_started() {
trace!("stoprx (stop)");
self.uarte.instance.events_rxstarted.reset();
self.uarte
.instance
.tasks_stoprx
.write(|w| unsafe { w.bits(1) });
T::state().rx_done.wait().await
} else {
// Transfer was stopped before it even started. No bytes were sent.
0
};
len as _
}
}