esp32

Diagnosing and Fixing ESP32 Double Exception Crashes

9 September 2026

What causes this

A double exception crash on the ESP32 typically arises from the CPU encountering a critical error while handling another exception. This often involves stack corruption or illegal memory access, leading to a nested exception scenario. The ESP32 uses two cores (PRO_CPU and APP_CPU), so the error can occur on either core, but is more common on the PRO_CPU due to its primary role in handling exceptions. Key registers like EXCVADDR (Exception Cause Address) and EPC1 (Exception Program Counter) will show invalid addresses or corrupted data. For instance, if EXCVADDR contains 0x00000000 or 0xFFFFFFFF, it indicates a null pointer dereference or stack overflow, respectively. The error codes LoadProhibited and StoreProhibited in the backtrace are crucial indicators of such issues, often pointing to attempts to access restricted memory areas.

Minimal reproduction

To reproduce a double exception crash, consider the following minimal code snippet:

```cpp

#include

void setup() {

Serial.begin(115200);

delay(1000);

// Intentionally causing a stack overflow

recursiveFunction();

}

void loop() {

// Empty loop

}

void recursiveFunction() {

int stackArray[1000]; // Large stack allocation

Serial.println(millis());

delay(10);

recursiveFunction();

}

```

Expected Serial Output:

```

Guru Meditation Error: Core 1 panic'ed (LoadProhibited). Exception was unhandled.

Core 1 register dump:

PC : 0x400d1af6 PS : 0x00060c30 A0 : 0x800d1b21 A1 : 0x3ffb1f40

...

EXCVADDR: 0x00000000 LBEG : 0x400d1af0 LEND : 0x400d1af6 LCOUNT : 0xffffffff

...

```

This code causes a stack overflow, leading to a double exception as it recursively allocates memory without a base case.

The fix

To prevent a double exception crash, you should ensure that your code handles exceptions gracefully and uses memory efficiently. Here’s how you can modify the above code to avoid crashes:

Before:

```cpp

void recursiveFunction() {

int stackArray[1000];

Serial.println(millis());

delay(10);

recursiveFunction();

}

```

After:

```cpp

void recursiveFunction(int depth) {

if (depth > 10) return; // Base case to prevent stack overflow

int stackArray[100];

Serial.println(millis());

delay(10);

recursiveFunction(depth + 1);

}

void setup() {

Serial.begin(115200);

delay(1000);

recursiveFunction(0); // Start with depth 0

}

```

Adding a base case to the recursion prevents the stack from overflowing and avoids the double exception scenario.

How SerialDoctor catches this

SerialDoctor simplifies diagnosing double exception crashes by quickly interpreting serial outputs. After connecting to your ESP32 via Web Serial, SerialDoctor reads the crash log, identifies critical error codes and register values, and provides a root cause analysis in under 3 seconds. Visit [serialdoctor.com](https://serialdoctor.com) to diagnose your crash logs efficiently.

Quick checklist

  • [ ] Ensure all memory accesses are within valid bounds to avoid LoadProhibited and StoreProhibited errors.
  • [ ] Implement base cases in recursive functions to prevent stack overflow.
  • [ ] Monitor EXCVADDR and EPC1 registers for illegal addresses.
  • [ ] Use tools like SerialDoctor for quick error identification and resolution.
  • [ ] Regularly update your ESP-IDF to incorporate the latest stability improvements.

Seeing this crash on your board right now?

Connect it to SerialDoctor and get a root cause + code fix in under 3 seconds.

Try SerialDoctor free →