Does the Arduino library load its internal interrupts in IRAM on the ESP32
23:37 07 Aug 2025

When I've developed for the ESP32, I've always included the linker attribute IRAM_ATTR when I've declared functions called from interrupts. This is based on https://docs.espressif.com/projects/esp-idf/en/v4.2/esp32s2/api-guides/general-notes.html :

Interrupt handlers must be placed into IRAM if ESP_INTR_FLAG_IRAM is used when registering the interrupt handler. In this case, ISR may only call functions placed into IRAM or functions present in ROM

To better understand how attachInterrupt intRoutine callback is used.This std::function is called from an internal function:

static void ARDUINO_ISR_ATTR __onPinInterrupt(void * arg) {
    InterruptHandle_t * isr = (InterruptHandle_t*)arg;
    if(isr->fn) {
        if(isr->arg){
            ((voidFuncPtrArg)isr->fn)(isr->arg);
        } else {
            isr->fn();
        }
    }
}

Where ARDUINO_ISR_ATTR is defined as:

#if CONFIG_ARDUINO_ISR_IRAM
#define ARDUINO_ISR_ATTR IRAM_ATTR
#define ARDUINO_ISR_FLAG ESP_INTR_FLAG_IRAM
#else
#define ARDUINO_ISR_ATTR
#define ARDUINO_ISR_FLAG (0)
#endif

I'm not sure where CONFIG_ARDUINO_ISR_IRAM is set for the Arduino tool chain, but looking at the PlatformIO framework-arduinoespressif32/tools/sdk/esp32*/sdkconfig files, it does not appear to be set for any of them.

Does this mean that generally the Arduino interrupts aren't being loaded into the IRAM for ESP32 targets?

c++ arduino embedded esp32 arduino-esp32