/embedded-skills:embedded-isr-designfrom embedded-skills
Generates and reviews interrupt service routines for embedded firmware (STM32, GD32, ESP32, FreeRTOS, bare-metal). Enforces Fast In, Fast Out principle: ISRs capture events, tasks process logic. Prevents common mistakes like protocol parsing, blocking calls, or missing FromISR APIs.
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.
Design and review interrupt service routines for embedded systems.
Goals:
The core principle: ISRs capture events, tasks process business logic. An ISR is not a function — it is a hardware-triggered context switch that must execute and return as fast as possible.
The most common and dangerous AI mistake is writing ISRs that contain protocol parsing, sensor
fusion, PID computation, or printf calls. This pattern:
Fast In, Fast Out — enter quickly, do the minimum, exit immediately.
An ISR should be measured in microseconds, not milliseconds.
xTaskNotifyGiveFromISR, osEventFlagsSet)xQueueSendFromISR, osMessageQueuePut)xSemaphoreGiveFromISR)vTaskNotifyGiveFromISR)Every ISR must have a bounded and predictable execution time.
| ISR Type | Maximum Recommended Execution Time |
|---|---|
| GPIO | < 5 µs |
| UART | < 10 µs |
| SPI | < 10 µs |
| DMA | < 10 µs |
| I2C | < 15 µs |
| CAN | < 20 µs |
| Timer | < 20 µs |
Forbidden — unbounded loops in ISR:
for (int i = 0; i < large_variable; i++) { // forbidden — unbounded
process(data[i]);
}
Allowed — minimal data movement:
rx_buf[index++] = data; // allowed — bounded ring buffer write
Forbidden — heavy processing:
json_parse(&parser, byte); // forbidden
protobuf_decode(&msg, buf, len); // forbidden
kalman_update(&kf, measurement); // forbidden
printf Ruleprintf (or any printf-family function) is strictly forbidden inside ISR context. It is:
printf can take hundreds of microseconds to milliseconds)Forbidden:
void USART1_IRQHandler(void) {
printf("rx byte: %02x\r\n", data); // forbidden
}
Heap allocation functions are strictly forbidden inside ISR:
malloc(size); // forbidden
calloc(n, size); // forbidden
realloc(ptr, sz); // forbidden
free(ptr); // forbidden
Heap operations have non-deterministic latency (coalescing, splitting, garbage collection in some allocators), which violates the bounded execution requirement of ISRs.
Extensive floating-point math is forbidden in ISR context:
float angle = atan2f(y, x); // forbidden — FPU operations are costly, stack-heavy
On Cortex-M4F/M7F with FPU, a single atan2f can take 50–150 cycles. On Cortex-M3/M0 (no FPU),
software float emulation adds thousands of cycles and massive stack usage.
Allowed — interrupt handler dispatch calls that clear hardware state:
HAL_UART_IRQHandler(&huart1); // allowed — dispatches to HAL RX/TX/error callbacks
HAL_DMA_IRQHandler(&hdma); // allowed
Forbidden — blocking HAL operations in ISR:
HAL_UART_Transmit(&huart1, data, len, timeout); // forbidden — blocking, polling
HAL_SPI_Transmit(&hspi1, data, len, timeout); // forbidden
HAL_Delay(ms); // forbidden — SysTick-based blocking
Correct — DMA completion signals a task to process data:
DMA Complete IRQ → [Event Flag / TaskNotify] → Task → Process Data
Incorrect — DMA ISR runs the processing inline:
DMA Complete IRQ → Parse Protocol → Control Logic (forbidden)
When using an RTOS (FreeRTOS, CMSIS-RTOS2, RT-Thread, Zephyr), ISR-to-task communication
must use the FromISR variants of RTOS APIs:
Required for FreeRTOS:
xQueueSendFromISR(queue, &data, &higherPriorityTaskWoken);
vTaskNotifyGiveFromISR(task, &higherPriorityTaskWoken);
xSemaphoreGiveFromISR(semaphore, &higherPriorityTaskWoken);
portYIELD_FROM_ISR(higherPriorityTaskWoken);
Required for CMSIS-RTOS2:
osMessageQueuePut(queue, &data, 0, timeout); // allowed in ISR
osEventFlagsSet(flags, mask); // allowed in ISR
Forbidden — non-FromISR APIs inside ISR:
xQueueSend(queue, &data, timeout); // forbidden
osMessageQueuePut(queue, &data, ...); // forbidden with non-zero timeout
xSemaphoreGive(semaphore); // forbidden
Always check higherPriorityTaskWoken and call portYIELD_FROM_ISR() if true, so the
scheduler runs before returning to the outermost interrupt.
Interrupt priorities must reflect real-time criticality, not convenience:
Highest Priority
↑
Timer Control (control loop tick — highest, hard real-time)
↑
DMA (data throughput, buffer management)
↑
SPI / I2C (sensor data streaming)
↑
UART (communication — lower priority than control)
↑
EXTI (user buttons, low-speed events)
↑
Lowest Priority
For a flight controller:
TIM Update IRQ priority 0 (highest — control loop tick)
IMU Data Ready IRQ priority 1
SPI DMA IRQ priority 2
UART IRQ priority 3
EXTI (button) priority 4
Control-related interrupts must have higher priority than communication interrupts. This prevents a burst of UART data from delaying the control loop.
Bare global variables shared between ISR and task context must be protected. The preferred mechanisms (in order of preference) are:
Queue — ISR enqueues, task dequeues
// ISR
xQueueSendFromISR(rx_queue, &byte, &woken);
// Task
xQueueReceive(rx_queue, &byte, portMAX_DELAY);
Double buffer — ISR writes to one buffer, task reads the other
static uint8_t buf[2][256];
static uint8_t active_buf = 0;
static uint16_t index = 0;
// ISR: fill active buffer
buf[active_buf][index++] = byte;
// Task: when buffer is full, swap and process
Event flag + single reader — for simple status sharing
// ISR
vTaskNotifyGiveFromISR(consumer_task, &woken);
// Task
ulTaskNotifyTake(pdTRUE, portMAX_DELAY);
Forbidden — unstructured shared global with no synchronization:
volatile imu_t imu_data; // ISR writes, task reads — no synchronization
// ISR
imu_data = sensor_read(); // problematic
// Task
process(&imu_data); // data may be partially updated
For UART RX, use a ring buffer rather than parsing in the ISR:
UART IRQ → Ring Buffer → UART Task → Protocol Parser
// ISR
ringbuf_put(&uart_rx_ring, rx_byte);
// Task
uint8_t byte;
ringbuf_get(&uart_rx_ring, &byte);
// parse protocol here — in task context
A timer ISR should only be responsible for:
osKernelGetTickCount)Forbidden in timer ISR:
void TIM_IRQHandler(void) {
HAL_TIM_IRQHandler(&htim);
pid_update(); // forbidden — control algorithm belongs in task
telemetry_send(); // forbidden — communication belongs in task
sensor_fusion_update(); // forbidden — estimation belongs in task
}
void EXTI_IRQHandler(void) {
data_ready = true; // simple flag, checked by task poll
EXTI->PR1 |= (1U << 0);
}
void USART1_IRQHandler(void) {
uint8_t byte;
byte = (uint8_t)(USART1->DR & 0xFFU);
BaseType_t woken = pdFALSE;
xQueueSendFromISR(rx_queue, &byte, &woken);
portYIELD_FROM_ISR(woken);
}
void DMA2_IRQHandler(void) {
DMA2->IFCR |= (1U << 0);
BaseType_t woken = pdFALSE;
vTaskNotifyGiveFromISR(processor_task, &woken);
portYIELD_FROM_ISR(woken);
}
void USART1_IRQHandler(void) {
uint8_t byte = (uint8_t)(USART1->DR & 0xFFU);
ringbuf_put(&uart_rx_ring, byte);
USART1->SR &= ~(USART_SR_RXNE);
}
For flight controller and robotics applications specifically:
Forbidden — running Mahony/PID inside IMU data-ready ISR:
IMU IRQ → Mahony → PID → PWM (all in ISR — forbidden)
Required — ISR signals the control task:
IMU IRQ → [TaskNotify]
↓
Control Task (1 kHz)
↓
Mahony → PID → PWM
With this pattern, the control loop period is determined by the RTOS scheduler, not by the ISR execution time. ISR latency accumulates into control loop jitter — keeping ISRs minimal ensures consistent and predictable control timing.
After generating ISR code, verify:
printf or logging in ISRmalloc/free or heap operations in ISRFromISR APIs used where applicableportYIELD_FROM_ISR() called when task wake is requestedWhen ISR violations are found:
FromISR variantsWhat SKILL.md sets; muted values are Claude Code's defaults
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-rtos-designUse when designing, generating, or reviewing RTOS-based embedded firmware (FreeRTOS, CMSIS-RTOS2, RT-Thread, Zephyr, ThreadX) for STM32, GD32, ESP32, drone flight controllers, and robotics projects. Enforces real-time system architecture — task decomposition, scheduling, priority assignment, inter-task communication, ISR cooperation, resource ownership, and watchdog monitoring. Prevents the common AI anti-pattern of creating monolithic super-tasks with mixed responsibilities and jitter-prone control loops coupled to communication timing.
Other plugins' skills for the same job