Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

i2c_master: Shorted SDA/SCL lines cause a watchdog timeout (IDFGH-12586) #13587

Closed
3 tasks done
KJ7LNW opened this issue Apr 10, 2024 · 1 comment
Closed
3 tasks done
Assignees
Labels
Resolution: Done Issue is done internally Status: Done Issue is done internally Type: Bug bugs in IDF

Comments

@KJ7LNW
Copy link
Contributor

KJ7LNW commented Apr 10, 2024

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.

5a40bb8

Espressif SoC revision.

ESP32-C6

Operating System used.

Linux

How did you build your project?

Command line with CMake

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

None

Development Kit.

ESP32-WROOM-32

Power Supply used.

USB

What is the expected behavior?

Return a timeout or ESP_ERR_INVALID_STATE when there is a bus failure.

What is the actual behavior?

The device hangs and triggers an ISR WDT

Steps to reproduce.

  1. Continuously sample the I2C bus with i2c_master_transmit_receive
  2. Short the SDA and SCL pins together with a 2.1kOhm resistor. (I know, this is not advised, but we want the product to be as robust as possible).

Debug Logs.

(note: these backtrace lines might be off by a line or two due to debug prints I had added to i2c_master.c)

Guru Meditation Error: Core  0 panic'ed (Interrupt wdt timeout on CPU0). 

Core  0 register dump:
MEPC    : 0x40803702  RA      : 0x408038fe  SP      : 0x4080d240  GP      : 0x4080b8a4  
Stack dump detected
0x40803702: i2c_ll_is_bus_busy at /home/ewheeler/src/esp32/esp-idf/components/hal/esp32c6/include/hal/i2c_ll.h:521
 (inlined by) i2c_isr_receive_handler at /home/ewheeler/src/esp32/esp-idf/components/esp_driver_i2c/i2c_master.c:570
0x408038fe: i2c_master_isr_handler_default at /home/ewheeler/src/esp32/esp-idf/components/esp_driver_i2c/i2c_master.c:631

TP      : 0x40811200  T0      : 0x0000001f  T1      : 0x2000103c  T2      : 0x00000002  
S0/FP   : 0x4081145c  S1      : 0x40811784  A0      : 0x4081145c  A1      : 0x0000000a  
A2      : 0x00000001  A3      : 0x000000c8  A4      : 0x00000001  A5      : 0x4600c011  
A6      : 0x00000004  A7      : 0x00000000  S2      : 0x40811784  S3      : 0x00000001  
S4      : 0x00000000  S5      : 0x00000000  S6      : 0x00000000  S7      : 0x00000000  
S8      : 0x00000000  S9      : 0x00000000  S10     : 0x00000000  S11     : 0x00000000  
T3      : 0x00000000  T4      : 0x00000000  T5      : 0x00000000  T6      : 0x00000000  
MSTATUS : 0x00001881  MTVEC   : 0x40800001  MCAUSE  : 0x00000018  MTVAL   : 0x00008391  
0x40800001: _vector_table at /home/ewheeler/src/esp32/esp-idf/components/riscv/vectors_intc.S:54

MHARTID : 0x00000000  


Backtrace:


0x40803702 in i2c_ll_is_bus_busy (hw=0x0) at /home/ewheeler/src/esp32/esp-idf/components/hal/esp32c6/include/hal/i2c_ll.h:521
521	    return hw->sr.bus_busy;
#0  0x40803702 in i2c_ll_is_bus_busy (hw=0x0) at /home/ewheeler/src/esp32/esp-idf/components/hal/esp32c6/include/hal/i2c_ll.h:521
#1  i2c_isr_receive_handler (i2c_master=i2c_master@entry=0x4081145c) at /home/ewheeler/src/esp32/esp-idf/components/esp_driver_i2c/i2c_master.c:570
#2  0x408038fe in i2c_master_isr_handler_default (arg=0x4081145c) at /home/ewheeler/src/esp32/esp-idf/components/esp_driver_i2c/i2c_master.c:631
#3  0x40800e76 in shared_intr_isr (arg=<optimized out>) at /home/ewheeler/src/esp32/esp-idf/components/esp_hw_support/intr_alloc.c:445
#4  0x4080a1b2 in _global_interrupt_handler (sp=<optimized out>, mcause=<optimized out>) at /home/ewheeler/src/esp32/esp-idf/components/riscv/interrupt.c:90
#5  0x4080026c in _interrupt_handler () at /home/ewheeler/src/esp32/esp-idf/components/riscv/vectors.S:352
Backtrace stopped: previous frame inner to this frame (corrupt stack?)
ELF file SHA256: b48de9005

More Information.

This is caused because the i2c_mater driver busy waits in the ISR. Increasing CONFIG_ESP_INT_WDT_TIMEOUT_MS will delay the watchdog trigger, but of course that is not a fix.

IRAM_ATTR static void i2c_isr_receive_handler(i2c_master_bus_t *i2c_master)
{
i2c_hal_context_t *hal = &i2c_master->base->hal;
while (i2c_ll_is_bus_busy(hal->dev)) {}

Suggestion:

Do not spin forever. Ideally this code would:

  1. spin for only CONFIG_ESP_INT_WDT_TIMEOUT_MS / 2
  2. exit the ISR
  3. set i2c_master->status to ESP_ERR_INVALID_STATE, and
  4. abort the transaction

I started to workup a patch for this, but I'm not sure how to check the ESP32 equivalent of a "time-step-counter" in an interrupt context.

Is there a way?

@KJ7LNW KJ7LNW added the Type: Bug bugs in IDF label Apr 10, 2024
@KJ7LNW KJ7LNW changed the title Shorted SDA/SCL lines cause a watchdog timeout i2c: Shorted SDA/SCL lines cause a watchdog timeout Apr 10, 2024
@KJ7LNW KJ7LNW changed the title i2c: Shorted SDA/SCL lines cause a watchdog timeout i2c_master: Shorted SDA/SCL lines cause a watchdog timeout Apr 10, 2024
@espressif-bot espressif-bot added the Status: Opened Issue is new label Apr 10, 2024
@github-actions github-actions bot changed the title i2c_master: Shorted SDA/SCL lines cause a watchdog timeout i2c_master: Shorted SDA/SCL lines cause a watchdog timeout (IDFGH-12586) Apr 10, 2024
@mythbuster5
Copy link
Collaborator

Actually, For synchronous transaction, this line can be removed. For shout cut situation. Timeout interrupt can handle this properly. I will provide a quick fix.

@espressif-bot espressif-bot added Status: Done Issue is done internally Resolution: Done Issue is done internally and removed Status: Opened Issue is new labels Apr 29, 2024
espressif-bot pushed a commit that referenced this issue Jul 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution: Done Issue is done internally Status: Done Issue is done internally Type: Bug bugs in IDF
Projects
None yet
Development

No branches or pull requests

3 participants