Home › Embedded / firmware › ESP32 ESP-IDF firmware CLAUDE.md

ESP32 ESP-IDF firmware CLAUDE.md

CLAUDE.md for ESP32 firmware on ESP-IDF 5.x in C: components, FreeRTOS tasks, error handling, and logging.

Claude Code (CLAUDE.md)Embedded / firmware

How to use

Save this as CLAUDE.md in your repository root, commit it, and your agent will pick it up automatically. Edit the commands to match your project.

CLAUDE.mdDownload  
# CLAUDE.md: ESP-IDF firmware (ESP32)

## Commands
- `idf.py set-target esp32s3` (once) · `idf.py build` · `idf.py -p <PORT> flash monitor` (ask before flashing a device)
- Config: `idf.py menuconfig`; commit defaults in `sdkconfig.defaults`, not the generated `sdkconfig`.
- Host unit tests (where set up): `idf.py --preview set-target linux && idf.py build` or Unity tests in `test/`.

## Structure
- `main/` holds `app_main` wiring only. Features live in `components/<name>/` with `CMakeLists.txt` (`idf_component_register(... REQUIRES ...)`) and a public header in `include/`.
- External libs through the component manager (`idf_component.yml`), pinned versions.

## Code rules
- Every ESP-IDF call returning `esp_err_t` is checked: `ESP_ERROR_CHECK` only during init where a reboot is acceptable; otherwise `ESP_RETURN_ON_ERROR`/`ESP_GOTO_ON_ERROR` and propagate.
- Logging with `ESP_LOGI/W/E(TAG, ...)` and a `static const char *TAG` per file. No `printf` in components.
- FreeRTOS: each task has a sized stack (check with `uxTaskGetStackHighWaterMark`), a priority with a reason, and blocks on queues/event groups/notifications instead of busy-waiting. Use `vTaskDelay(pdMS_TO_TICKS(ms))`.
- ISRs are short, marked `IRAM_ATTR`, use only `FromISR` APIs, and defer work to a task.
- Shared data is protected by a mutex or passed through queues; no unguarded globals across tasks.
- No dynamic allocation in hot loops; check `malloc`/`heap_caps_malloc` results.
- Wi-Fi/credentials come from NVS or provisioning, never hard-coded in source.

## Done
`idf.py build` has no new warnings and binary size is reported (`idf.py size`).

Related rules

AWS CDK (TypeScript) CLAUDE.md

CLAUDE.md for AWS CDK v2 apps in TypeScript: constructs, least-privilege grants, snapshot tests, and safe deploys.

Claude Code (CLAUDE.md)AWS CDK

Bun runtime CLAUDE.md

CLAUDE.md for TypeScript projects on Bun 1.2+: bun test, Bun.serve, built-in SQLite/Postgres, and bundling.

Claude Code (CLAUDE.md)Bun

Claude Agent SDK CLAUDE.md

CLAUDE.md for building agents with the Claude Agent SDK (Python/TypeScript): options, tools, permissions, and hooks.

Claude Code (CLAUDE.md)LLM apps & agents

Code reviewer subagent (Claude Code)

A Claude Code subagent definition that reviews the current diff for bugs, security, and tests, reporting by severity.

Claude Code (CLAUDE.md)Agent workflows

Get new rules weekly

One email a week: fresh rule files, agent tips, and what's changing in Cursor, Claude Code and Copilot. Free, unsubscribe anytime.

Opens the Rulestack Newsletter on beehiiv in a new tab. Or subscribe directly on beehiiv.