fix(i2c): reset master before bus clear on chips without HW FSM reset

Reorder s_i2c_hw_fsm_reset() so i2c_ll_reset_register and interrupt
masking run before s_i2c_master_clear_bus(). Avoids ISR firing when
i2c_common_set_pins reconnects GPIOs to a stuck FSM (IDFGH-17497).

Closes https://github.com/espressif/esp-idf/issues/18438

Made-with: Cursor
This commit is contained in:
Chen Chen
2026-04-10 11:21:14 +08:00
parent 6a003df617
commit c513f95ebb
+5 -4
View File
@@ -119,10 +119,7 @@ static esp_err_t s_i2c_hw_fsm_reset(i2c_master_bus_handle_t i2c_master, bool cle
i2c_hal_get_timing_config(hal, &timing_config);
i2c_ll_master_get_filter(hal->dev, &filter_cfg);
//to reset the I2C hw module, we need re-enable the hw
if (clear_bus) {
ret = s_i2c_master_clear_bus(i2c_master->base);
}
// Run bus clear after reset and interrupt masking; reconnecting pins must not wake a stuck FSM.
PERIPH_RCC_ATOMIC() {
i2c_ll_reset_register(i2c_master->base->port_num);
}
@@ -137,6 +134,10 @@ static esp_err_t s_i2c_hw_fsm_reset(i2c_master_bus_handle_t i2c_master, bool cle
i2c_ll_clear_intr_mask(hal->dev, I2C_LL_INTR_MASK);
i2c_hal_set_timing_config(hal, &timing_config);
i2c_ll_master_set_filter(hal->dev, filter_cfg);
if (clear_bus) {
ret = s_i2c_master_clear_bus(i2c_master->base);
}
#else
i2c_ll_master_fsm_rst(hal->dev);
if (clear_bus) {