whitecatboard / Lua-RTOS-ESP32

Lua RTOS for ESP32
Other
1.18k stars 222 forks source link

LMIC_ASSERT(readReg(RegOpMode) == 0x10); fails in txfsk (after waking up from cpu.sleep(10)) #388

Open elsbiet opened 3 years ago

elsbiet commented 3 years ago

.. lora.attach(lora.BAND868)

lora.setAppEui("***.. ") lora.setAppKey("**..")

lora.setDr(7) lora.setAdr(true) lora.setReTx(4) lora.join(lora.OTAA) lora.tx(false, 4, pack.pack(msg)) ..

will crash the system (at least on my esp32) soon after waking up from cpu.sleep(10). if i move lora.setDr(7) 1 line down the system will run fine.

the crash is the consequence of a failed assertion in static void txfsk () - RegOpMode contains 0. i feel this might be the consequence of the (partly uninitialized) global variable LMIC - i have never requested fsk-modem operation.

is there anything to do before sending the cpu to sleep?

crash details:

Guru Meditation Error: Core 0 panic'ed (LoadProhibited). Exception was unhandled. Core 0 register dump: PC : 0x4000c250 PS : 0x00060d30 A0 : 0x800576e9 A1 : 0x3ffca600
A2 : 0x000001b8 A3 : 0x00000000 A4 : 0x000001b7 A5 : 0x00000042
A6 : 0x3ffcad0f A7 : 0x00000000 A8 : 0x00000007 A9 : 0x3ffcad15
A10 : 0x00000020 A11 : 0x3f42f149 A12 : 0x00000042 A13 : 0x00000000
A14 : 0x3ffcaccd A15 : 0x00000000 SAR : 0x0000001f EXCCAUSE: 0x0000001c
EXCVADDR: 0x000001b8 LBEG : 0x4000c2e0 LEND : 0x4000c2f6 LCOUNT : 0xffffffff

ELF file SHA256: 14be0c661e99678fc1da75111a144c2e248e9abb3f3d9fedd70bd64d4ddc1cce

Backtrace: 0x4000c250:0x3ffca600 0x400576e6:0x3ffca620 0x4005730f:0x3ffca650 0x40056a4e:0x3ffca6e0 0x40056a86:0x3ffca770 0x400dbf8f:0x3ffca7b0 0x400dc0b2:0x3ffca7f0 0x40173141:0x3ffca840 0x4017599d:0x3ffca860 0x40174a19:0x3ffca8a0 0x401751ec:0x3ffca8f0 0x40175226:0x3ffca910 0x401731bd:0x3ffca930 0x40172b60:0x3ffca970 0x400d5b77:0x3ffca990 0x400dbf8f: vsyslog at /home/splge/ESP32/Lua-RTOS-ESP32/components/sys/unix/syslog.c:168

0x400dc0b2: syslog at /home/splge/ESP32/Lua-RTOS-ESP32/components/sys/unix/syslog.c:123

0x40173141: hal_failed at /home/splge/ESP32/Lua-RTOS-ESP32/components/lora/node/lmic/lmic_hal.c:391

0x4017599d: txfsk at /home/splge/ESP32/Lua-RTOS-ESP32/components/lora/node/lmic/radio.c:440 (inlined by) starttx at /home/splge/ESP32/Lua-RTOS-ESP32/components/lora/node/lmic/radio.c:534 (inlined by) os_radio at /home/splge/ESP32/Lua-RTOS-ESP32/components/lora/node/lmic/radio.c:849

0x40174a19: engineUpdate at /home/splge/ESP32/Lua-RTOS-ESP32/components/lora/node/lmic/lmic.c:175

0x401751ec: LMIC_setTxData at /home/splge/ESP32/Lua-RTOS-ESP32/components/lora/node/lmic/lmic.c:175

0x40175226: LMIC_setTxData2 at /home/splge/ESP32/Lua-RTOS-ESP32/components/lora/node/lmic/lmic.c:175

0x401731bd: hal_lmic_command at /home/splge/ESP32/Lua-RTOS-ESP32/components/lora/node/lmic/lmic_hal.c:425

0x40172b60: os_runloop at /home/splge/ESP32/Lua-RTOS-ESP32/components/lora/node/lmic/oslmic.c:160

0x400d5b77: pthreadTask at /home/splge/ESP32/Lua-RTOS-ESP32/components/pthread/_pthread.c:551 .. (gdb) bt

0 0x4000c250 in ?? ()

1 0x400576e9 in ?? ()

2 0x40057312 in ?? ()

3 0x40056a51 in ?? ()

4 0x40056a89 in ?? ()

5 0x400dbf92 in vsyslog (pri=, fmt=0x3f42eecc "%lu: assert at %s, line %s\n", ap=...) at /home/splge/ESP32/Lua-RTOS-ESP32/components/sys/unix/syslog.c:168

6 0x400dc0b5 in syslog (pri=3, fmt=0x3f42eecc "%lu: assert at %s, line %s\n") at /home/splge/ESP32/Lua-RTOS-ESP32/components/sys/unix/syslog.c:123

7 0x40173144 in hal_failed (file=0x3f42f149 "/home/splge/ESP32/Lua-RTOS-ESP32/components/lora/node/lmic/radio.c", line=440) at /home/splge/ESP32/Lua-RTOS-ESP32/components/lora/node/lmic/lmic_hal.c:391

8 0x401759a0 in txfsk () at /home/splge/ESP32/Lua-RTOS-ESP32/components/lora/node/lmic/radio.c:440

9 starttx () at /home/splge/ESP32/Lua-RTOS-ESP32/components/lora/node/lmic/radio.c:534

10 os_radio (mode=) at /home/splge/ESP32/Lua-RTOS-ESP32/components/lora/node/lmic/radio.c:849

11 0x40174a1c in engineUpdate () at /home/splge/ESP32/Lua-RTOS-ESP32/components/lora/node/lmic/lmic.c:2262

12 0x401751ef in LMIC_setTxData () at /home/splge/ESP32/Lua-RTOS-ESP32/components/lora/node/lmic/lmic.c:2353

13 0x40175229 in LMIC_setTxData2 (port=4 '\004', data=, dlen=13 '\r', confirmed=0 '\000') at /home/splge/ESP32/Lua-RTOS-ESP32/components/lora/node/lmic/lmic.c:2366

14 0x401731c0 in hal_lmic_command () at /home/splge/ESP32/Lua-RTOS-ESP32/components/lora/node/lmic/lmic_hal.c:425

15 0x40172b63 in os_runloop (pvParameters=) at /home/splge/ESP32/Lua-RTOS-ESP32/components/lora/node/lmic/oslmic.c:160

16 0x400d5b7a in pthreadTask (taskArgs=0x3ffc8ff4) at /home/splge/ESP32/Lua-RTOS-ESP32/components/pthread/_pthread.c:651

the0ne commented 2 years ago

I guess you mean this assert in file components/lora/node/lmic/radio.c on line 436 LMIC_ASSERT(readReg(RegOpMode) == 0x10); That would be a little strange though, as the line before set's the RegOpMode register to exactly that value: writeReg(RegOpMode, 0x10); // FSK, BT=0.5

Please confirm. If so, you could probably try to put a while instead of the LMIC_ASSERT and just re-execute the line that is setting the RegOpMode. Like e.g.

    while(readReg(RegOpMode) != 0x10) {
        // select FSK modem (from sleep mode)
        writeReg(RegOpMode, 0x10); // FSK, BT=0.5
    }
    // enter standby mode (required for FIFO loading)
    opmode(OPMODE_STANDBY);

That could make sure that even when coming out of wakeup, the register should properly be set.