DebuggingTools

Debugging the ESP32: reading Guru Meditation errors, backtraces and watchdogs

Applies to the Arduino core and ESP-IDF · needs a USB cable and a Serial Monitor at 115200

You flash your code, the ESP32 runs for a while, then prints a long block starting with "Guru Meditation Error: Core 1 panic'ed", a string of hex numbers, and reboots. That text is not noise: it is an autopsy report telling you why the chip died and, once decoded, which line of code it died on. This article shows how to read it in order, from quick to deep.

A typical error message

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

Core  1 register dump:
PC      : 0x400d1a3c  PS      : 0x00060830  A0      : 0x800d1b10  A1      : 0x3ffb1f60
...
EXCVADDR: 0x00000000  LBEG    : 0x4000c2e0  LEND    : 0x4000c2f6  LCOUNT  : 0x00000000

Backtrace: 0x400d1a3c:0x3ffb1f60 0x400d1b0d:0x3ffb1f80 0x400d2a55:0x3ffb1fb0

ELF file SHA256: 6b5c...
Rebooting...

The four most important pieces:

A triage procedure

Guru Meditation / unexpected reset1. Read the error name and EXCVADDRLoadProhibited /StoreProhibitedEXCVADDR ≈ 0 → NULL pointerStack canary / overflowa task used too much stackor the heap is corruptedTask watchdog / Brownouta loop blocked too longor the supply voltage sagged2. Decode the backtrace→ find the line, check pointersRaise stack, shrink locals,check for array overrunsRemove long delays, changethe supply, add a big capacitor
Figure 1: Classifying a fault by its name. For every type, read the error name and EXCVADDR before changing any code.

What the common errors mean

MessageWhat it meansUsual causes
LoadProhibited / StoreProhibitedRead or write to an invalid addressNULL or uninitialised pointers (an object whose begin() was never called, malloc returning NULL on out-of-memory), array index out of bounds, using freed memory.
InstrFetchProhibitedJumped to an address that is not program codeA bad or NULL function pointer, or a buffer overflow that corrupted a return address.
IntegerDivideByZeroInteger division by zeroA denominator taken from a sensor or an unassigned variable.
Unhandled debug exception with "Stack canary watchpoint triggered (task name)"A task's stack overflowedLarge local arrays or strings, deep recursion, String and printf with big buffers in a small task. Raise the stack size or move the array to a global.
Task watchdog got triggered ("The following tasks did not reset the watchdog in time")A task hogged the CPU and never yieldedAn infinite while wait, a very long delay, a hung sensor read, heavy computation in loop() or a callback.
Interrupt wdt timeout on CPU0/1An interrupt handler or interrupts-disabled section ran too longAn ISR calling Serial.print, delay, or doing heavy work. An ISR must be short and only set a flag.
Cache disabled but cached memory region accessedAn ISR called a function stored in flash while flash was busy (NVS write, OTA)Mark the ISR and every function/variable it uses with IRAM_ATTR.
Brownout detector was triggeredThe supply voltage fell below the thresholdA thin USB cable, a weak supply, or large loads (relay, WiFi, camera, motor) switching on together. See below.
CORRUPT HEAP / assert failed: ... heapHeap memory was overwrittenOverrunning a dynamically allocated buffer, double free, using a pointer after freeing it.

Decoding the backtrace into a source line

The addresses in "Backtrace:" mean nothing by eye. A tool turns them into function names and source lines.

Option 1: PlatformIO (easiest)

Add one line to platformio.ini. On every crash the Serial Monitor prints function names and source lines right below the backtrace:

[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino
monitor_speed = 115200
monitor_filters = esp32_exception_decoder
build_type = debug          ; keep debug info for more accurate decoding

Option 2: Arduino IDE

Arduino IDE 2.x no longer supports the "ESP Exception Decoder" plugin from 1.8. Use the addr2line tool shipped in the board package, with the .elf file from that exact build:

  1. Find the .elf: in Arduino IDE enable File → Preferences → Show verbose output during: compile, or use Sketch → Export Compiled Binary and open the sketch's build folder.
  2. Run the command (the tool lives under packages/esp32/tools/xtensa-esp32-elf-gcc/...; ESP32-C3/C6 use the riscv32-esp-elf toolchain):
xtensa-esp32-elf-addr2line -pfiaC -e sketch.ino.elf 0x400d1a3c 0x400d1b0d 0x400d2a55

The output looks like readSensor() at sketch.ino:42 and tells you the faulting function and line. Important: the ELF must match the firmware currently on the chip. Compare the "ELF file SHA256" in the error message with your file; any code change and recompile moves the addresses.

Reading the result

The first line is where it died (PC); the following lines are the chain of callers. Skip system library functions (esp_*, vTask*) and find the first frame that is your code: the cause is usually there, typically a pointer or index you passed down into a library.

Real examples and fixes

NULL pointer: LoadProhibited, EXCVADDR 0x00000000

// Wrong: bme was never created or started
Adafruit_BME280* bme;            // = nullptr
void loop() { float t = bme->readTemperature(); }

// Right: create the object and check the result before using it
Adafruit_BME280 bme;
void setup() { if (!bme.begin(0x76)) { Serial.println("BME280 not found"); while (true) delay(1000); } }

Stack overflow

// Wrong: a big local array in a task with a small stack (loopTask defaults to 8 KB)
void handleUpload() { char buf[16384]; /* ... */ }

// Right: move it to static storage/heap, or enlarge the task's stack
static char buf[16384];
xTaskCreatePinnedToCore(worker, "worker", 8192, NULL, 1, NULL, 1);   // 8192-byte stack

To see how much stack a task has left, call uxTaskGetStackHighWaterMark(NULL). The closer to 0, the more dangerous (in bytes under ESP-IDF on the ESP32).

Watchdog

// Wrong: waits forever for a sensor that may never answer
while (!sensor.ready()) { }

// Right: bounded wait that yields the CPU
uint32_t t0 = millis();
while (!sensor.ready()) {
  if (millis() - t0 > 2000) { Serial.println("Sensor not responding"); break; }
  delay(10);                       // delay() yields to other tasks
}

For work that is genuinely long, move it into its own task. Do not disable the watchdog just to make the error go away: the bug stays, you just stop seeing it.

Brownout: when the power supply is the culprit

The message Brownout detector was triggered is not a code bug. The ESP32 has a voltage monitor; when the supply dips below roughly 2.4–2.7 V (depending on configuration) it resets itself to avoid running incorrectly. During WiFi transmission the ESP32 can pull current bursts of 300–500 mA, so a weak supply sags:

More debugging tools

Bugs worth preventing from the start

Summary