From 4118f4f72d7983063490cc1981aced0273df602d Mon Sep 17 00:00:00 2001 From: Chen Chen Date: Mon, 7 Sep 2026 16:13:43 +0800 Subject: [PATCH] fix(i2c): fixed potential multi-core race in I2C read Closes https://github.com/espressif/esp-idf/issues/19050 --- components/esp_driver_i2c/i2c_master.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/components/esp_driver_i2c/i2c_master.c b/components/esp_driver_i2c/i2c_master.c index 8c6c56b7697..ce938b27e6a 100644 --- a/components/esp_driver_i2c/i2c_master.c +++ b/components/esp_driver_i2c/i2c_master.c @@ -805,14 +805,15 @@ static void i2c_master_isr_handler_default(void *arg) i2c_master->trans_done = true; i2c_master->event = I2C_EVENT_DONE; } - if (i2c_master->event != I2C_EVENT_ALIVE) { - xQueueSendFromISR(i2c_master->event_queue, (void *)&i2c_master->event, &HPTaskAwoken); - } if (i2c_master->contains_read == true) { if (int_mask & I2C_LL_INTR_MST_COMPLETE || int_mask & I2C_LL_INTR_END_DETECT) { i2c_isr_receive_handler(i2c_master); } } + /* Wait for the ISR to finish copying RX FIFO before notifying the waiter so the caller's buffer is complete */ + if (i2c_master->event != I2C_EVENT_ALIVE) { + xQueueSendFromISR(i2c_master->event_queue, (void *)&i2c_master->event, &HPTaskAwoken); + } if (i2c_master->async_trans) { i2c_master_dev_handle_t i2c_dev = NULL;