Left here for archival purposes.

User avatar
By cal
#15224 Moin,

I wanted to have more information in case of cpu exceptions.
The result is the c level module "cal_dex" to debug exceptions.
The cpu exception handlers are tried to be wrapped and
additional information is printed to serial.

The following exception is the result from adding the following 2 lines
to "void nodemcu_init(void)" in user_main.c:
Code: Select all     // NODE_DBG("Flash sec num: 0x%x\n", flash_get_sec_num());
     task_init();
     system_os_post(USER_TASK_PRIO_0,SIG_LUA,'s');
+    // provoke Exception(29) writing the value 0xdeadbeaf to memory location 0x1020
+    *((int*)(0x1020)) = 0xdeadbeaf;
 }

This produces the following exception output:
Code: Select allcal_dex 0.1, dump 0.1
Fatal Exception: 001d (29), sp 3ffff720
SDK Version: 0.9.5
Fingerprint: 1/xh=4023fb8c,t=0000-7d1c,d=8000-8b48,b=ca80-5360,ro=8b50-ca80
 epc1: 4023f8c2  exccause: 0000001d  excvaddr: 00001020  depc: 00000000
 ps  : 00000030  sar     : 0000000b  unk1    : 00000000
 a0 :  4023f8bc  a1 :  3ffff820  a2 :  00001020  a3 :  deadbeaf
 a4 :  c0200000  a5 :  3fffdab0  a6 :  c0000000  a7 :  3fffdb20
 a8 :  3fff58e0  a9 :  00000000  a10:  00000018  a11:  00000001
 a12:  00080000  a13:  3ffecaa6  a14:  00000000  a15:  00000000
Stack (3ffff800)
3ffff7e0  00000480 00000000 3fffc718 402401b4 3fff5900 3fff58d0 4023f7d5 00080000
3ffff800  00000000 00000073 00000016 40100905 4023f8bc 3ffecaa6 00080000 4023f8af
3ffff820  8772000a 8d6c0a1b 2a106b73 efb59fcc d224ed2a 3c53381c e5db8fa3 8b45d9c1
3ffff840  72a005bd d9f8672f 91922415 d74dfbcf 09371733 4fd43d77 bc909457 bea74191
3ffff860  02e0906f 8a8722e5 900aa04e 80b6c98c be011f95 f75f530d 102bb6e3 bfe22af7
3ffff880  fe02e578 36bd19e3 931137ae b584d88c e6081f9d b058f2b2 fac9a074 f10981d8
3ffff8a0  0061f580 537d058c f5948567 179aec11 e2b2b36a 35f067b6 ad61578d 121e80b3
3ffff8c0  414db20d da021081 ae2c98d1 8b366efb f9c6bad4 7ff68b1e 89e889d7 9c9e04b2
3ffff8e0  e374d251 525dcc6a 6d378304 7300f335 22622da5 2cbaaa64 2c2b22fa 4f7ace44
3ffff900  c2c4be7c 7cb7780c 18a5cfb9 674efe6a 63211ff7 2e57b5aa 2bf88b5e 81ebad6e
3ffff920  0a24a65a 9b402545 83e268cf 8cd84bd7 654ace64 fe3abe60 2c8bc0c6 15b5a5d7
3ffff940  4c44e16f f5e9510b b8d31267 445e01c7 ce42d021 48edd298 c125c630 96c36f0d
3ffff960  a4f9df23 cf7d7a1c ea3a75ca e791ca53 717013eb 52a5d9be 5f83c23d f55d354d
3ffff980  03f255f8 312746f8 4ed7d74c 605d76dd 00000000 00000000 0000001f 40002e35
3ffff9a0  4000050c a0889c20 00000000 00004ec3 00009c20 00004ec3 00000000 ffffffff
3ffff9c0  40002ef1 00855c79 00000013 00000000 50444e10 00000000 3ffffa52 40221926

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

wdt reset
load 0x40100000, len 32028, room 16
tail 12
chksum 0xf9
ho 0 tail 12 room 4
load 0x3ffe8000, len 2888, room 12
tail 12
chksum 0x6a
ho 0 tail 12 room 4
load 0x3ffe8b50, len 16176, room 12
tail 4
chksum 0x08
csum 0x08
r,


1. Exception code 29: Illegal write access
2. epc1: 4023f8c2
The program counter when exception happened.

Execute:
xtensa-lx106-elf-addr2line -f -e app/.output/eagle/debug/image/eagle.app.v6.out 4023f8c2

nodemcu_init
??:?

3. excvaddr: 00001020
Someone wrote (exception 29) to address "00001020"

The code is here

https://github.com/cal101/nodemcu-firmw ... ev-cal-dex

You can use the whole branch which is just nodemcu-firmware, branch dev@6eb5b9c874cb1248ec77b57e946ffbf1cb431d08 (20.4.)
with cal_dex 0.1 added and startup message changed accordingly.


Integrating into your own builds is easy:

1. Add
Code: Select all   app/platform/cal_dex.c

to your build.

2. Add the following 3 lines to your Makefile
Code: Select all@@ -116,6 +116,9 @@ CCFLAGS +=                  \
        -mtext-section-literals
 #      -Wall                   
 
+# for cal_dex - exception debugging
+LDFLAGS += -Wl,--undefined=_xtos_set_exception_handler -Wl,--wrap=_xtos_set_exception_handler
+
 CFLAGS = $(CCFLAGS) $(DEFINES) $(EXTRA_CCFLAGS) $(INCLUDES)


I suggest also to switch the baud rate of your nodemcu firmware to 115200 because
early output is written at 115200 and that means less switching.

Code: Select allapp/user/user_main.c:
@@ -133,7 +135,8 @@ void user_init(void)
 #ifdef DEVELOP_VERSION
     uart_init(BIT_RATE_74880, BIT_RATE_74880);
 #else
-    uart_init(BIT_RATE_9600, BIT_RATE_9600);
+    uart_init(BIT_RATE_115200, BIT_RATE_115200);
+    //uart_init(BIT_RATE_9600, BIT_RATE_9600);
 #endif
     // uart_init(BIT_RATE_115200, BIT_RATE_115200);

Note that really early messages will be printed at 74880 baud.

Please let me know what you think about it!

Carsten