embedded-firmware-drivers
Installation
SKILL.md
Embedded Firmware & Peripheral Drivers
Follow this workflow when creating or refactoring C/C++ embedded drivers and peripheral code.
Workflow
-
Inspect target & SDK first
- Identify the MCU family, framework, and C/C++ standard from build files (
platformio.ini,CMakeLists.txt,sdkconfig,*.ioc,Makefile). - Check existing HAL/board headers, CMSIS-SVD (
.svd) register maps (viaquery_svd.pyinembedded-hardware-bringup), or datasheet excerpts for pin definitions, bus handles, clock rates, and error conventions before writing code. Never invent register addresses or pin numbers. - Load Platform Quick Reference when bridging idioms across ESP-IDF, STM32 HAL/LL, PlatformIO/Arduino, or RP2040.
- Identify the MCU family, framework, and C/C++ standard from build files (
-
Separate driver logic from hardware transport (HAL decoupling)
- Design device drivers (sensors, displays, EEPROMs, motor controllers) around an injected bus interface (
read_reg,write_reg,delay_ms,ctxpointer) so the core driver compiles cleanly for unit tests and ports across MCUs. - Start from driver_template.h and driver_template.c for new C99/C11 device drivers.
- Design device drivers (sensors, displays, EEPROMs, motor controllers) around an injected bus interface (
-
Apply protocol-specific reliability guardrails
- Read Peripheral Protocols Reference for I2C (7-bit addressing, pull-ups, stuck-bus recovery), SPI (CPOL/CPHA mode, CS timing, DMA alignment), UART (framing/overrun errors, idle-line DMA), ADC/PWM calibration, and GPIO debouncing.
- Every bus transaction and register poll MUST include an explicit timeout and propagate a typed status enum (
*_ok,*_err_timeout,*_err_nack,*_err_invalid_arg).