/embedded-skills:embedded-driver-designfrom embedded-skills
Enforces layered driver architecture for embedded firmware (STM32, GD32, ESP32, FreeRTOS) with bus abstraction, device context objects, register encapsulation, and strict separation between bus drivers, device drivers, BSP, and business modules.
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 embedded drivers using a layered architecture.
The objective is to ensure:
Drivers must hide hardware details behind stable interfaces. Business logic shall never access MCU peripherals directly.
The complete driver stack:
APP
↓
MODULE (business logic — estimator, controller, navigation)
↓
INTERFACE (contracts only — uart_if.h, spi_if.h)
↓
DEVICE DRIVER (icm42688, w25q64, bmp280)
↓
BUS DRIVER (spi, i2c, uart, can)
↓
HAL / BSP (vendor HAL -> platform abstraction)
↓
STM32 HAL / CMSIS
The forbidden pattern — IMU driver calling HAL directly:
APP
↓
ICM42688 ← contains HAL_SPI_Transmit()
↓
HAL_SPI_Transmit()
This couples the device driver to one MCU family and makes porting, testing, and reuse impossible.
Before generating driver code, classify the driver into exactly one of these categories.
driver/bus/Responsible for bus protocol transaction on a specific MCU.
Examples: SPI, I2C, UART, CAN, USB, ETH
Directory: driver/bus/spi/, driver/bus/i2c/
driver/device/Responsible for a specific peripheral chip.
Examples: ICM42688, MPU6050, W25Q64, BMP280, SX1278
Directory: driver/device/icm42688/
bsp/Board-level resources that map to specific hardware.
Examples: LED, Button, Buzzer, OLED
Directory: bsp/ (not driver/)
Many AI tools incorrectly place board-level items like LED or Button into driver/. BSP items
belong under bsp/, not driver/.
Device drivers must never contain:
Mixing driver code with control algorithms is a common architecture error in AI-generated flight controller and robotics firmware. The IMU driver reads and converts sensor data. The attitude estimator processes that data. Keep these in separate layers:
driver/device/imu/ ← register reads, data conversion only
module/estimator/ ← Kalman, attitude fusion
module/controller/ ← PID, control law
driver/
├── bus/
│ ├── spi/
│ ├── i2c/
│ ├── uart/
│ └── can/
├── device/
│ ├── icm42688/
│ │ ├── icm42688.c
│ │ ├── icm42688.h
│ │ └── icm42688_reg.h
│ ├── w25qxx/
│ │ ├── w25qxx.c
│ │ ├── w25qxx.h
│ │ └── w25qxx_reg.h
│ └── bmp280/
└── common/
├── error.h
└── types.h
Every bus must expose an abstract interface. Device drivers depend on these interfaces only — never on vendor HAL types.
SPI bus interface:
typedef struct {
int32_t (*transfer)(const uint8_t *tx, uint8_t *rx, uint32_t len);
int32_t (*transfer_async)(const uint8_t *tx, uint8_t *rx, uint32_t len,
void (*callback)(int32_t status));
} spi_if_t;
I2C bus interface:
typedef struct {
int32_t (*write)(uint8_t addr, const uint8_t *data, uint32_t len);
int32_t (*read)(uint8_t addr, uint8_t *data, uint32_t len);
int32_t (*write_read)(uint8_t addr, const uint8_t *cmd, uint32_t cmd_len,
uint8_t *rx, uint32_t rx_len);
} i2c_if_t;
A device driver may only access the bus through spi_if_t or i2c_if_t, never through
SPI_HandleTypeDef or HAL_SPI_Transmit() directly.
Forbidden in any device driver:
SPI_HandleTypeDef hspi1; // forbidden — MCU-specific type
HAL_SPI_Transmit(&hspi1, ...); // forbidden — vendor HAL API
Required — always go through the bus interface:
spi->transfer(tx, rx, len); // correct
Driver state must live in a device context struct, not in global variables.
Forbidden — global device state:
static float gyro_x;
static float gyro_y;
static uint8_t initialized; // forbidden
Required — device context:
typedef struct {
spi_if_t *spi;
float gyro[3];
float accel[3];
uint8_t initialized;
uint32_t timeout_ms;
} icm42688_t;
All state belongs to the device object. This enables multiple instances of the same device on different bus channels.
Unified init interface — all device drivers must follow this signature:
error_t xxx_init(xxx_t *dev);
Example:
error_t icm42688_init(icm42688_t *imu);
Forbidden:
void imu_init(void); // hidden global state — cannot determine which instance
Register addresses and bit-field definitions must be centralized in a _reg.h header.
Forbidden — magic register addresses scattered in driver code:
spi_write(0x1A, 0x80); // what is 0x1A? what is 0x80?
Required — named register constants:
// icm42688_reg.h
#define ICM42688_REG_PWR_MGMT0 (0x4EU)
#define ICM42688_BIT_TEMP_EN (0x01U << 4)
// icm42688.c
ret = icm42688_write_reg(imu, ICM42688_REG_PWR_MGMT0, ICM42688_BIT_TEMP_EN);
Device drivers must not be aware of DMA streams, DMA channels, or IRQ numbers. These belong to the bus driver layer.
The bus interface exposes both synchronous and asynchronous transfer functions:
spi->transfer(tx, rx, len); // synchronous — blocks until done
spi->transfer_async(tx, rx, len, cb); // asynchronous — callback on completion
The device driver chooses the mode but does not configure DMA hardware directly.
Forbidden in device drivers:
DMA_HandleTypeDef hdma_spi1_tx; // forbidden — DMA is a bus-layer concern
__HAL_DMA_ENABLE(...); // forbidden
Device drivers must be RTOS-agnostic. They must not call:
osDelay(); // forbidden — introduces RTOS dependency
vTaskDelay(); // forbidden
osMutexAcquire(); // forbidden
Device drivers must not busy-wait:
while (!(reg & BIT_READY)); // forbidden — spin-wait blocks the entire system
Instead, device drivers should support timeout, callback, or event mechanisms:
ret = spi->transfer(tx, rx, len);
if (ret == ERR_TIMEOUT) {
// handle timeout — caller decides retry or recovery
}
RTOS concerns (blocking, yielding, mutex protection) are handled by the layer above the device driver — the module or app layer coordinates access if multiple tasks share a device.
All drivers must use a unified error code type:
typedef enum {
ERR_OK = 0,
ERR_TIMEOUT,
ERR_BUSY,
ERR_INVALID_PARAM,
ERR_NOT_READY,
ERR_COMMUNICATION,
} error_t;
Forbidden:
return -1; // meaningless — what failed?
return -2;
return -3;
Every bus interface must be mockable. The bus abstraction (spi_if_t, i2c_if_t) design
enables this naturally — the same interface can point to real hardware or a test stub:
// real hardware
spi_if_t spi = { .transfer = stm32_spi_transfer };
// test mock
spi_if_t mock_spi = { .transfer = mock_spi_transfer };
This allows device drivers to be tested on a PC without any MCU hardware:
mock_spi that returns known patternsAfter generating driver code, verify:
_reg.hstatic device stateerror_t xxx_init(xxx_t *dev) patternerror_t), not magic -1/-2osDelay, vTaskDelay, mutex) in driver codeWhen violations are found:
spi_if_t / i2c_if_t interface_reg.h headererror_t enum valuesmodule/ — drivers read data, modules process itWhat 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-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.
/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