/embedded-skills:embedded-rtos-designfrom embedded-skills
Enforces real-time architecture rules for RTOS-based embedded firmware (FreeRTOS, CMSIS-RTOS2, Zephyr, etc.) on STM32, ESP32, and drone/robotics projects. Prevents monolithic super-tasks by enforcing one-task-one-responsibility, control loop timing isolation, and proper task classification.
Ships in embedded-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
This skill defines architecture rules for RTOS-based embedded systems.
Goals:
This skill applies to: FreeRTOS, CMSIS-RTOS2, RT-Thread, Zephyr, ThreadX, and similar RTOS targets.
The most common AI mistake is generating a single monolithic task that reads sensors, runs PID, drives UART, updates OLED, and writes flash — all in one loop. This creates a system that is:
This skill decomposes that pattern into proper task architecture.
Each task owns exactly one functional domain.
Correct task decomposition:
sensor_task — read sensors, publish data
control_task — compute control outputs
telemetry_task — handle communication
logger_task — background logging
Incorrect — the monolithic super-task:
main_task:
read IMU
run PID
update OLED
send UART
write flash
osDelay(1)
This pattern is forbidden. It couples unrelated concerns, prevents real-time analysis, and cannot scale.
Control loops must never depend on communication timing.
Allowed:
sensor_task (1 kHz) → queue → control_task (1 kHz) → queue → motor_task (1 kHz)
telemetry_task (50 Hz, independent)
Forbidden — control loop triggered by communication events:
UART Receive → Trigger Control Loop
Coupling control to communication introduces jitter and destabilizes the control period. This is critical for flight controllers, balance bots, and无人车 (autonomous vehicles).
Every task the agent creates must be classified into one of the categories below.
Examples: imu_task, adc_task, encoder_task, gps_task
Responsibilities:
Must not contain:
Examples: attitude_task, motor_control_task, balance_task
Responsibilities:
osDelayUntil / vTaskDelayUntilMust not contain:
Examples: uart_task, can_task, usb_task, ethernet_task
Responsibilities:
Must not contain:
Examples: logger_task, storage_task, monitor_task, health_check_task
Responsibilities:
Must not contain:
Periodic tasks must use fixed-rate scheduling to avoid drift.
Forbidden — drifting loop:
while (1) {
work();
osDelay(1);
}
osDelay(1) waits 1 ms from the end of work(), so the actual period drifts by the
execution time of work().
Required — drift-free scheduling:
uint32_t tick = osKernelGetTickCount();
while (1) {
work();
osDelayUntil(tick, 1);
}
or:
vTaskDelayUntil(&xLastWakeTime, pdMS_TO_TICKS(1));
Assign priority based on real-time criticality:
Higher Priority
↑
Control Task (highest — hard real-time)
↑
Sensor Task (next — data freshness)
↑
Communication Task (soft real-time)
↑
Service / Logging Task (background)
↑
Idle (lowest)
Example assignment for a flight controller:
control_task priority 6
imu_task priority 5
uart_task priority 4
logger_task priority 2
Shared data between tasks must never use bare global variables.
Forbidden:
// shared header
extern imu_data_t g_imu; // forbidden
Use message queues for streaming data from producer to consumer:
imu_task → [queue] → control_task
osMessageQueuePut(imu_queue_id, &data, 0, timeout);
osMessageQueueGet(imu_queue_id, &data, NULL, wait);
Use event flags for signaling state changes:
osEventFlagsSet(event_id, IMU_DATA_READY);
osEventFlagsWait(event_id, IMU_DATA_READY, flags, timeout);
Use mutexes when multiple tasks access a shared resource (flash, SD card, shared memory buffer):
osMutexAcquire(flash_mutex_id, timeout);
// access shared flash
osMutexRelease(flash_mutex_id);
Do not use a mutex as a message-passing mechanism.
ISRs must be minimal. Allowed operations only:
Example:
void USART_IRQHandler(void) {
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
xQueueSendFromISR(rx_queue_id, &rx_byte, &xHigherPriorityTaskWoken);
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
}
Forbidden inside ISR:
printf() // blocking, non-deterministic
malloc() / free() // non-deterministic latency
floating-point math // excessive stack and cycle cost
protocol parsing // should be in task context
control algorithm math // should be in task context
Correct:
DMA ISR → [event] → communication_task → protocol_parser
Incorrect (all work done in ISR context):
DMA ISR → protocol_parser → control_algorithm
Every hardware resource must have exactly one owning task.
Example:
UART1 → owner: telemetry_task
SPI1 → owner: imu_task
I2C1 → owner: sensor_task
Forbidden — multiple tasks writing the same UART directly:
imu_task ──┐
logger_task ──┤→ UART1 (conflict)
control_task ──┘
Correct — single owner, shared via queue:
all tasks → [queue] → telemetry_task → UART1
Every RTOS project must include a watchdog or health-monitor mechanism:
health_monitor_task:
- verify all task periodic heartbeats
- monitor queue fill levels
- track CPU load (via idle task hook)
- report anomalies or trigger safe state
Minimum watchdog coverage:
When creating a periodic task, record the following parameters in the task design doc:
+----------------+------+----------+-------+--------+
| Task | Hz | Priority | Stack | WCET |
+----------------+------+----------+-------+--------+
| imu_task | 1000 | 5 | 1024 | 150 µs |
| control_task | 1000 | 6 | 1024 | 200 µs |
| telemetry_task | 50 | 3 | 512 | 50 µs |
+----------------+------+----------+-------+--------+
WCET (Worst-Case Execution Time) should be estimated and documented for every hard real-time task.
After generating RTOS code, verify:
osDelayUntil or vTaskDelayUntil (not osDelay)printf, malloc, floating-point math, protocol parsing, or control logicextern globalsWhen violations are found:
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
rtos, embedded-firmware, real-time-systems, task-decomposition, freertos, stm32
npx claudepluginhub rovinax/embedded-skills --plugin embedded-skills6 skills in this plugin
/embedded-architectureUse when creating a new embedded firmware project, adding a module, refactoring firmware, reviewing architecture, or generating project structure. Enforces mandatory architecture rules for maintainable, portable, testable, hardware-independent firmware targeting STM32, GD32, ESP32, RP2040, NXP, Nordic, and similar MCU platforms. Covers project structure, dependency management, module boundaries, platform abstraction, and architecture validation.
/embedded-cstyleUse when generating, modifying, reviewing, or refactoring C code for embedded firmware projects (STM32, GD32, ESP32, FreeRTOS, bare-metal, driver development, robotics). Enforces engineering coding standards — naming, types, functions, variables, macros, headers, memory, concurrency, error handling, and documentation. Catches AI-common mistakes: global variables, magic numbers, missing static/const, volatile abuse, ignored return values, unchecked null pointers, and HAL calls leaking into business logic.
/embedded-documentationUse when creating or reviewing embedded firmware projects (STM32, FreeRTOS, drone, robotics) to ensure complete, consistent, and maintainable documentation. Automatically generates and validates project documentation: README, architecture docs, module design docs, interface specs, RTOS task design, ISR documentation, state machines, hardware pin mapping, and data flow diagrams. Triggers on new projects, new modules, new RTOS tasks/ISRs, state machine detection, or any undocumented component.
/embedded-driver-designUse when developing or reviewing peripheral drivers for embedded firmware (STM32, GD32, ESP32, FreeRTOS, drone flight controllers, robotics). Enforces layered driver architecture with bus abstraction, device context objects, register encapsulation, and strict separation between bus drivers, device drivers, BSP, and business modules. Prevents HAL/register leakage into device drivers and keeps control algorithms (PID, Kalman, attitude estimation) out of driver code.
/embedded-isr-designUse when generating or reviewing interrupt service routines (ISRs) for embedded firmware (STM32, GD32, ESP32, FreeRTOS, bare-metal, drone flight controllers, robotics). Enforces the "Fast In, Fast Out" principle — ISRs capture events and defer processing to task context. Prevents common AI mistakes: protocol parsing in ISR, control algorithms in ISR, printf/malloc in ISR, blocking calls, forgotten flag clearing, and missing FromISR API usage for RTOS integration.
Other plugins' skills for the same job