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

esp32c3 i2c will cause cpu IDLE (IDFGH-6463) #8120

Closed
3 tasks
FanhuaCloud opened this issue Dec 21, 2021 · 14 comments
Closed
3 tasks

esp32c3 i2c will cause cpu IDLE (IDFGH-6463) #8120

FanhuaCloud opened this issue Dec 21, 2021 · 14 comments
Labels
Resolution: Done Issue is done internally Status: Done Issue is done internally

Comments

@FanhuaCloud
Copy link
Contributor

Environment

  • Development Kit: none
  • Module or chip used: esp32-c3
  • IDF version (run git describe --tags to find it):
    // ESP-IDF v5.0-dev-797-g279c8aeb8a
  • Build System: idf.py
  • Compiler version (run xtensa-esp32-elf-gcc --version to find it):
    // riscv32-esp-elf-gcc-8.4.0.exe (crosstool-NG esp-2021r2) 8.4.0
  • Operating System: Windows
  • (Windows only) environment type: ESP Command Prompt
  • Using an IDE?: Yes vscode esp-idf
  • Power Supply: USB

Problem Description

When using i2c, there is a chance that the cpu will be idle
I think it might be because the i2c code took too long
//Detailed problem description goes here.

Expected Behavior

Actual Behavior

E (6907) task_wdt: Task watchdog got triggered. The following tasks did not reset the watchdog in time:
E (6907) task_wdt: - IDLE (CPU 0)
E (6907) task_wdt: Tasks currently running:
E (6907) task_wdt: CPU 0: main

Steps to reproduce

  1. step1
  2. ...

// If possible, attach a picture of your setup/wiring here.

Code to reproduce this issue

        i2c_cmd_handle_t cmd = i2c_cmd_link_create();
        i2c_master_start(cmd);
        i2c_master_write_byte(cmd, AHT_I2C_ADDRESS_GND << 1 | I2C_MASTER_READ, true);
        i2c_master_read(cmd, data, 6, I2C_MASTER_ACK);
        i2c_master_stop(cmd);
        i2c_master_cmd_begin(I2C_NUM_0, cmd, 1000 / portTICK_PERIOD_MS);
        i2c_cmd_link_delete(cmd);

// If your code is longer than 30 lines, GIST is preferred.

Debug Logs

Debug log goes here, should contain the backtrace, as well as the reset source if it is a crash.
Please copy the plain text here for us to search the error log. Or attach the complete logs but leave the main part here if the log is *too* long.

Other items if possible

  • sdkconfig file (attach the sdkconfig file from your project folder)
  • elf file in the build folder (note this may contain all the code details and symbols of your project.)
  • coredump (This provides stacks of tasks.)
@FanhuaCloud
Copy link
Contributor Author

I look the same ploblem #7812

@espressif-bot espressif-bot added the Status: Opened Issue is new label Dec 21, 2021
@github-actions github-actions bot changed the title esp32c3 i2c will cause cpu IDLE esp32c3 i2c will cause cpu IDLE (IDFGH-6463) Dec 21, 2021
@mythbuster5
Copy link
Collaborator

i2c_patch_1210 .txt

A patch may help here, change the *.txt to *.patch and git apply i2c_patch_1210.patch. Thanks

@o-marshmallow
Copy link
Collaborator

o-marshmallow commented Dec 22, 2021

Hi @FanhuaCloud ,

Can you provide a way for us to reproduce this issue? Can you provide an sdkconfig? What is you FreeRTOS tick rate and task watchdog timeout period in your sdkconfig (FREERTOS_HZ and ESP_TASK_WDT_TIMEOUT_S) ?
Thank @mythbuster5 for providing a fix

In a more general note, we do provide wrappers to ease I2C transfers, in your case, you could use:

i2c_master_read_from_device(I2C_NUM_0, AHT_I2C_ADDRESS_GND, data, 6, 1000 / portTICK_PERIOD_MS)

@FanhuaCloud
Copy link
Contributor Author

Hi @FanhuaCloud ,

Can you provide a way for us to reproduce this issue? Can you provide an sdkconfig? What is you FreeRTOS tick rate and task watchdog timeout period in your sdkconfig (FREERTOS_HZ and ESP_TASK_WDT_TIMEOUT_S) ? Thank @mythbuster5 for providing a fix

