From 68778b1135783f374155df4d609737cd3036b027 Mon Sep 17 00:00:00 2001 From: Peter Harper <77111776+peterharperuk@users.noreply.github.com> Date: Mon, 11 Nov 2024 16:09:08 +0000 Subject: [PATCH] Clear i2c abort reason less often. (#2026) It seems to be possible to get stuck in the loop which is checking for abort. It can take 100s of iterations before an abort happens and on each iteration we're clearing the abort interrupt even when it's not required. If we only clear the abort when needed the lockup doesn't seem to be reproducible. Fixes #2025 --- src/rp2_common/hardware_i2c/i2c.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/rp2_common/hardware_i2c/i2c.c b/src/rp2_common/hardware_i2c/i2c.c index 0bf88eb50..e6fc76419 100644 --- a/src/rp2_common/hardware_i2c/i2c.c +++ b/src/rp2_common/hardware_i2c/i2c.c @@ -298,7 +298,10 @@ static int i2c_read_blocking_internal(i2c_inst_t *i2c, uint8_t addr, uint8_t *ds do { abort_reason = i2c->hw->tx_abrt_source; - abort = (bool) i2c->hw->clr_tx_abrt; + if (i2c->hw->raw_intr_stat & I2C_IC_RAW_INTR_STAT_TX_ABRT_BITS) { + abort = true; + i2c->hw->clr_tx_abrt; + } if (timeout_check) { timeout = timeout_check(ts, false); abort |= timeout;