From 9e8035cfb922d1b85f020e31bee2d3f815ba6f28 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Sun, 16 Jun 2024 11:00:56 +0200 Subject: [PATCH] [USPD] clear interrupt flags right after reception Clearing the interrupt flags at beginning of reception will masks overruns and cause corrupted packets to be received. Instead clear the flags right after disabling the interrupt/after reception, so overruns on the next receive can be caught. Tested by forcing overruns due to explicit sleeps Signed-off-by: Sjoerd Simons --- embassy-stm32/src/ucpd.rs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/embassy-stm32/src/ucpd.rs b/embassy-stm32/src/ucpd.rs index cbec85ff3..40aea75cb 100644 --- a/embassy-stm32/src/ucpd.rs +++ b/embassy-stm32/src/ucpd.rs @@ -347,15 +347,14 @@ impl<'d, T: Instance> PdPhy<'d, T> { .read(r.rxdr().as_ptr() as *mut u8, buf, TransferOptions::default()) }; - // Clear interrupt flags (possibly set from last receive). - r.icr().write(|w| { - w.set_rxorddetcf(true); - w.set_rxovrcf(true); - w.set_rxmsgendcf(true); - }); - let _on_drop = OnDrop::new(|| { Self::enable_rx_interrupt(false); + // Clear interrupt flags + r.icr().write(|w| { + w.set_rxorddetcf(true); + w.set_rxovrcf(true); + w.set_rxmsgendcf(true); + }); }); poll_fn(|cx| {