-
Notifications
You must be signed in to change notification settings - Fork 7.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Resolve hardware timer functions not in IRAM, crashes when called from ISR #4684
Conversation
@crankyoldgit subscribing so I know when I can remove my ugly hack. |
I am a bit divided between this and actually not running the ISR in IRAM at all (which will be the default approach in the upcoming 2.0.0). Placing more stuff in IRAM can cause issues with WiFi and BT code that is placed there (running out of IRAM space). Will merge this for now, but expect soon to run all interrupts out of IRAM. |
@me-no-dev Can you please elaborate on this (or point to a discussion somewhere) please? Also, so I know when I can remove my hack in IRremoteESP8266, what be the next release version of core that will include this merge? |
I'll add to be clear, I can't make this timer call outside of an ISR. i.e. I'm familiar with setting a flag via an ISR, exiting, and then having non-IRAM code act accordingly later etc. |
Hi @me-no-dev - thanks for taking a look at this, and noted on my TODO list to look at the impacts of moving ISRs out of IRAM (at least for the ESP32 family). Arduino/esp8266 core requires ISRs to be in IRAM so I hadn't considered running outside of IRAM for ESP32. In the case of dscKeybusInterface, the timer functions are getting called from a GPIO edge interrupt ISR every 500us (the external clock signal), which trigger a timer interrupt 250us later. If the timer interrupt is delayed by more than 250us, the data will be corrupt so I'll need to see what would happen in the case of a flash cache miss. Some of the implementations of this library use ESPAsyncWebServer (thank you for this!) and SPIFFS - would a non-IRAM ISR be reliable in this scenario? xTaskNotifyFromISR() and such wouldn't help if the data itself isn't captured in time by the ISR. |
FYI I found a way to have ISR function in IRAM for timers and at the same time run concurrent flash operations, by redefining some of the gtimer calls to be lined. I am using that in the project: https://github.com/mathieucarbou/MycilaPulseAnalyzer which is a pulse analyser for ZCD circuits and ZC event trigger. So it deals with ISR, gpio interrupts and timer interrupts, all in IRAM on Arduino. There are 2 examples showing that, with also concurrent operations, which, of course crash if I use the Arduino API or ESP-IDF gtimer library directly. |
Hi folks,
As seen in crankyoldgit/IRremoteESP8266#1350 and taligentx/dscKeybusInterface#80, the Arduino/esp32 hardware timer functions are currently not in IRAM and cause crashes when called from an ISR:
I've run across this issue when using ESPAsyncWebServer and Blynk with my library (dscKeybusInterface). The library uses a GPIO pin change interrupt to catch a clock signal, and that ISR triggers a timer interrupt to read data from a different GPIO after 250us. This works fine with Arduino/AVR and esp8266, but calling
timerStart()
andtimerStop()
on Arduino/esp32 results in the above crash, and is resolved by placing these functions in IRAM.For reference, Arduino/esp8266 places its hardware timer functions in IRAM: https://github.com/esp8266/Arduino/blob/master/cores/esp8266/core_esp8266_timer.cpp
The current workaround in the IRremoteESP8266 library bypasses the Arduino esp32 core functions and redefines
hw_timer_t
andhw_timer_reg_t
so its ISR can configure the timers directly: crankyoldgit/IRremoteESP8266#1351It'd be great to be able to avoid these kinds of workarounds - thanks!