esp32-heap-discipline

Featured

Memory-allocation discipline for AgentDeck ESP32 firmware (esp32/). Use whenever writing or reviewing firmware code that allocates — new / malloc / ps_malloc / heap_caps_alloc / std::vector / std::string / String / a buffer / a cache / anything held across a render loop. Covers the PSRAM-vs-no-PSRAM board split, the allocation decision order, fragmentation avoidance, the makeUniqueNoThrow / ScopedCleanup helpers, the PROTOCOL_MAX_MSG_BYTES JSON guard, and the heap diagnostics (logHeap / [PERF] freeblk).

AI & Automation 232 stars 47 forks Updated today MIT

Install

View on GitHub

Quality Score: 89/100

Stars 20%
79
Recency 20%
100
Frontmatter 20%
70
Documentation 15%
100
Issue Health 10%
50
License 10%
100
Description 5%
100

Skill Content

# ESP32 Heap Discipline Memory rules for `esp32/` firmware. Adapted from crosspoint-reader's `heap-discipline` skill to AgentDeck's multi-board reality. This is the procedure you run while writing firmware and the gate before handing it back. ## The board split — know which world you're in AgentDeck firmware targets two memory regimes. Check the board macros first. - **PSRAM boards** — `BOARD_BOX_86`, `BOARD_IPS35`, `BOARD_AMOLED`, `BOARD_IPS10` (ESP32-S3 / -P4, 8–32MB PSRAM). Large canvases/caches go in PSRAM (`ps_malloc` / `MALLOC_CAP_SPIRAM`). **But** per-pixel / LVGL draw buffers and PPA rotation buffers must stay in **internal SRAM** (`MALLOC_CAP_INTERNAL`): PSRAM writes are ~30× slower, so a PSRAM draw buffer makes every widget render crawl (see the IPS10 rationale in `esp32/src/ui/display.cpp`). Plenty of total RAM here; the constraint is *write latency and internal-SRAM headroom*, not bytes. - **No-PSRAM boards** — `BOARD_TTGO` (classic ESP32, ~160KB heap), `BOARD_ESP32_C6_147` (single-core RISC-V), `BOARD_LED8X32` (TC001). This is crosspoint's world: every allocation matters and **fragmentation, not total usage, is what kills the device.** Free heap can read fine while the largest free block is too small for the next alloc. Optimize for not leaving holes. The canvas/buffer code already encodes this split (`renderer.cpp::init` uses static pre-allocated buffers on TTGO/C6 and `ps_malloc`+SRAM fallback elsewhere). Match the existing pattern; d...

Details

Author
puritysb
Repository
puritysb/AgentDeck
Created
6 months ago
Last Updated
today
Language
TypeScript
License
MIT

Similar Skills

Semantically similar based on skill content — not just same category

Code & Development Listed

memory-management-guide

Use when deciding how memory is allocated, owned, and freed in manual-memory or buffer-passing code, in any language. Triggers on prompts about caller-owns-memory / caller-provided buffers, arena/bump/linear allocators, object pools and free lists, virtual-memory reserve/commit, scratch/temp allocators, object lifetimes, ownership (single-owner/borrow), leaks/use-after-free/double-free, even when the user doesn't say 'memory' or 'allocator'.

5 Updated 4 days ago
xonovex
Code & Development Listed

esp32-expert

This skill should be used when the user is writing, reviewing, debugging, or architecting C++ firmware for ESP32 and variants (ESP32-S2, S3, C3, C5, C6, H2, P4) using ESP-IDF or PlatformIO. Provides expert critique covering FreeRTOS task design, memory management (IRAM/DRAM/PSRAM), peripheral drivers (I2C/SPI/UART/GPIO), build systems (CMake/platformio.ini), power management, OTA updates, and embedded C++ best practices. Use when the user asks "review my ESP32 code", "fix FreeRTOS crash", "optimize memory usage", "debug I2C issue", "set up PlatformIO project", "review my CMakeLists", "search datasheet for this chip", "why is my task crashing", "configure deep sleep", or "help with ESP-IDF component structure".

11 Updated 2 weeks ago
johnkozaris
Code & Development Listed

esp32-expert

This skill should be used when the user is writing, reviewing, debugging, or architecting C++ firmware for ESP32 and variants (ESP32-S2, S3, C3, C6, H2, P4) using ESP-IDF or PlatformIO. Provides expert critique covering FreeRTOS task design, memory management (IRAM/DRAM/PSRAM), peripheral drivers (I2C/SPI/UART/GPIO), build systems (CMake/platformio.ini), power management, OTA updates, and embedded C++ best practices. Use when the user asks "review my ESP32 code", "fix FreeRTOS crash", "optimize memory usage", "debug I2C issue", "set up PlatformIO project", "review my CMakeLists", "search datasheet for this chip", "why is my task crashing", "configure deep sleep", or "help with ESP-IDF component structure".

3 Updated yesterday
mathisk2095