In a more general note, we do provide wrappers to ease I2C transfers, in your case, you could use:

i2c_master_read_from_device(I2C_NUM_0, AHT_I2C_ADDRESS_GND, data, 6, 1000 / portTICK_PERIOD_MS)

https://gist.github.com/FanhuaCloud/be12c7ad155f7a75221b99bd3e64ca62
This is my code, I am using aht10 to get the temperature.But when I use i2c to operate other devices, it is normal

@AxelLin
Copy link
Contributor

AxelLin commented Feb 26, 2022

i2c_patch_1210 .txt

A patch may help here, change the *.txt to *.patch and git apply i2c_patch_1210.patch. Thanks

@mythbuster5
The patch does not apply to current master (and v4.4) tree.

@AxelLin
Copy link
Contributor

AxelLin commented Mar 8, 2022

Just wondering how is the status, @mythbuster5 @o-marshmallow

I found:
In i2c_master_cmd_begin(),
If portBASE_TYPE evt_res = xQueueReceive(p_i2c->cmd_evt_queue, &evt, wait_time); timeout
then it calls
i2c_hw_fsm_reset
-> i2c_master_clear_bus(i2c_num); << This call never return

Then it keeps showing:
E (11445) task_wdt: Task watchdog got triggered. The following tasks did not reset the watchdog in time:
E (11445) task_wdt: - IDLE (CPU 0)
E (11445) task_wdt: Tasks currently running:
E (11445) task_wdt: CPU 0: main

@AxelLin
Copy link
Contributor

AxelLin commented Mar 28, 2022

Hi @FanhuaCloud ,

Thank @mythbuster5 for providing a fix

@o-marshmallow @mythbuster5
Caould you clarify what was fix? (Above patch does not apply)

@mythbuster5
Copy link
Collaborator

i2c_patch_0317.txt

@AxelLin Sorry, I saw the message just now

@AxelLin
Copy link
Contributor

AxelLin commented Mar 28, 2022

@mythbuster5

I test it by disconnect the SCL from my i2c sensor on pupose to simulate the TIMEOUT case.
Without the patch, I always got "task_wdt: Task watchdog got triggered.".
With the path, I no longer hit watchdog issue.
Thanks.

@AxelLin
Copy link
Contributor

AxelLin commented Apr 6, 2022

@o-marshmallow @mythbuster5

The fix is not available in any branch, when would you merge it?
The original patch (#8120 (comment)) was provided in last year,
no idea what are you waiting for.

@o-marshmallow
Copy link
Collaborator

@AxelLin This fix is simply a workaround, the goal is to fix the root cause first

@AxelLin
Copy link
Contributor

AxelLin commented Apr 8, 2022

@AxelLin This fix is simply a workaround, the goal is to fix the root cause first

The workaround fix appears in various places:
#8358 (comment)
#8543 (comment)
The feedback is the patch does not apply, however, there is no follow up.
It's a mess now.

@AxelLin
Copy link
Contributor

AxelLin commented Apr 25, 2022

Just wondering how is the status, @mythbuster5 @o-marshmallow

I found: In i2c_master_cmd_begin(), If portBASE_TYPE evt_res = xQueueReceive(p_i2c->cmd_evt_queue, &evt, wait_time); timeout then it calls i2c_hw_fsm_reset -> i2c_master_clear_bus(i2c_num); << This call never return

@o-marshmallow
FYI: Comment out this line fixes the "Task watchdog got triggered" issue:
https://github.com/espressif/esp-idf/blob/master/components/hal/esp32c3/include/hal/i2c_ll.h#L811

@espressif-bot espressif-bot added Status: In Progress Work is in progress Resolution: NA Issue resolution is unavailable Status: Done Issue is done internally Resolution: Done Issue is done internally and removed Status: Opened Issue is new Status: In Progress Work is in progress Resolution: NA Issue resolution is unavailable labels Apr 30, 2022
@Alvin1Zhang
Copy link
Collaborator

Alvin1Zhang commented May 16, 2022

Thanks for reporting and sorry for slow turnaround, fix is available 0b00831, we are also back porting to release branches.

Feel free to reopen.

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
Projects
None yet
Development

No branches or pull requests

6 participants