Embedded Architecture
Purpose
Design the firmware architecture for an embedded/IoT device, including RTOS selection, memory layout, power state machine, and task decomposition.
Scope Constraints
Analyzes hardware specifications, firmware requirements, and power budgets to produce architecture recommendations. Does not generate or compile firmware code. Does not interact with hardware debuggers or flash tools.
Inputs
- Target hardware (MCU, memory, peripherals, power source)
- Feature requirements (sensing, communication, actuation, UI)
- Power budget and battery life requirements
- Real-time constraints (latency, update frequency)
- Regulatory requirements (FCC, CE, safety)
Input Sanitization
No user-provided values are used in commands or file paths. All inputs are treated as read-only analysis targets.
Procedure
Step 1: Hardware Capability Assessment
Document the hardware constraints:
- MCU: Architecture (ARM Cortex-M, RISC-V, ESP32), clock speed, cores
- Memory: Flash size (code storage), SRAM size (runtime), external storage
- Peripherals: UART, SPI, I2C, ADC, PWM, timers, DMA channels
- Power source: Battery capacity, charging method, voltage regulators
- Radio: BLE, Wi-Fi, cellular, LoRa — power draw per mode
Step 2: Select RTOS or Bare-Metal
Decision framework:
- Bare-metal: < 3 concurrent tasks, no networking stack, simple timing requirements
- FreeRTOS: General-purpose, large ecosystem, good for most IoT applications
- Zephyr: Strong networking stack, Matter/Thread support, Linux Foundation backing
- NuttX: POSIX-compliant, good for complex applications with file systems
- Custom RTOS: Almost never justified — use an existing one
Step 3: Design Task Architecture
Decompose the firmware into tasks/threads:
- Sensor task: Read sensors at defined intervals, buffer data
- Communication task: Manage radio connection, send/receive data
- Application task: Process data, make decisions, trigger actuators
- Power management task: Monitor battery, manage sleep states
- OTA task: Check for updates, manage download and apply
Define priorities, stack sizes, and inter-task communication (queues, events, semaphores).
Step 4: Design Memory Layout
Plan memory allocation:
- Flash partitions: Application, OTA staging, file system, configuration
- RAM allocation: Task stacks, heap, DMA buffers, ring buffers
- Static vs dynamic allocation: Prefer static allocation — malloc on embedded systems is risky
- Stack overflow protection: Guard patterns, MPU regions
Step 5: Design Power State Machine
Define power modes and transitions:
- Active: Full speed, all peripherals on
- Low power: Reduced clock, unnecessary peripherals off
- Sleep: MCU sleeping, RTC running, wake on interrupt
- Deep sleep: Minimum power, RAM retention optional, slow wake-up
- Transitions: What triggers each transition, wake-up latency, power consumption per mode
Step 6: Design Watchdog and Recovery
Plan for failure recovery:
- Watchdog timer: Hardware watchdog with appropriate timeout
- Task health monitoring: Each task must pet a software watchdog
- Crash recovery: Save crash dump to flash, reboot, report crash on next connection
- Fail-safe defaults: If firmware is corrupted, boot into recovery/OTA mode
Progress Checklist
Compaction resilience: If context was lost during a long session, re-read the Inputs section to reconstruct what system is being analyzed, check the Progress Checklist for completed steps, then resume from the earliest incomplete step.
Output Format
# Embedded Architecture
## Hardware Summary
| Component | Specification | Constraint |
|-----------|--------------|------------|
| MCU | [Model] | [Clock, cores] |
| Flash | [Size] | [Partitioning plan] |
| SRAM | [Size] | [Allocation plan] |
| Battery | [Capacity] | [Target life: X months] |
## RTOS Selection
**Choice:** [RTOS name]
**Rationale:** [Why this RTOS for this hardware and requirements]
## Task Architecture
| Task | Priority | Stack Size | Rate | Description |
|------|----------|-----------|------|-------------|
| Sensor | High | 2KB | 1Hz | Read and buffer sensor data |
| Comms | Medium | 4KB | Event | BLE/MQTT communication |
| App | Medium | 2KB | On data | Process and decide |
| Power | Low | 1KB | 10s | Monitor and manage power states |
## Memory Layout
### Flash (Xkb)
| Partition | Start | Size | Purpose |
|-----------|-------|------|---------|
| Bootloader | 0x0000 | 32KB | Boot and OTA |
| App A | 0x8000 | 448KB | Active firmware |
| App B | 0x78000 | 448KB | OTA staging |
| NVS | 0xE8000 | 32KB | Configuration |
### RAM (Xkb)
| Region | Size | Purpose |
|--------|------|---------|
| Task stacks | 12KB | All task stacks |
| Heap | 8KB | Dynamic allocation (minimized) |
| DMA buffers | 4KB | Peripheral DMA |
## Power State Machine
[Active] --idle 5s--> [Low Power] --idle 30s--> [Sleep] --idle 5min--> [Deep Sleep]
^ ^ ^ |
|---sensor event--------|---BLE event-----------|---RTC alarm-----------|
| State | Power Draw | Wake Latency | Wake Sources |
|-------|-----------|-------------|--------------|
| Active | 50mA | — | — |
| Low Power | 5mA | <1ms | Any interrupt |
| Sleep | 500uA | 5ms | BLE, GPIO, timer |
| Deep Sleep | 10uA | 500ms | RTC alarm |
## Recovery Strategy
- [Watchdog configuration]
- [Crash dump approach]
- [Fail-safe boot mode]
Handoff
- Hand off to protocol-design if wireless protocol selection or stack design questions arise during firmware architecture work.
- Hand off to fleet-management if OTA update strategy or device provisioning concerns surface during embedded design.
Quality Checks
Evolution Notes
Converted and distributed by TomeVault — claim your Tome and manage your conversions.
1---2name: embedded-architecture3description: Use when designing firmware architecture for embedded or IoT devices. Covers RTOS selection, memory layout, power state machine, task decomposition, and watchdog recovery design. Do not use for wireless protocol selection (use protocol-design) or fleet-scale device management (use fleet-management).4---56# Embedded Architecture78## Purpose910Design the firmware architecture for an embedded/IoT device, including RTOS selection, memory layout, power state machine, and task decomposition.1112## Scope Constraints1314Analyzes hardware specifications, firmware requirements, and power budgets to produce architecture recommendations. Does not generate or compile firmware code. Does not interact with hardware debuggers or flash tools.1516## Inputs1718- Target hardware (MCU, memory, peripherals, power source)19- Feature requirements (sensing, communication, actuation, UI)20- Power budget and battery life requirements21- Real-time constraints (latency, update frequency)22- Regulatory requirements (FCC, CE, safety)2324## Input Sanitization2526No user-provided values are used in commands or file paths. All inputs are treated as read-only analysis targets.2728## Procedure2930### Step 1: Hardware Capability Assessment3132Document the hardware constraints:33- **MCU:** Architecture (ARM Cortex-M, RISC-V, ESP32), clock speed, cores34- **Memory:** Flash size (code storage), SRAM size (runtime), external storage35- **Peripherals:** UART, SPI, I2C, ADC, PWM, timers, DMA channels36- **Power source:** Battery capacity, charging method, voltage regulators37- **Radio:** BLE, Wi-Fi, cellular, LoRa — power draw per mode3839### Step 2: Select RTOS or Bare-Metal4041Decision framework:42- **Bare-metal:** < 3 concurrent tasks, no networking stack, simple timing requirements43- **FreeRTOS:** General-purpose, large ecosystem, good for most IoT applications44- **Zephyr:** Strong networking stack, Matter/Thread support, Linux Foundation backing45- **NuttX:** POSIX-compliant, good for complex applications with file systems46- **Custom RTOS:** Almost never justified — use an existing one4748### Step 3: Design Task Architecture4950Decompose the firmware into tasks/threads:51- **Sensor task:** Read sensors at defined intervals, buffer data52- **Communication task:** Manage radio connection, send/receive data53- **Application task:** Process data, make decisions, trigger actuators54- **Power management task:** Monitor battery, manage sleep states55- **OTA task:** Check for updates, manage download and apply5657Define priorities, stack sizes, and inter-task communication (queues, events, semaphores).5859### Step 4: Design Memory Layout6061Plan memory allocation:62- **Flash partitions:** Application, OTA staging, file system, configuration63- **RAM allocation:** Task stacks, heap, DMA buffers, ring buffers64- **Static vs dynamic allocation:** Prefer static allocation — malloc on embedded systems is risky65- **Stack overflow protection:** Guard patterns, MPU regions6667### Step 5: Design Power State Machine6869Define power modes and transitions:70- **Active:** Full speed, all peripherals on71- **Low power:** Reduced clock, unnecessary peripherals off72- **Sleep:** MCU sleeping, RTC running, wake on interrupt73- **Deep sleep:** Minimum power, RAM retention optional, slow wake-up74- **Transitions:** What triggers each transition, wake-up latency, power consumption per mode7576### Step 6: Design Watchdog and Recovery7778Plan for failure recovery:79- **Watchdog timer:** Hardware watchdog with appropriate timeout80- **Task health monitoring:** Each task must pet a software watchdog81- **Crash recovery:** Save crash dump to flash, reboot, report crash on next connection82- **Fail-safe defaults:** If firmware is corrupted, boot into recovery/OTA mode8384### Progress Checklist8586- [ ] Step 1: Hardware capability assessment complete87- [ ] Step 2: RTOS or bare-metal selection justified88- [ ] Step 3: Task architecture decomposed with priorities89- [ ] Step 4: Memory layout planned with partitions90- [ ] Step 5: Power state machine defined with transitions91- [ ] Step 6: Watchdog and recovery strategy designed9293> **Compaction resilience**: If context was lost during a long session, re-read the Inputs section to reconstruct what system is being analyzed, check the Progress Checklist for completed steps, then resume from the earliest incomplete step.9495## Output Format9697```markdown98# Embedded Architecture99100## Hardware Summary101| Component | Specification | Constraint |102|-----------|--------------|------------|103| MCU | [Model] | [Clock, cores] |104| Flash | [Size] | [Partitioning plan] |105| SRAM | [Size] | [Allocation plan] |106| Battery | [Capacity] | [Target life: X months] |107108## RTOS Selection109**Choice:** [RTOS name]110**Rationale:** [Why this RTOS for this hardware and requirements]111112## Task Architecture113| Task | Priority | Stack Size | Rate | Description |114|------|----------|-----------|------|-------------|115| Sensor | High | 2KB | 1Hz | Read and buffer sensor data |116| Comms | Medium | 4KB | Event | BLE/MQTT communication |117| App | Medium | 2KB | On data | Process and decide |118| Power | Low | 1KB | 10s | Monitor and manage power states |119120## Memory Layout121### Flash (Xkb)122| Partition | Start | Size | Purpose |123|-----------|-------|------|---------|124| Bootloader | 0x0000 | 32KB | Boot and OTA |125| App A | 0x8000 | 448KB | Active firmware |126| App B | 0x78000 | 448KB | OTA staging |127| NVS | 0xE8000 | 32KB | Configuration |128129### RAM (Xkb)130| Region | Size | Purpose |131|--------|------|---------|132| Task stacks | 12KB | All task stacks |133| Heap | 8KB | Dynamic allocation (minimized) |134| DMA buffers | 4KB | Peripheral DMA |135136## Power State Machine137```138[Active] --idle 5s--> [Low Power] --idle 30s--> [Sleep] --idle 5min--> [Deep Sleep]139 ^ ^ ^ |140 |---sensor event--------|---BLE event-----------|---RTC alarm-----------|141```142143| State | Power Draw | Wake Latency | Wake Sources |144|-------|-----------|-------------|--------------|145| Active | 50mA | — | — |146| Low Power | 5mA | <1ms | Any interrupt |147| Sleep | 500uA | 5ms | BLE, GPIO, timer |148| Deep Sleep | 10uA | 500ms | RTC alarm |149150## Recovery Strategy151- [Watchdog configuration]152- [Crash dump approach]153- [Fail-safe boot mode]154```155156## Handoff157158- Hand off to protocol-design if wireless protocol selection or stack design questions arise during firmware architecture work.159- Hand off to fleet-management if OTA update strategy or device provisioning concerns surface during embedded design.160161## Quality Checks162163- [ ] All task stack sizes are justified (not just "big enough")164- [ ] Memory layout accounts for OTA dual-partition scheme165- [ ] Power state machine has defined transitions and wake sources166- [ ] Watchdog timeout is appropriate for the slowest legitimate operation167- [ ] Static allocation is preferred over dynamic — heap usage is justified168- [ ] Battery life estimate is calculated from power state duty cycle169170## Evolution Notes171<!-- Observations appended after each use -->172173---174> Converted and distributed by [TomeVault](https://tomevault.io/claim/dtsong) — claim your Tome and manage your conversions.175<!-- tomevault:4.0:skill_md:2026-04-13 -->