It 100% has something to do with the IRAM or how the compiler implements the update()
function. I found that even the very first line of update()
causes a crash. I replaced it with a simple “increment counter” logic and that still crashes.
What “fixes” the problem is if I follow Timer and Wifi: (Cache disabled but cached memory region accessed) (IDFGH-4322) · Issue #6164 · espressif/esp-idf · GitHub and remove the IRAM allocation flag
esp_intr_alloc(intr_source, (int)(/*ESP_INTR_FLAG_IRAM|*/ESP_INTR_FLAG_LOWMED|ESP_INTR_FLAG_EDGE), __timerISR, NULL, &intr_handle);
(in <home folder>\.platformio\packags\framework-arduinoespressif32\esp32-hal-timer.c
)
so that the interrupt will simply not be running when a flash programming operation is in place.
But that should not be necessary if all routines are ISR IRAM safe per Interrupt allocation - ESP32 - — ESP-IDF Programming Guide latest documentation. I don’t see where a flash access would be coming from.
I’ll see whether I can either find the issue or reproduce it in a minimal example to ask the Arduino-ESP32 people.