ESP32 InstrFetchProhibited: jumping to an address with no code

The CPU tried to fetch its next instruction from an address that is not instruction memory. Something made it jump there: a function pointer, or a return address on a damaged stack.

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

Core  1 register dump:
PC      : 0x00000000  PS      : 0x00060330  A0      : 0x800d1a2f  A1      : 0x3ffb1f80
...
Backtrace: 0x00000000:0x3ffb1f80 0x400d1a2c:0x3ffb1fa0 0x40089c46:0x3ffb1fc0

On RISC-V chips it is Instruction access fault.

Read PC first

Valid code on the ESP32 is at 0x4xxxxxxx. If PC is 0x00000000, a NULL function pointer was called. If it is some other value outside that range, the pointer, or a return address, was garbage.

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:

Here the first address is the bad one, so start at the second entry: that is the code that made the call or the return.

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: IllegalInstruction · Stack overflow · LoadProhibited · StoreProhibited. All ESP32 errors: the list. Messages and causes from ESP-IDF's panic handler and Espressif's Fatal Errors guide.

More