Electronics Microcontrollers "/>

Guru Meditation Error: Core 0 panic’ed (LoadProhibited)

30 April 2021 at 3:11 pm

Article image for Guru Meditation Error: Core  0 panic’ed (LoadProhibited)

I’m working a lot with ESP32-based microcontrollers these days. The Arduino setup for ESP is quite nice, but since I’m using the new ESP32-S2 variant, it’s not well supported. So I’m taking this as a chance to play around with the official esp-idf, using just C. I just spent way too much time debugging a problem, so I wanted to post the solution here for others to find.

​For my application, I want to make it possible to setup an ESP32 to connect to your local network by saving credentials. The device only has a single switch as an input and I’ll check this during statup to see if the device should be in Access Point mode (AP) or Station mode (STA). All good, but how do I enter the Setup mode? Easy. If you change the switch while the device is powered, it’ll go into setup mode so this provides a third input.

I got this in place and started using the Non-volatile storage library (NVS) for storing SSID and password and from here it went downhill. The ESP32 crashed and output core dumps with errors like this:

Guru Meditation Error: Core 0 panic’ed (LoadProhibited). Exception was unhandled.
Core 0 register dump: 
PC : 0x40007e40 PS : 0x00060930 A0 : 0x800e1ef0 A1 : 0x3ffd2be0 
A2 : 0x00000000 A3 : 0xfffffffc A4 : 0x000000ff A5 : 0x0000ff00 
A6 : 0x00ff0000 A7 : 0xff000000 A8 : 0x800267b4 A9 : 0x3ffd2ba0 
A10 : 0x00000000 A11 : 0xffffffff A12 : 0x00000001 A13 : 0x00000000 
A14 : 0x00000001 A15 : 0x00000000 SAR : 0x00000020 EXCCAUSE: 0x0000001c 
EXCVADDR: 0x00000000 LBEG : 0x00000001 LEND : 0x00000000 LCOUNT : 0x40025ff9 

Backtrace:0x40007e3d:0x3ffd2be0 0x400e1eed:0x3ffd2bf0 0x400d9fd9:0x3ffd2f00 0x40082204:0x3ffd2f50 0x40082ecc:0x3ffd2f80 0x400845d3:0x3ffd2fb0 0x4002aa55:0x3ffd2fe0 
ELF file SHA256: 37cfd39113fd02ad 
Build:Oct 25 2019 
rst:0x3 (RTC_SW_SYS_RST),
boot:0x18 (SPI_FAST_FLASH_BOOT) 
Saved PC:0x40025a89 
mode:DIO, clock div:1

This error had me puzzled for far too long time. I commented in and out methods and nailed it down to it being related to reading back NVS with nvs_get_str. Googling the error provided no answers, so I started widening my search. Eventually, text from a PDF book from 2017 by Neil Kolban pointed me to the answer. Looking at EXCVADDR and where it’s pointing (0x00000000) I could see that something was very wrong. It makes no sense for memory to point here and I started thinking about what was ACTUALLY happening in the code.

Then it struck me - I had no terminating character in my string? Turns out that strcpy did not terminate strings as I thought, but strlcpy will do the job safely. This has bitten me before and it probably will do again. That’s what I get for having spent so many years in managed programming languages. C & C++ is very bare bones, but it’s easy to forget when you use modern C++ or the Arduino framework. Hope this helps someone!