Home › Embedded / firmware › Embedded C (bare metal / RTOS) AGENTS.md

Embedded C (bare metal / RTOS) AGENTS.md

AGENTS.md for embedded C firmware (bare metal, Zephyr, FreeRTOS): safety-minded C rules, memory, and hardware access.

AGENTS.mdEmbedded / firmware

How to use

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

Note: Review and test before use. Provided as is, without warranty. See Terms.

AGENTS.mdDownload  
# AGENTS.md: Embedded C firmware

## Commands
- Build: `cmake --preset <board> && cmake --build --preset <board>` (or `west build -b <board>` for Zephyr).
- Host tests: `ctest --preset host` (Unity/CMock or ztest on `native_sim`). Static analysis: `cppcheck --enable=warning,style src/` or clang-tidy if configured.
- Never flash or erase hardware from the agent unless asked.

## C rules (MISRA-inspired)
- C11/C17 with `-Wall -Wextra -Werror`. Fixed-width types (`uint32_t`) for hardware and protocol data; `bool` from `<stdbool.h>`.
- No dynamic allocation after init. Static buffers sized with named constants; check every bound.
- Every function returning a status is checked. Use an `enum` error type, not magic ints.
- `volatile` only for memory-mapped registers and variables shared with ISRs. Shared multi-byte data needs critical sections or atomics.
- No recursion, no variable-length arrays, no `goto` except a single cleanup label.
- Register access through the vendor HAL/CMSIS or the project's driver layer, not raw addresses scattered in app code.
- Interrupts: short handlers, clear flags, defer to tasks/main loop.
- Avoid floating point in ISRs and on MCUs without an FPU unless the project already uses it.

## Structure
- `drivers/` (hardware), `app/` (logic, hardware-independent so it's testable on host), `bsp/` (board config).

## Done
Clean build with zero warnings, host tests pass, and you report flash/RAM size changes from the map/size output.

More: all Embedded / firmware rules · all AGENTS.md rules

Related rules

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

Arduino / PlatformIO rules

Cursor rules for microcontroller projects with PlatformIO and the Arduino framework: non-blocking loops, memory, pins.

CursorEmbedded / firmware

Zig AGENTS.md

AGENTS.md for Zig 0.15 projects: build.zig, explicit allocators, error unions, defer cleanup, and zig test.

AGENTS.mdZig

Modern C++ with CMake rules

Cursor rules for modern C++ (C++20/23) projects built with CMake presets: RAII, ownership, warnings, and tests.

CursorC++

Solidity + Foundry Copilot path instructions

Path-specific Copilot instructions for Solidity 0.8.x contracts with Foundry: security patterns, fuzz tests, and gas.

GitHub CopilotSolidity / smart contracts

Solidity smart contract security CLAUDE.md

CLAUDE.md for reviewing and writing Solidity contracts safely: threat checklist, Foundry tests, and no-deploy rules.

Claude Code (CLAUDE.md)Solidity / smart contracts

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.