Skip to content

attachInterrupt(rxPin, onRx, FALLING) results in immediate reset after updating from 2.0.2 to 2.0.3 (and 2.0.4) #7202

Closed
@dagnall53

Description

@dagnall53

Board

ESP32 devboard

Device Description

The fault was noted in code that uses a software UART.
I have added a number of debug printlns to explore when and why the code resets repeatedly after being compiled with 2.0.3 (and 2.0.4).
These debug printlns appear to show that the code resets if attachInterrupt(rxPin, onRx, FALLING); is called from within a timer interrupt.
When compiled using 2.0.2, the code functions ok, and progresses past this point and then works fully.
I have made a much simplified code (below) that demonstrates this effect.

Hardware Configuration

Fault occurs with bare board. Resets during setup with 2.0.3 (+) revision compilers. but works with 2.0.2 and earlier.

Version

v2.0.4

IDE Name

Version: 2.0.0-rc9.2 Date: 2022-08-10T13:03:18.962Z CLI Version: 0.26.0-rc.1 [fc2ea723] Copyright © 2022 Arduino SA

Operating System

win10

Flash frequency

80Mhz

PSRAM enabled

no

Upload speed

115200

Description

The problem manifests as the Hardware resetting during code start-up.

BY adding debugprint lines I have traced the issue to a single line that attaches a falling edge interrupt as part of a Timer interrupt.
In "normal" use as compiled by earlier versions (eg 2.0.2), the code will setup a timerAlarmEnable(timer_1);, and do subsequent debug prints and will function as expected.
But with 2.0.3 (+) the code appears to fail and reset the ESP at this line.

This timer interrupt code does many things, but the FIRST time it is run, it stops the timer and Sets a falling edge interrupt. It is this element that appears to be failing.

The UART code was originally designed to overcome the (undocumented?) ESP32 hardware(?) issue that results in the FIRST timer interrupt always occurring immediately after the timer is setup. (If this 'first immediate trigger' was a SOFTWARE fault, it is possible that we can redesign the code to accept 2.0.3 on.. but I have not been able to explore this possibility)

I have sketched the key parts of the code below it does not "do" anything, but it does demonstrate how the code will not complete my setup with compiler 2.0.3 on.
.
Many thanks

Sketch

//  Updated with a simpler example.. 
//This partial code shows the general form of the UART setup. and is sufficient to demonstrate the reset behaviour with 2.0.3 on.
// if pin IO18 is pulled down it will start (simulated) reading a byte
// but if compiled with 2.0.3 (0n), it will give a GURU mediation error, like this...
//setup-start
//v4.4.1-472-gc9140caf8c
//0
//attachInterrupt
//Guru Meditation Error: Core  1 panic'ed (Interrupt wdt timeout on CPU1). 
 //interrupt  wdt interrupt crash
//******** code starts **************
#define RX_ST_PIN 18
hw_timer_t * timer_1 = NULL;

volatile byte rxBitCounter = 0;

void IRAM_ATTR onRx() { 
  detachInterrupt(RX_ST_PIN);
  Serial.println("onRx");  
  timerStart(timer_1);
  timerAlarmWrite(timer_1, 1.8 * 10000000.0 / 4800, true);
  timerAlarmEnable(timer_1);
}

void IRAM_ATTR onRxTimer() {
  Serial.println(rxBitCounter);
  if ( rxBitCounter == 0 ) {   // special case for first setup. to overcome initial zero time timeout
    rxBitCounter = 1;
    timerStop(timer_1);
    Serial.println("attachInterrupt");
    attachInterrupt(RX_ST_PIN, onRx, FALLING);//Crashes here in v2.0.3+
    Serial.println("attachInterrupt-done");    
  }
  if (rxBitCounter == 10) {
    rxBitCounter = 1;
    timerStop(timer_1);   
    attachInterrupt(RX_ST_PIN, onRx, FALLING);
    return;
  }
  rxBitCounter++;
}

void setup() {
  Serial.begin(115200, SERIAL_8N1, 3, 1);
  delay(1000);
  Serial.println("setup-start");
  Serial.println(ESP.getSdkVersion());
  pinMode(RX_ST_PIN, INPUT_PULLUP);
  timer_1 = timerBegin(1, 8, true);
  timerAttachInterrupt(timer_1, &onRxTimer, true);
  timerAlarmWrite(timer_1, 10, true);
  timerAlarmEnable(timer_1);  
  Serial.println("setup-end");
}

void loop() {
  Serial.println("loop");
  delay (10000);
}

Debug Message

When compiled with 2.0.3 or subsequent, the code does not progress past  the "attachInterrupt(rxPin, onRx, FALLING);" statement: 

This is demonstrated in the debug prints:  (here with V2.0.4)
setup-start
v4.4.1-472-gc9140caf8c
0
attachInterrupt
Guru Meditation Error: Core  1 panic'ed (Interrupt wdt timeout on CPU1). 

Core  1 register dump:
PC      : 0x4008a7f0  PS      : 0x00060735  A0      : 0x80089a46  A1      : 0x3ffbec7c  
A2      : 0x3ffb7bf8  A3      : 0x3ffb8890  A4      : 0x00000004  A5      : 0x00060723  

Other Steps to Reproduce

Code works with previous versions of compiler, its just versions after 2.0.3 that fail.

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

  • I confirm I have checked existing issues, online documentation and Troubleshooting guide.

Metadata

Metadata

Assignees

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions