espressif / arduino-esp32

Arduino core for the ESP32
GNU Lesser General Public License v2.1
13.3k stars 7.35k forks source link

Caught in constant reboots when using interrupts #8412

Closed Tinyu-Zhao closed 1 year ago

Tinyu-Zhao commented 1 year ago

Board

ESP32-D0WDQ6-V3

Device Description

M5Paper COMM EDition

Hardware Configuration

Schematic

Version

v2.0.5

IDE Name

PlatfromIO and Arduino

Operating System

macOS 11.7.8 or Windows

Flash frequency

40Mhz

PSRAM enabled

no

Upload speed

115200

Description

Constant reboot after program execution.

image

I suspect a conflict between Wire and IRQ, if I comment out the interrupts(); or Wire part of GT911::begin in the program, the program won't get stuck in a reboot.

`volatile uint8_t gt911_irq_trigger = 0;

void IRAM_ATTR GT911IRQ() { noInterrupts(); gt911_irq_trigger = 1; interrupts(); }

esp_err_t GT911::begin(uint8_t pin_sda, uint8_t pin_scl, uint8_t pin_int) { log_d("GT911: I2C Initialization"); pinMode(pin_int, INPUT); // Startup sequence PIN part

Wire.begin((int)pin_sda, (int)pin_scl,
           (uint32_t)100000U);  // Note: SHT3x sensor built into M5Paper
                                // only seems to work with default 100kHz
delay(100);

Wire.beginTransmission(0x14);
if (Wire.endTransmission()) {
    Wire.beginTransmission(0x5D);
    if (Wire.endTransmission()) {
        // log_e("Touch screen IIC connection error");
        return ESP_FAIL;
    }
    _iic_addr = 0x5D;
    // log_e("Wire.beginTransmission(0x5D)");
}
// log_d("Wire.endTransmission()=%d", Wire.endTransmission(true));

delay(100);
attachInterrupt(pin_int, ___GT911IRQ___, FALLING);
return ESP_OK;

}`

Sketch

https://github.com/Tinyu-Zhao/M5EPD/blob/main/%20main.cpp

Debug Message

Guru Meditation Error: Core  0 panic'ed (Unhandled debug exception). 
Debug exception reason: Stack canary watchpoint triggered (IDLE) 
Core  0 register dump:
PC      : 0x40084373  PS      : 0x00050036  A0      : 0x3ffbcec0  A1      : 0x3ffbce00  
A2      : 0x00000028  A3      : 0x3ffbe050  A4      : 0x400843db  A5      : 0xc0000000  
A6      : 0x3ffbcec0  A7      : 0x00000000  A8      : 0x3ffc198c  A9      : 0x4008438f  
A10     : 0x4008438f  A11     : 0x3ffbde98  A12     : 0x00000014  A13     : 0x00000000  
A14     : 0x3ffbde98  A15     : 0x80000001  SAR     : 0x0000001a  EXCCAUSE: 0x00000001  
EXCVADDR: 0x3ffbe11c  LBEG    : 0x00000000  LEND    : 0x00000000  LCOUNT  : 0x00000000  

Backtrace:0x40084370:0x3ffbce000x3ffbcebd:0x00000400  |<-CORRUPTED

Guru Meditation Error or Backtrace:
PC: 0x40084373: esp_spiram_writeback_cache at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/esp_hw_support/port/esp32/spiram.c line 257
EXCVADDR: 0x3ffbe11c

Decoding stack results
0x40084370: esp_spiram_writeback_cache at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/esp_hw_support/port/esp32/spiram.c line 257

Other Steps to Reproduce

No response

I have checked existing issues, online documentation and the Troubleshooting Guide

SuGlider commented 1 year ago

@Tinyu-Zhao - Please try using the latest Arduino Core 2.0.10 and let me know if the issue continues.

Tinyu-Zhao commented 1 year ago

@SuGlider Hi, just upgraded the kernel to 2.0.10 and tried again, but the problem still exists!

image

Debug Message

ELF file SHA256: f82a5b93590fc88a

Rebooting...

assert failed: spinlock_acquire spinlock.h:122 (result == core_id || result == SPINLOCK_FREE)

Backtrace: 0x40086389:0x3ffbc4c0 0x400d9e35:0x3ffbc4d0 0x40083900:0x3ffbc520 0x40084890:0x3ffbc540 0x4008386d:0x3ffbc600 0x400884b5:0x3ffbc620 0x4008d559:0x3ffbc640 0x4008b213:0x3ffbc770 0x400d939c:0x3ffbc7b0 0x400d93eb:0x3ffbc7e0 0x400d97da:0x3ffbc800 0x400896b1:0x3ffbc820

ESP Exception Decoding stack results

0x400d9e35: panic_handler at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/esp_system/port/panic_handler.c line 124
0x40083900: xt_unhandled_exception at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/esp_system/port/panic_handler.c line 219
0x4008386d: panic_abort at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/esp_system/panic.c line 408
0x400884b5: esp_system_abort at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/esp_system/esp_system.c line 137
0x4008d559: __assert_func at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/newlib/assert.c line 85
0x4008b213: xPortEnterCriticalTimeout at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/esp_hw_support/include/soc/spinlock.h line 122
0x400d939c: esp_task_wdt_reset at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/port/xtensa/include/freertos/portmacro.h line 578
0x400d93eb: idle_hook_cb at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/esp_system/task_wdt.c line 80
0x400d97da: esp_vApplicationIdleHook at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/esp_system/freertos_hooks.c line 51
0x400896b1: prvIdleTask at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/tasks.c line 3987
SuGlider commented 1 year ago

@Tinyu-Zhao

Please try this code:

void IRAM_ATTR GT911IRQ() {
  // removed interrupts()/noInterrupts() from the GPIO ISR
  gt911_irq_trigger = 1;
}

Is there a reason for using interrupts()/noInterrupts()?

Tinyu-Zhao commented 1 year ago

After testing, removing "interrupts()/noInterrupts()" doesn't affect the functionality and stops the constant rebooting.

This is the code left by a former colleague many years ago, before esp 2.0.5 this problem did not occur, do you know what causes this problem?

Is it because of this?

image
SuGlider commented 1 year ago

ESP32 Arduino runs on top of FreeRTOS. It doesn't make much sense to disable interrupts when running a RTOS. The software shall use FreeRTOS resources to achieve results.

SuGlider commented 1 year ago

Is it because of this?

Yes, I think that before 2.0.5 sei() and cli() had no code.

Tinyu-Zhao commented 1 year ago

Thank you for your answer and help. Have fun.☺️