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:
parent
39ca8b8ded
commit
9f28c7ab8d
@ -313,7 +313,7 @@ where
|
|||||||
{
|
{
|
||||||
fn drop(self: &mut Self) {
|
fn drop(self: &mut Self) {
|
||||||
if self.uarte.rx_started() {
|
if self.uarte.rx_started() {
|
||||||
trace!("stoprx");
|
trace!("stoprx (drop)");
|
||||||
|
|
||||||
self.uarte.instance.events_rxstarted.reset();
|
self.uarte.instance.events_rxstarted.reset();
|
||||||
self.uarte
|
self.uarte
|
||||||
@ -364,9 +364,20 @@ where
|
|||||||
T: Instance,
|
T: Instance,
|
||||||
{
|
{
|
||||||
/// Stops the ongoing reception and returns the number of bytes received.
|
/// Stops the ongoing reception and returns the number of bytes received.
|
||||||
pub async fn stop(self) -> usize {
|
pub async fn stop(mut self) -> usize {
|
||||||
drop(self);
|
let len = if self.uarte.rx_started() {
|
||||||
let len = T::state().rx_done.wait().await;
|
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 _
|
len as _
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user