-
Notifications
You must be signed in to change notification settings - Fork 29
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
ESP32 - IRAM interrupts #44
Comments
Thanks for the observation. I had replaced the IRAM_ATTR with Given the current implementation, I except possible "long latency" but no crashes. I don't know how much this latency can be. As you point out, I may replace all Arduino HAL calls with "native" low-level calls about timers and GPIOs, but it will require some effort. I can consider it. |
Using IRAM_ATTR or ARDUINO_ISR_IRAM on an interrupt is pretty much useless if the interrupt itself is calling even a single non IRAM function. The ESP_INTR_FLAG_IRAM is there to place the interrupt handler in IRAM as well. The doc says the ARDUINO_ISR_IRAM flag makes some HAL function, like digitalRead/Write and more to be loaded into IRAM. Looking at the Arduino sources, What's disturbing is that the hal functions All the code from Espressif are using interrupts with code executed exclusively from IRAM.
Some discussions on the subject: |
The routine will be called 100 times/second if AC@50Hz, so it will stay in IRAM very probably and you won't have problems. The same for the other ISRs. If your firmware performs a lot of flash operations will have sporadic huge latencies, and this is bad. About timer_ll.h gpio_ll.h Hence, there is a chance to code an optimized version which stays in IRAM despite the Arduino config. |
You're right, sorry i meant to say that one inherits the IRAM attribute while the other (Arduino) doesn't. |
FYI I have extracted a ZCD I am using for YaSolR (solar diverter) to https://github.com/mathieucarbou/MycilaPulseAnalyzer I've managed to recreated some inlined versions of gptimer calls: they are isolated in a header. ( Thanks to that I am able to compile the examples with
And have all the ISR code loaded into IRAM. The 2 examples are doing concurrent flash (nvs) operations to prove that there is no crash anymore (before, a crash would happen immediately or after a few seconds). This is not as optimised as the code @florentbr has done (triac_timer.cpp, which inspried me a lot), but it it far less complex to use eventually in a project like dimmable light. Also, using gpio_ll instead of arduino GPUI functions is quite svraitworward. Note: my library only work with Arduino >= 3 and esp32 boards. |
I noticed that the current implementation uses non IRAM functions in the ESP32 interrupts :
dimmable-light/src/hw_timer_esp32.cpp
Lines 39 to 56 in 21edb0d
All the interrupt code needs to be placed into IRAM to avoid long latency or crash when the flash is locked.
https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/system/intr_alloc.html#iram-safe-interrupt-handlers
Either replace the timer functions with specific isr timer functions from
timer.h
:timer_group_set_alarm_value_in_isr(...) timer_group_set_counter_enable_in_isr(...) timer_group_enable_alarm_in_isr(...)
or with inlined low level functions from
timer_ll.h
:The text was updated successfully, but these errors were encountered: