Skip to content

I2C driver causes watchdog timer reset waiting for stop after nack (IDFGH-16612) #17720

@j9brown

Description

@j9brown

Answers checklist.

  • I have read the documentation ESP-IDF Programming Guide and the issue is not addressed there.
  • I have updated my IDF branch (master or release) to the latest version and checked that the issue is present there.
  • I have searched the issue tracker for a similar issue and not found a similar issue.

IDF version.

v5.4.2

Espressif SoC revision.

ESP32 (revision 100)

Operating System used.

macOS

How did you build your project?

Command line with CMake

If you are using Windows, please specify command line type.

None

Development Kit.

LilyGo T-Relay

Power Supply used.

External 3.3V

What is the expected behavior?

The I2C driver should not cause a watchdog timer reset

What is the actual behavior?

Occasionally, the ESP-IDF I2C driver hangs and triggers a watchdog timer reset while waiting for a STOP to occur after a NACK. When a NACK occurs, s_i2c_send_commands() waits indefinitely for i2c_ll_is_bus_busy() to return false but the I2C FSM is stuck and it never clears so eventually the watchdog timer resets the microcontroller.

The ESP-IDF I2C driver can already recover from several types of I2C bus errors, it just doesn't handle this situation. I suggest adding a timeout to exit the busy-wait loop when the bus is stuck and then call to s_i2c_hw_fsm_reset() and I have prepared a pull-request to illustrate.

Perhaps the root cause is noise on my I2C bus but I haven't been able to isolate it completely yet. Regardless, I think the I2C driver should be able to recover from the transient.

Steps to reproduce.

Sorry, I don't have specific steps to reproduce. It might be possible to simulate the problem by glitching the I2C bus to trigger a NACK without a STOP.

Debug Logs.

[12:23:35]E (1665918) task_wdt: Task watchdog got triggered. The following tasks/users did not reset the watchdog in time:
[12:23:35]E (1665918) task_wdt:  - loopTask (CPU 0)
[12:23:35]E (1665918) task_wdt: Tasks currently running:
[12:23:35]E (1665918) task_wdt: CPU 0: loopTask
[12:23:35]E (1665918) task_wdt: CPU 1: IDLE1
[12:23:35]E (1665918) task_wdt: Aborting.
[12:23:35]E (1665918) task_wdt: Print CPU 0 (current core) backtrace
[12:23:35]Backtrace: 0x4010880d:0x3ffbfa80 0x401089ae:0x3ffbfab0 0x40108a76:0x3ffbfae0 0x401094a7:0x3ffbfb10 0x400df6a5:0x3ffbfbb0 0x4019db17:0x3ffbfc60 0x400df369:0x3ffbfc90 0x400da8a5:0x3ffbfcc0 0x400daac0:0x3ffbfcf0 0x400dea76:0x3ffbfd10 0x400dea86:0x3ffbfd30 0x4019e9a1:0x3ffbfd50 0x400ebcdd:0x3ffbfd70 0x400eb3e9:0x3ffbfd90 0x400eeb76:0x3ffbfdc0 0x400dd052:0x3ffbfde0

0x4010880d: i2c_ll_is_bus_busy at /data/cache/platformio/packages/framework-espidf/components/hal/esp32/include/hal/i2c_ll.h:463
0x4010880d: s_i2c_send_commands at /data/cache/platformio/packages/framework-espidf/components/esp_driver_i2c/i2c_master.c:543
0x401089ae: s_i2c_transaction_start at /data/cache/platformio/packages/framework-espidf/components/esp_driver_i2c/i2c_master.c:649
0x40108a76: s_i2c_synchronous_transaction at /data/cache/platformio/packages/framework-espidf/components/esp_driver_i2c/i2c_master.c:945
0x40108a76: s_i2c_synchronous_transaction at /data/cache/platformio/packages/framework-espidf/components/esp_driver_i2c/i2c_master.c:925
0x401094a7: i2c_master_execute_defined_operations at /data/cache/platformio/packages/framework-espidf/components/esp_driver_i2c/i2c_master.c:1366
0x400df6a5: esphome::i2c::IDFI2CBus::write_readv(unsigned char, unsigned char const*, unsigned int, unsigned char*, unsigned int) at /data/build/van-central/src/esphome/components/i2c/i2c_bus_esp_idf.cpp:173
0x4019db17: esphome::i2c::I2CDevice::read_register(unsigned char, unsigned char*, unsigned int) at /data/build/van-central/src/esphome/components/i2c/i2c.cpp:33
0x400df369: esphome::i2c::I2CRegister::get() const at /data/build/van-central/src/esphome/components/i2c/i2c.cpp:93
0x400da8a5: esphome::aw9523::AW9523Component::digital_read(unsigned char) at /data/build/van-central/src/esphome/components/aw9523/aw9523.cpp:211
0x400daac0: esphome::aw9523::AW9523GPIOPin::digital_read() at /data/build/van-central/src/esphome/components/aw9523/aw9523_gpio_pin.cpp:18
0x400dea76: esphome::gpio::GPIOBinarySensor::loop() at /data/build/van-central/src/esphome/components/gpio/binary_sensor/gpio_binary_sensor.cpp:94
0x400dea86: {virtual override thunk({offset(-48)}, esphome::gpio::GPIOBinarySensor::loop())} at /data/build/van-central/src/esphome/components/gpio/binary_sensor/gpio_binary_sensor.h:58
0x4019e9a1: esphome::Component::call_loop() at /data/build/van-central/src/esphome/core/component.cpp:129
0x400ebcdd: esphome::Component::call() at /data/build/van-central/src/esphome/core/component.cpp:174
0x400eb3e9: esphome::Application::loop() at /data/build/van-central/src/esphome/core/application.cpp:145
0x400eeb76: loop() at /config/esphome/van-central.yaml:947
0x400dd052: esphome::loop_task(void*) at /data/build/van-central/src/esphome/components/esp32/core.cpp:82

Diagnostic report archive.

No response

More Information.

No response

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions