﻿# ESP32 IRAM safety covers the handler’s code and every accessed dependency

Placing an interrupt entry point in IRAM does not make flash-resident callees, constants or PSRAM data accessible while the cache is disabled. Review the complete path.

Author: Retrivium team
Updated: 2026-11-06
Canonical URL: https://retrivium.ai/journal/edge-esp32-iram-safe-transitive-code-data/
Language: en

## The entry function moved but the failure remained

A sensor callback supplies observations to a tiny local classifier. After adding periodic settings writes, the appliance occasionally reports a cache-access fault. The team moves the interrupt entry function into IRAM and considers the path repaired, but a helper or lookup table remains in flash. The location of the first function is only the beginning of the dependency review. Identify the complete interrupt-time path, keeping classification outside the handler unless its actual execution contract supports that placement.

## Safety is a property of all reachable code and data

The [interrupt-allocation guide](https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-reference/system/intr_alloc.html) says flash writes and erases disable the cache on the documented ESP32 path. IRAM-safe handlers must access internal code and data. The guide explicitly includes indirect function calls and read-only data; an IRAM entry calling a flash helper is not safe. ESP_INTR_FLAG_IRAM does not relocate dependencies automatically. Treat registration as a declaration the application must justify, rather than an annotation that converts arbitrary handler behavior into a supported path.

## A readable PSRAM pointer can become inaccessible

The [external-RAM restrictions](https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-guides/external-ram.html) also make PSRAM inaccessible when flash cache is disabled. A buffer successfully read during ordinary operation is therefore not proof of accessibility in that interval. Include callback context, descriptors and lookup data in the placement inventory, not only executable instructions. A pointer stored internally can still lead to external data. Keep this platform-specific restriction attached to the ESP32 target and build rather than generalizing it to every chip in the product family.

## Keep the interrupt-time work small and explainable

A proposed design limits the interrupt path to supported capture and handoff operations using resources whose placement is known. Review the linked map and reachable functions for the actual configuration; a source attribute alone cannot show where every dependency ended up. If the application instead accepts postponing a non-IRAM handler, document the resulting sampling or backlog consequence. These are different design choices. Do not remove the flag as a universal repair without checking whether delayed acquisition is acceptable.

## Accept placement and controlled overlap separately

On a recoverable development target, propose reviewing placement first, then exercising the supported flash-operation overlap with harmless sensor input. Preserve errors and input continuity evidence; avoid using a production acquisition path as the fault experiment. Acceptance requires the declared dependencies to remain accessible and the application’s chosen acquisition behavior to hold. No firmware was built, flashed or exercised here. Passing a small overlap fixture would not certify every interrupt branch, library configuration or future linker change.

## Do not confuse accessibility with coherency or capacity

[Explicit host/device buffer coherence](/journal/fg2-embree-sycl-explicit-host-device-buffer-coherence/) concerns whether views contain current data. [TinyML memory and energy boundaries](/journal/tinyml-memory-wall-inference-energy-sensor-boundary/) concern another resource question. Here the failure is whether the interrupt can access required code and data at all during a documented interval. Report that narrower contract and its evidence. Enough free RAM, a valid pointer and correct normal-mode outputs do not individually establish cache-disabled accessibility.
