Closed CheatingBoy6890 closed 3 months ago
I think the problem is the ISR code - it is typically advisable to do as little as possible in it:
void IRAM_ATTR onShoot()
...
TaskShoot.restartDelayed(weapons[myWeaponIndex].getTimeBeforeShot());
...
}
The code for getTimeBeforeShot()
may not be in memory during ISR call, and an attempt to load it from flash fails.
I would use values instead of method calls and maybe place those in IRAM as well.
I tried replacing the
TaskShoot.restartDelayed(...);
with just
TaskShoot.restart();
and then with a 2 millisecond delay (I know you shouldn't use delay in interrupts). But even then the exception states that exception stays the same:
epc1=0x40236240 epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000000 depc=0x00000000
Illegal instruction
epc1=0x40236240 in Task::isEnabled() at .pio/libdeps/d1_mini_debug/TaskScheduler/src/TaskScheduler.h:512
>>>stack>>>
ctx: cont
sp: 3ffff900 end: 3fffffc0 offset: 0150
3ffffa50: 40100a28 f0bb379c 77d67f28 40100add
3ffffa60: 00000020 3ffffa90 3fff0d4c 40242fc8
3ffffa70: c0034034 3fff32f4 3ffffab0 402584f2
3ffffa80: 401006a0 00000002 00000001 00000022
3ffffa90: 3fffc200 401009ec 3fffc258 4000050c
3ffffaa0: 4000437d 00000030 00000016 ffffffff
3ffffab0: 60000200 00000008 ffffffff 80000000
3ffffac0: 20000000 3fff2140 80000000 20344060
3ffffad0: 80000000 00000002 00000734 3fff2144
3ffffae0: 000000a0 00344060 00344000 00000030
3ffffaf0: 401006a0 401005f8 3fffc270 4000050c
3ffffb00: 400043e9 401005f8 3fffc270 4000050c
3ffffb10: 400043a3 00000030 00000016 ffffffff
3ffffb20: 60000200 00000006 1c261ac4 80000000
3ffffb30: 20000000 3fff2400 80000000 203438e0
3ffffb40: 00000000 00000004 000006a4 3fff2404
3ffffb50: 00000020 003438e0 00343800 00000030
3ffffb60: 40004b31 3fff1ebc 00000100 00338400
3ffffb70: 40107070 00000030 0000001c ffffffff
3ffffb80: 40100779 3fff1ebc 00000100 3fff1ebc
3ffffb90: 00000000 400042db 00338400 40227575
3ffffba0: 40004b31 3fff20e4 00000100 00344000
3ffffbb0: 40107070 00000000 00000020 40100724
3ffffbc0: 40100779 3fff20e4 00000100 3fff20e4
3ffffbd0: 3ffe9e05 40105c1b 00344000 40227575
3ffffbe0: 4010350f 3ffed868 0000000a 40227611
3ffffbf0: 00007fff 0097443e 3ffee124 401036ec
3ffffc00: 00000000 400042db 00000000 3fff0000
3ffffc10: 40004b31 3fff1fd0 00000100 00348100
3ffffc20: 40107070 7fffffff 00000000 00000001
3ffffc30: 40100779 3fff1fd0 00000100 3fff1fd0
3ffffc40: 3ffea6a4 00000000 00348100 40227575
3ffffc50: 401006a0 2c9f0300 4000050c 40227611
3ffffc60: 401038c8 401005f8 3fffc270 4000050c
3ffffc70: 401006a0 00000030 0000001c ffffffff
3ffffc80: 402358c4 401005f8 3fffc270 4000050c
3ffffc90: 00000000 00000000 0000001f 40100724
3ffffca0: 4022fdf2 00002000 3fffc228 401064b5
3ffffcb0: 4000050c 00002000 00000429 00000100
3ffffcc0: 00000100 00000030 00000017 ffffffff
3ffffcd0: 4023266c 00000002 00010000 00000100
3ffffce0: 401006a0 3fff1ebc 00338400 4022e29e
3ffffcf0: 00000000 00000000 0000001f 40100724
3ffffd00: 00000100 00000030 3fffc228 401064b5
3ffffd10: 00000005 3ffffd50 3fff22b0 00000100
3ffffd20: 00000100 3fff20e4 00344000 4022e29e
3ffffd30: 00344000 3fff1e94 3fff17b4 4022bf60
3ffffd40: 3fff17b4 00038400 00000384 40232723
3ffffd50: 00000100 3fff1c94 3fff20d0 00000000
3ffffd60: 4022bf58 00000003 3ffffe10 00000000
3ffffd70: 00000100 00388014 3fff08a4 3fff17b4
3ffffd80: 3fff17b4 00000000 00000100 4022fdce
3ffffd90: 00000100 00000e6c 00000000 00000001
3ffffda0: 00000022 00000080 4022f684 00000000
3ffffdb0: 00000000 3fff1c94 00008003 00044000
3ffffdc0: 00000000 3ffffe00 00000128 00000000
3ffffdd0: 401006a0 00000030 3fffc228 00000161
3ffffde0: 3ffffe40 00000003 3fff17b4 402302a2
3ffffdf0: 00000000 3ffffe10 3ffffe00 3ffffe04 <
3ffffe00: 0000001c 00000003 00000005 3ffffef4
3ffffe10: 00000003 00000000 3fff1dcc 00000160
3ffffe20: fffff6d0 00000001 00000001 00000161
3ffffe30: 00015bf6 00000003 3fff17b4 40232024
3ffffe40: 40000384 00000030 00000010 401005f8
3ffffe50: 3fff1dcc 00015a1b 00000161 3fff3655
3ffffe60: 3fff1b94 00000002 00015a02 000001f4
3ffffe70: 3fff1dcc 4025cc45 00000000 000001f4
3ffffe80: 0002cc42 00000000 3fff17b4 4022e505
3ffffe90: 3fff1dcc 3fffdab0 00000000 3fffdad0
3ffffea0: 3fff363c 00000030 00000000 fffffffe
3ffffeb0: ffffffff 3fffc6fc 00000001 00000001
3ffffec0: 00000001 3fff24c4 3fff24b4 4022ec1e
3ffffed0: 00000001 3fff24fc 3fff24b4 4022c2c4
3ffffee0: 00000000 3fffdad0 3fff08d0 402374ec
3ffffef0: 0a910a91 aab556aa 3fff08d0 40226448
3fffff00: 40227bf4 3fff0704 3ffe8ac0 4023723c
3fffff10: 40227bf4 3fff0704 3ffe8ac0 3ffef454
3fffff20: 00000001 3fff24c4 3fff24b4 402266ac
3fffff30: 3ffef7a8 5ed8fc37 3ffef860 3ffef67c
3fffff40: 000000d3 00000000 000000d3 4020427e
3fffff50: 00000000 0189374b 3ffef8c0 40235f66
3fffff60: 00000001 00000000 3ffef8c0 40100101
3fffff70: 00000001 00000000 3ffef8c0 4020500a
3fffff80: 00000000 00000000 00000001 3fff08d0
3fffff90: 3fffdad0 00000000 3fffdab0 40205049
3fffffa0: 3fffdad0 00000000 3fffdab0 4022b03e
3fffffb0: feefeffe feefeffe feefeffe 40101739
<<<stack<<<
0x40100a28 in interrupt_handler at /home/silas/.platformio/packages/framework-arduinoespressif8266/cores/esp8266/core_esp8266_wiring_digital.cpp:144
0x40100add in esp8266::InterruptLock::~InterruptLock() at /home/silas/.platformio/packages/framework-arduinoespressif8266/cores/esp8266/interrupts.h:29
(inlined by) interrupt_handler at /home/silas/.platformio/packages/framework-arduinoespressif8266/cores/esp8266/core_esp8266_wiring_digital.cpp:154
0x40242fc8 in netif_do_set_ipaddr at /local/users/gauchard/arduino/arduino_esp8266/origin/tools/sdk/lwip2/builder/lwip2-src/src/core/netif.c:490
0x402584f2 in wpa_receive at ??:?
0x401006a0 in i2s_slc_isr at /home/silas/.platformio/packages/framework-arduinoespressif8266/cores/esp8266/core_esp8266_i2s.cpp:194
0x401009ec in interrupt_handler at /home/silas/.platformio/packages/framework-arduinoespressif8266/cores/esp8266/core_esp8266_wiring_digital.cpp:135
0x401006a0 in i2s_slc_isr at /home/silas/.platformio/packages/framework-arduinoespressif8266/cores/esp8266/core_esp8266_i2s.cpp:194
0x401005f8 in i2s_slc_isr at /home/silas/.platformio/packages/framework-arduinoespressif8266/cores/esp8266/core_esp8266_i2s.cpp:167
0x401005f8 in i2s_slc_isr at /home/silas/.platformio/packages/framework-arduinoespressif8266/cores/esp8266/core_esp8266_i2s.cpp:167
0x40107070 in spi_flash_read at ??:?
0x40100779 in __wrap_spi_flash_read at /home/silas/.platformio/packages/framework-arduinoespressif8266/cores/esp8266/core_esp8266_phy.cpp:320
0x40227575 in EspClass::flashRead(unsigned int, unsigned int*, unsigned int) at /home/silas/.platformio/packages/framework-arduinoespressif8266/cores/esp8266/Esp.cpp:932
0x40107070 in spi_flash_read at ??:?
0x40100724 in ets_post at /home/silas/.platformio/packages/framework-arduinoespressif8266/cores/esp8266/core_esp8266_main.cpp:238
0x40100779 in __wrap_spi_flash_read at /home/silas/.platformio/packages/framework-arduinoespressif8266/cores/esp8266/core_esp8266_phy.cpp:320
0x40105c1b in lmacRxDone at ??:?
0x40227575 in EspClass::flashRead(unsigned int, unsigned int*, unsigned int) at /home/silas/.platformio/packages/framework-arduinoespressif8266/cores/esp8266/Esp.cpp:932
0x4010350f in rcReachRetryLimit at ??:?
0x40227611 in EspClass::flashRead(unsigned int, unsigned char*, unsigned int) at /home/silas/.platformio/packages/framework-arduinoespressif8266/cores/esp8266/Esp.cpp:911
0x401036ec in rcReachRetryLimit at ??:?
0x40107070 in spi_flash_read at ??:?
0x40100779 in __wrap_spi_flash_read at /home/silas/.platformio/packages/framework-arduinoespressif8266/cores/esp8266/core_esp8266_phy.cpp:320
0x40227575 in EspClass::flashRead(unsigned int, unsigned int*, unsigned int) at /home/silas/.platformio/packages/framework-arduinoespressif8266/cores/esp8266/Esp.cpp:932
0x401006a0 in i2s_slc_isr at /home/silas/.platformio/packages/framework-arduinoespressif8266/cores/esp8266/core_esp8266_i2s.cpp:194
0x40227611 in EspClass::flashRead(unsigned int, unsigned char*, unsigned int) at /home/silas/.platformio/packages/framework-arduinoespressif8266/cores/esp8266/Esp.cpp:911
0x401038c8 in wDev_ProcessFiq at ??:?
0x401005f8 in i2s_slc_isr at /home/silas/.platformio/packages/framework-arduinoespressif8266/cores/esp8266/core_esp8266_i2s.cpp:167
0x401006a0 in i2s_slc_isr at /home/silas/.platformio/packages/framework-arduinoespressif8266/cores/esp8266/core_esp8266_i2s.cpp:194
0x402358c4 in Twi::write_bit(bool) at /home/silas/.platformio/packages/framework-arduinoespressif8266/cores/esp8266/core_esp8266_si2c.cpp:323
0x401005f8 in i2s_slc_isr at /home/silas/.platformio/packages/framework-arduinoespressif8266/cores/esp8266/core_esp8266_i2s.cpp:167
0x40100724 in ets_post at /home/silas/.platformio/packages/framework-arduinoespressif8266/cores/esp8266/core_esp8266_main.cpp:238
0x4022fdf2 in spiffs_obj_lu_find_entry_visitor at /home/silas/.platformio/packages/framework-arduinoespressif8266/cores/esp8266/spiffs/spiffs_nucleus.cpp:173
0x401064b5 in ets_timer_disarm at ??:?
0x4023266c in spiffs_phys_rd at /home/silas/.platformio/packages/framework-arduinoespressif8266/cores/esp8266/spiffs/spiffs_cache.cpp:135
0x401006a0 in i2s_slc_isr at /home/silas/.platformio/packages/framework-arduinoespressif8266/cores/esp8266/core_esp8266_i2s.cpp:194
0x4022e29e in flash_hal_read at /home/silas/.platformio/packages/framework-arduinoespressif8266/cores/esp8266/flash_hal.cpp:36
0x40100724 in ets_post at /home/silas/.platformio/packages/framework-arduinoespressif8266/cores/esp8266/core_esp8266_main.cpp:238
0x401064b5 in ets_timer_disarm at ??:?
0x4022e29e in flash_hal_read at /home/silas/.platformio/packages/framework-arduinoespressif8266/cores/esp8266/flash_hal.cpp:36
0x4022bf60 in spiffs_impl::SPIFFSImpl::spiffs_hal_read(unsigned int, unsigned int, unsigned char*) at /home/silas/.platformio/packages/framework-arduinoespressif8266/cores/esp8266/spiffs_api.h:343
0x40232723 in spiffs_phys_rd at /home/silas/.platformio/packages/framework-arduinoespressif8266/cores/esp8266/spiffs/spiffs_cache.cpp:163
0x4022bf58 in spiffs_impl::SPIFFSImpl::spiffs_hal_read(unsigned int, unsigned int, unsigned char*) at /home/silas/.platformio/packages/framework-arduinoespressif8266/cores/esp8266/spiffs_api.h:342
0x4022fdce in spiffs_obj_lu_find_entry_visitor at /home/silas/.platformio/packages/framework-arduinoespressif8266/cores/esp8266/spiffs/spiffs_nucleus.cpp:168
0x4022f684 in spiffs_obj_lu_find_id_and_span_v at /home/silas/.platformio/packages/framework-arduinoespressif8266/cores/esp8266/spiffs/spiffs_nucleus.cpp:509
0x401006a0 in i2s_slc_isr at /home/silas/.platformio/packages/framework-arduinoespressif8266/cores/esp8266/core_esp8266_i2s.cpp:194
0x402302a2 in spiffs_obj_lu_find_id_and_span at /home/silas/.platformio/packages/framework-arduinoespressif8266/cores/esp8266/spiffs/spiffs_nucleus.cpp:539 (discriminator 4)
0x40232024 in spiffs_object_read at /home/silas/.platformio/packages/framework-arduinoespressif8266/cores/esp8266/spiffs/spiffs_nucleus.cpp:2014
0x401005f8 in i2s_slc_isr at /home/silas/.platformio/packages/framework-arduinoespressif8266/cores/esp8266/core_esp8266_i2s.cpp:167
0x4025cc45 in cont_continue at /home/silas/.platformio/packages/framework-arduinoespressif8266/cores/esp8266/cont.S:51
0x4022e505 in spiffs_hydro_read at /home/silas/.platformio/packages/framework-arduinoespressif8266/cores/esp8266/spiffs/spiffs_hydrogen.cpp:417
0x4022ec1e in SPIFFS_read at /home/silas/.platformio/packages/framework-arduinoespressif8266/cores/esp8266/spiffs/spiffs_hydrogen.cpp:430
0x4022c2c4 in spiffs_impl::SPIFFSFileImpl::read(unsigned char*, unsigned int) at /home/silas/.platformio/packages/framework-arduinoespressif8266/cores/esp8266/spiffs_api.h:395 (discriminator 1)
0x402374ec in fs::File::read(unsigned char*, unsigned int) at /home/silas/.platformio/packages/framework-arduinoespressif8266/cores/esp8266/FS.cpp:73
0x40226448 in AudioFileSourceFS::read(void*, unsigned int) at .pio/libdeps/d1_mini_debug/ESP8266Audio/src/AudioFileSourceFS.cpp:49
0x40227bf4 in HardwareSerial::write(unsigned char const*, unsigned int) at /home/silas/.platformio/packages/framework-arduinoespressif8266/cores/esp8266/HardwareSerial.h:191
0x4023723c in AudioGeneratorWAV::GetBufferedData(int, void*) at .pio/libdeps/d1_mini_debug/ESP8266Audio/src/AudioGeneratorWAV.cpp:67 (discriminator 4)
0x40227bf4 in HardwareSerial::write(unsigned char const*, unsigned int) at /home/silas/.platformio/packages/framework-arduinoespressif8266/cores/esp8266/HardwareSerial.h:191
0x402266ac in AudioGeneratorWAV::loop() at .pio/libdeps/d1_mini_debug/ESP8266Audio/src/AudioGeneratorWAV.cpp:98
0x4020427e in loopAudio() at src/main.cpp:470
0x40235f66 in std::_Function_handler<void (), void (*)()>::_M_invoke(std::_Any_data const&) at /home/silas/.platformio/packages/toolchain-xtensa/xtensa-lx106-elf/include/c++/10.3.0/bits/std_function.h:293
0x40100101 in std::function<void ()>::operator()() const at /home/silas/.platformio/packages/toolchain-xtensa/xtensa-lx106-elf/include/c++/10.3.0/bits/std_function.h:623
0x4020500a in Scheduler::execute() at .pio/libdeps/d1_mini_debug/TaskScheduler/src/TaskScheduler.h:1554
0x40205049 in loop at src/main.cpp:303
0x4022b03e in loop_wrapper() at /home/silas/.platformio/packages/framework-arduinoespressif8266/cores/esp8266/core_esp8266_main.cpp:258
0x40101739 in cont_wrapper at /home/silas/.platformio/packages/framework-arduinoespressif8266/cores/esp8266/cont.S:81
So I think it's a problem with the TaskShoot.isEnabled method.
Possible. Can you try and get rid of it? Just restart (for now).
I did and I had the same problem, but when I make the Task::isEnabled function an IRAM_ATTR as well as the TASK::restart function and the Task::enable functions the crash is getting really rare. So it seems that I have to make all the functions or methods IRAM_ATTR.
I thought about that - I will have to make it specific to ESP chips - this is not a problem on other architectures where the code is in memory all the time. For now - go ahead and modify the library until I come up with a perm solution. I hit the same issue on esp32 for one of my projects - so this needs to be fixed.
Ok thank you
BTW it seems like the _task_millis() function needs to be in IRAM as well.
That's just crazy - but ok! Seems line esp8266 is a lot more sensitive - esp32 does not have those issues.
just verified - esp32 millis()
implementation is already IRAM_ATTR
So I added the IRAM_ATTR to the isEnabled and other TaskScheduler functions. Sadly I noticed another problem: I'm using painlessmesh and as soon as I connect to another device in the mesh the ESP crashes this time with this exception:
Panic core_esp8266_main.cpp:191 __yield
>>>stack>>>
ctx: sys
sp: 3fffff50 end: 3fffffb0 offset: 0010
3fffff60: 00000000 00000000 3ffef8d0 4022b059
3fffff70: 00000000 00000000 3ffef8d0 40205097
3fffff80: 00000000 00000000 00000001 3fff08e0
3fffff90: 3fffdad0 00000000 3fffdab0 402050bf
3fffffa0: 3fffdad0 00000000 3fffdab0 4022b14e
<<<stack<<<
0x4022b059 in yield at ??:?
0x40205097 in Scheduler::execute() at .pio/libdeps/d1_mini_debug/TaskScheduler/src/TaskScheduler.h:1480
0x402050bf in loop at src/main.cpp:311
0x4022b14e in loop_wrapper() at /home/silas/.platformio/packages/framework-arduinoespressif8266/cores/esp8266/core_esp8266_main.cpp:258
What I think is happening (but could also be anything else) is that when the ESP connects to the mesh there are new Tasks created and because the methods from all these are in IRAM it overflows and the ESP crashes.
Or delay()
is called from an ISR function.
I recently prefer to not do much in the ISRs at all - just set some volatile variable and restart an ISR servicing task that runs immediately - that way you are out of the interrupt context. If fast reaction is required - use layered priority to make sure isr servicing task is always scheduled next
On Aug 14, 2024, at 2:05 PM, Anatoli Arkhipenko @.***> wrote:
I recently prefer to not do much in the ISRs at all - just set some volatile variable and restart an ISR servicing task that runs immediately - that way you are out of the interrupt context.
This has been the best practice for as long as I can remember, going back to the mid-1970s.
That said there are some cases where people have reenable interrupts from within the ISR but that is just asking for trouble that is VERY hard to debug.
So should I create another Task that is started instantly from the interrupt like
//interrupt handler
void IRAM_ATTR onShoot(){
TaskHandleInterrupt.restart();
}
or just set a volatile variable and check if it changed in a Task?
I think I fixed it now, the reason for the crash was that painlessmesh doesn't work in debug builds aka build_mode = debug.
So should I create another Task that is started instantly from the interrupt like
Yes, you can do that, OR, if you want to check for stray events from time to time you can create a task that runs every N seconds (for instance) and, if running on a schedule checks for stray events (you need to figure out how). For the true interrupts:
//interrupt handler
volatile bool intOccurred = false;
void IRAM_ATTR onShoot(){
intOccurred = true;
TaskHandleInterrupt.forceNextIteration();
}
Hey, first off thanks for this great library, I personally really love it. Sadly I have a problem. I've built a Lasertag program for the ESP8266 and I'm using TaskScheduler in it. I have an ISR that gets triggered when a button ist pressed:
The TaskCallback is the following:
The callback is pretty complex because there are full-auto burst and semi-automatic weapons. So to make it short: the Task Callback sends an IR-packet and checks if the task should stay enabled to keep shooting or disables it self.
The Problem is when you keep pressing the shoot-button the ESP8266 will crash with the following exception:
The full source code of my project can be found here.
Thank you for you're help.