#19154·esp-idf

Default event loop unexpectedly allocated in SPIRAM (IDFGH-18368)

Author: ljodalCreated Sep 29, 2026Updated Sep 30, 2026
LabelsType: BugStatus: Reviewing

Answers checklist.

  • I have read the documentation ESP-IDF Programming Guide and the issue is not addressed there.
  • I have updated my IDF branch (master or release) to the latest version and checked that the issue is present there.
  • I have searched the issue tracker for a similar issue and not found a similar issue.

IDF version.

v6.1

Espressif SoC revision.

ESP32-C5-N16R2 v1.2

Operating System used.

Linux

How did you build your project?

Command line with idf.py

If you are using Windows, please specify command line type.

No response

Development Kit.

Custom board

Power Supply used.

External 3.3V

What is the expected behavior?

With ESP_EVENT_LOOP_IN_EXT_RAM=f, ESP_EVENT_POST_FROM_IRAM_ISR=y and CONFIG_SPIRAM_USE_CAPS_ALLOC=y I expect the default event loop to be allocated in internal RAM.

What is the actual behavior?

The event loop (sometimes?) gets allocated in external SPIRAM, which causes a panic when accessed from an IRAM allocated interrupt handler.

When the ESP_EVENT_LOOP_IN_EXT_RAM option was added in https://github.com/espressif/esp-idf/commit/0c570d860d2a21d76790cce0887e133998c9eb30 the allocation function for the default loop was changed from calloc(...) to heap_caps_calloc(..., MALLOC_CAP_DEFAULT). According to the documentation for the CONFIG_SPIRAM_USE_CAPS_ALLOC flag MALLOC_CAP_DEFAULT includes PSRAM:

When enabled, memory is mapped to data virtual address space and also added to the capabilities-based heap memory allocator using MALLOC_CAP_SPIRAM. Since this memory is also tagged with MALLOC_CAP_DEFAULT, calls such as heap_caps_malloc(size, MALLOC_CAP_DEFAULT) can still return PSRAM pointers.

This means that even loop can be allocated in PSRAM regardless of the ESP_EVENT_POST_FROM_IRAM_ISR flag which is not checked in the esp_event_calloc function.

Steps to reproduce.

I'm not 100% sure, but this is what Claude suggests:

  1. Enable SPIRAM_USE_CAPS_ALLOC and the default ESP_EVENT_POST_FROM_IRAM_ISR.
  2. Call esp_event_isr_post() from an ESP_INTR_FLAG_IRAM GPIO ISR.
  3. Trigger that GPIO while an esp_partition_erase_range() is running. It panics with "Cache access error" at the configASSERT(pxQueue) in xQueueGenericSendFromISR.

Debug Logs.

plain

Diagnostic report archive.

No response

More Information.

I don't have a clean reproducer for this, so I'd rather not share memory dumps publicly. If it's needed I'd be happy to provide some privately