From 64b80c2e4d390b16a384e197f1c7ed2a9a6fc946 Mon Sep 17 00:00:00 2001 From: xoviat Date: Wed, 19 Apr 2023 16:16:44 -0500 Subject: [PATCH] stm32/i2c: ignore wakes without interrupt --- embassy-stm32/src/i2c/v2.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/embassy-stm32/src/i2c/v2.rs b/embassy-stm32/src/i2c/v2.rs index 44237b890..92fc05591 100644 --- a/embassy-stm32/src/i2c/v2.rs +++ b/embassy-stm32/src/i2c/v2.rs @@ -485,6 +485,7 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> { poll_fn(|cx| { state.waker.register(cx.waker()); + let isr = unsafe { T::regs().isr().read() }; if remaining_len == total_len { // NOTE(unsafe) self.tx_dma does not fiddle with the i2c registers if first_slice { @@ -503,6 +504,9 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> { T::regs().cr1().modify(|w| w.set_tcie(true)); } } + } else if !(isr.tcr() || isr.tc()) { + // poll_fn was woken without an interrupt present + return Poll::Pending; } else if remaining_len == 0 { return Poll::Ready(Ok(())); } else { @@ -575,6 +579,8 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> { poll_fn(|cx| { state.waker.register(cx.waker()); + + let isr = unsafe { T::regs().isr().read() }; if remaining_len == total_len { // NOTE(unsafe) self.rx_dma does not fiddle with the i2c registers unsafe { @@ -587,6 +593,9 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> { &check_timeout, )?; } + } else if !(isr.tcr() || isr.tc()) { + // poll_fn was woken without an interrupt present + return Poll::Pending; } else if remaining_len == 0 { return Poll::Ready(Ok(())); } else {