ESP32 LoadProhibited: reading from an address that is not there

A LoadProhibited panic means the CPU tried to read memory at an address that does not exist or is not readable. Almost always a pointer: NULL, uninitialized, or already freed.

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

Core  1 register dump:
PC      : 0x400d1d4e  PS      : 0x00060630  A0      : 0x800d1e5c  A1      : 0x3ffb2270
...
EXCVADDR: 0x0000000c  LBEG    : 0x4000c2e0  LEND    : 0x4000c2f6  LCOUNT  : 0x00000000

Backtrace: 0x400d1d4b:0x3ffb2270 0x400d1e59:0x3ffb2290 0x40089ec6:0x3ffb22b0

On the ESP32-C3, C6, H2 and the other RISC-V chips the same mistake is reported as Load access fault, with the address in MTVAL.

Read EXCVADDR first

The register dump has the address the CPU tried to read in EXCVADDR (in MTVAL on RISC-V chips). It tells you most of the story:

The usual causes

Find the line

The Backtrace: line is a list of PC:SP pairs, innermost call first. To turn the addresses into functions and lines you need the ELF of exactly the build that crashed:

The first address in the backtrace is the instruction that did the read. The line it points to dereferences the bad pointer; the lines below it show where that pointer came from.

When it happens in the field

On your desk the crash prints to the serial monitor. On a device in someone else's building it prints to a port nobody is reading, the chip restarts, and all you hear is that it "sometimes hangs". Pinscope keeps the panic reason and backtrace across the restart, sends them on the next connection and decodes them with the ELF of the build that crashed, so you get the function and line without anyone at the device. Free for three devices. How crash reporting from the field works.

Related errors: StoreProhibited · InstrFetchProhibited · CORRUPT HEAP · Stack overflow. All ESP32 errors: the list. Messages and causes from ESP-IDF's panic handler and Espressif's Fatal Errors guide.

More