esp32arduino-esp32

ESP32 Core 1 panic'ed (Interrupt wdt timeout on CPU1)


I am using Arduino IDE with ESP32. Hardware is simple: ESP32 dev board + led and reed switch. I want to detect reed switch inputs (1Hz to 40Hz frequency) and blink a LED for now.

Code is simple:

const int button = 27;
const int led =  25;

unsigned long now = millis();
unsigned long lastTrigger = 0;
boolean startTimer = false;

void IRAM_ATTR buttonInput() {
  Serial.println("IN");
  digitalWrite(led, HIGH);
  startTimer = true;
  lastTrigger = millis();
}

void setup() {
  Serial.begin(115200);
  pinMode(button, INPUT);
  pinMode(led, OUTPUT);
  digitalWrite(led, LOW);
  
  attachInterrupt(digitalPinToInterrupt(button), buttonInput, RISING);
}

void loop() {
  now = millis();
  if(startTimer && (now - lastTrigger > 25)) { // switch of led after 25 ms
    digitalWrite(led, LOW);
    startTimer = false;
  } 
}

But I am getting core panics and restarts on interrupts (looks to be independent from frequency of reed switch trigger):

IN
Guru Meditation Error: Core  1 panic'ed (Interrupt wdt timeout on CPU1). 

Core  1 register dump:
PC      : 0x4008a0dc  PS      : 0x00060435  A0      : 0x80089352  A1      : 0x3ffbed1c  
A2      : 0x3ffb8a00  A3      : 0x3ffb8890  A4      : 0x00000004  A5      : 0x00060423  
A6      : 0x00060423  A7      : 0x00000001  A8      : 0x3ffb8890  A9      : 0x00000018  
A10     : 0x3ffb8890  A11     : 0x00000018  A12     : 0x3ffc1804  A13     : 0x00060423  
A14     : 0x007bee78  A15     : 0x003fffff  SAR     : 0x0000000a  EXCCAUSE: 0x00000006  
EXCVADDR: 0x00000000  LBEG    : 0x40085fb5  LEND    : 0x40085fc5  LCOUNT  : 0xffffffff  
Core  1 was running in ISR context:
EPC1    : 0x400d8e2f  EPC2    : 0x00000000  EPC3    : 0x00000000  EPC4    : 0x00000000

Backtrace:0x4008a0d9:0x3ffbed1c |<-CORRUPTED

Core  0 register dump:
PC      : 0x4008a259  PS      : 0x00060035  A0      : 0x80088f7f  A1      : 0x3ffbe7cc  
A2      : 0x3ffbee78  A3      : 0xb33fffff  A4      : 0x0000abab  A5      : 0x00060023  
A6      : 0x00060021  A7      : 0x0000cdcd  A8      : 0x0000cdcd  A9      : 0xffffffff  
A10     : 0x3ffc160c  A11     : 0x00000000  A12     : 0x3ffc1608  A13     : 0x00000007  
A14     : 0x007bee78  A15     : 0x003fffff  SAR     : 0x0000001a  EXCCAUSE: 0x00000006  
EXCVADDR: 0x00000000  LBEG    : 0x00000000  LEND    : 0x00000000  LCOUNT  : 0x00000000  

Backtrace:0x4008a256:0x3ffbe7cc |<-CORRUPTED

ELF file SHA256: 0000000000000000

Rebooting...
ets Jun  8 2016 00:22:57

rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0030,len:1324
ho 0 tail 12 room 4
load:0x40078000,len:13508
load:0x40080400,len:3604
entry 0x400805f0
IN
IN
IN

What does it mean <-CORRUPTED? What am I doing wrong?


Solution

  • The code uses serial communication within an interrupt handler (buttonInput()). This does not work.

    When an interrupt handler is called, it blocks the entire system. So it must only do minimal work and return quickly. Serial communication however is slow and causes long delays. Thus, your program is terminated by the watchdog ("wdt" is the abbreviation for the watchdog).

    Chances are that your button bounces when it's pressed, i.e. it will repeatedly call the interrupt handler within fractions of a second. This will aggravate the problem.

    It's probably best to just set a flag in the interrupt handler and do all the relevant work in the main loop.