Chat freely about anything...

User avatar
By cristidr
#83048 I created a simple code that does nothing more that tries to print
__FILE__ __LINE__ and __func__ ( or __FUNCTION__) and the esp crashes at __func__.

I will like to use to use __func__ for debugging on a much bigger project, but I saw this crash and I tried to create this simple code to isolate the issue.

Searching on the internet reveals nothing.

I tested on more than 10 esp s , I got the same issue.
The wiring works fine, the voltage is ok, etc, I have a relatively big project that works fine with the same setup, but when I use __func__ it compiles, but it crashes.

If there a way to fix this ?

....

void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
//Serial.setDebugOutput(true);
Serial.println(__FILE__);Serial.println(__LINE__);
Serial.println(__func__);
}
....

When deploying this code on the esp8266 (esp 12 F version) I got


SDK:2.2.1(cfd48f3)/Core:2.5.2=20502000/lwIP:STABLE-2_1_2_RELEASE/glue:1.1-7-g82abda3/BearSSL:a143020
C:\Users\xxx\Desktop\sketch_jul06a\sketch_jul06a.ino
19
Fatal exception 3(LoadStoreErrorCause):
epc1=0x40202a11, epc2=0x00000000, epc3=0x00000000, excvaddr=0x4023e450, depc=0x00000000

Exception (3):
epc1=0x40202a11 epc2=0x00000000 epc3=0x00000000 excvaddr=0x4023e450 depc=0x00000000

>>>stack>>>

ctx: cont
sp: 3ffffda0 end: 3fffffc0 offset: 01a0
3fffff40: 3fffdad0 00000002 3ffee2fc 3ffee358
3fffff50: 3fffdad0 00000000 3ffee2fc 402010d4
3fffff60: 3ffe85a6 00000013 3ffee2fc 40201341
3fffff70: 4023e450 00000000 3ffee2fc 402013a4
3fffff80: 3fffdad0 00000000 3ffee2fc 402013e9
3fffff90: feefeffe 00000000 3ffee2fc 40201058
3fffffa0: feefeffe feefeffe 3ffee324 40201cc0
3fffffb0: feefeffe feefeffe 3ffe8508 40100461
<<<stack<<<

ets Jan 8 2013,rst cause:2, boot mode:(3,6)

load 0x4010f000, len 1384, room 16
tail 8
chksum 0x2d
csum 0x2d
v8b899c12
~ld

SDK:2.2.1....( the device rests and loops the same messages)

( I put this on the Newbie Corner but I think this is the correct location).
User avatar
By dr0b3rts
#84549 I had the same problem. The exception code hints at a memory access problem. So, I eventually figured out that __func__ needed to be accessed with a function that can directly read from flash memory.

Here's a guide I just found that explains this in detail:
https://arduino-esp8266.readthedocs.io/ ... OGMEM.html

From pgmspace.h:
Flash memory must be read using 32 bit aligned addresses else a processor
exception will be triggered.


Summary:
The fix in this case is to wrap __func__ in FPSTR().
Code: Select allSerial.println(FPSTR(__func__));

The function name (__func__) is stored on the flash (PROGMEM) and needs special functions (like strcpy_P) to access them.