Tensor arena is too small for the exported model on ESP32-S3-EYE. The default arena size (492352 bytes) causes a StoreProhibited crash immediately because the model tries to allocate a persistent buffer of 323200 bytes that doesn’t fit. When the arena is moved to PSRAM using heap_caps_malloc, a CORRUPT HEAP crash occurs instead.
Project ID: 1041663
Context/Use case:
Real-time forest fire detection using the ESP32-S3-EYE camera module. The camera captures frames and runs image classification inference continuously. The model uses 160x160 RGB input with 2 output classes (fire / no fire).
Steps Taken:
- Exported Arduino library from Edge Impulse and flashed the
esp32_cameraexample sketch to ESP32-S3-EYE - Observed crash:
ERR: Failed to allocate persistent buffer of size 576, does not fit in tensor arena and reached EI_MAX_OVERFLOW_BUFFER_COUNTfollowed byGuru Meditation Error: Core 1 panic'ed (StoreProhibited) - Confirmed PSRAM is available and working:
PSRAM size: 8388608, Free PSRAM: 8384768 - Increased
kTensorArenaSizeintflite_learn_1041663_8_compiled.cppto 700000 — crash changed, now showsERR: Failed to allocate persistent buffer of size 323200repeatedly until PSRAM runs out (arena was being allocated fresh each loop without being freed) - Added
if (!tensor_arena)guard to prevent re-allocation each loop, and changed allocation toheap_caps_malloc(kTensorArenaSize, MALLOC_CAP_SPIRAM)with#include "esp_heap_caps.h"at top of file - Increased
kTensorArenaSizeto 1500000 — arena allocates successfully in PSRAM (ptr valid, free PSRAM confirms allocation) but crashes withCORRUPT HEAP: Bad head at 0x3c29e104. Expected 0xabba1234 got 0x00000000 - Tried increasing
EI_CLASSIFIER_TFLITE_LARGEST_ARENA_SIZEinmodel_metadata.hto 1500000 — no effect onkTensorArenaSize - Tried increasing
EI_MAX_OVERFLOW_BUFFER_COUNTto 64 in bothei_classifier_porting.handtflite_learn_1041663_8_compiled.cpp— no resolution
Expected Outcome:
The model initializes successfully, camera captures frames, and inference runs continuously producing fire/no fire classification results.
Actual Outcome:
Either a StoreProhibited crash when arena is too small, or a CORRUPT HEAP crash when arena is placed in PSRAM. The device reboots in an infinite loop in both cases.
Reproducibility:
- Always
Environment:
- Platform: ESP32-S3-EYE (8MB PSRAM, OV2640 camera)
- Build Environment: Arduino IDE 1.8.19, ESP32 Arduino Core 3.3.10
- OS Version: Windows 10
- Edge Impulse Version: Check
EI_STUDIO_VERSIONinmodel_metadata.h - Project Version: Deploy version 6
- Custom Blocks / Impulse Configuration: Image classification, 160x160 RGB input, 2 classes (fire, no fire), EON compiled model, INT8 quantization, no anomaly detection
Logs:
Default arena size crash:
ERR: Failed to allocate persistent buffer of size 576, does not fit in tensor arena and reached EI_MAX_OVERFLOW_BUFFER_COUNT
Guru Meditation Error: Core 1 panic'ed (StoreProhibited). Exception was unhandled.
EXCVADDR: 0x00000000
After moving arena to PSRAM with 1500000 bytes:
Arena size requested: 1500000, ptr: 0x3c12e108, free PSRAM: 6627168
CORRUPT HEAP: Bad head at 0x3c29e104. Expected 0xabba1234 got 0x00000000
assert failed: multi_heap_free multi_heap_poisoning.c:279 (head != NULL)
Additional Information:
The board has 8MB PSRAM which is confirmed working. The issue appears to be that CMSIS-NN optimized kernels used on ESP32-S3 write scratch buffers expecting internal RAM alignment/access patterns, causing heap corruption when the arena is placed in PSRAM. The ei_calloc calls inside AllocatePersistentBufferImpl for overflow buffers may also need to use PSRAM. What is the officially supported method to use PSRAM for the tensor arena with EON compiled models on ESP32-S3?
