From ae669c7049b945de8e9d06af53e2f73aa8c30c8b Mon Sep 17 00:00:00 2001 From: DatanoiseTV <6614616+DatanoiseTV@users.noreply.github.com> Date: Sat, 9 May 2026 04:35:07 +0200 Subject: [PATCH] fix(i2c_master): yield from ISR when no matching device is found `i2c_master_isr_handler_default()` may set HPTaskAwoken to pdTRUE via `xQueueSendFromISR()` (event_queue), `xSemaphoreTakeFromISR()` and `xSemaphoreGiveFromISR()` on `bus_lock_mux`. When the device list lookup returns no matching device, the function returned directly, skipping the `portYIELD_FROM_ISR()` at the bottom of the handler. A higher- priority task waiting on the bus mux or the event queue would then have to wait for the next scheduler tick instead of being preempted into immediately, inflating worst-case event latency. Replace the early return with a goto to the existing yield check at the end of the ISR. Merges https://github.com/espressif/esp-idf/pull/18569 --- components/esp_driver_i2c/i2c_master.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/components/esp_driver_i2c/i2c_master.c b/components/esp_driver_i2c/i2c_master.c index 82dd74b1ad7..d8a782277c4 100644 --- a/components/esp_driver_i2c/i2c_master.c +++ b/components/esp_driver_i2c/i2c_master.c @@ -827,7 +827,10 @@ static void i2c_master_isr_handler_default(void *arg) } xSemaphoreGiveFromISR(i2c_master->bus_lock_mux, &HPTaskAwoken); if (i2c_dev == NULL) { - return; + // HPTaskAwoken may have been set by xQueueSendFromISR / xSemaphoreTakeFromISR / + // xSemaphoreGiveFromISR above; fall through to the yield check at the end of + // the ISR rather than returning directly. + goto out; } i2c_master_event_data_t evt = { .event = i2c_master->event, @@ -865,6 +868,7 @@ static void i2c_master_isr_handler_default(void *arg) xSemaphoreGiveFromISR(i2c_master->cmd_semphr, &HPTaskAwoken); } +out: if (HPTaskAwoken == pdTRUE) { portYIELD_FROM_ISR(); }