embedded-stm32
Installation
SKILL.md
Embedded STM32 / HAL Development
This skill covers firmware development for STM32 microcontrollers using the STM32 HAL, including project structure, peripheral and interrupt handling, memory and timing constraints, and testing strategies for hardware-focused code.
Workflow for STM32 HAL Firmware Development
- Configure the hardware in CubeMX — Set up clocks, pins, and peripherals in the
.iocfile; generate the HAL initialization code. - Separate generated and hand-written code — Keep CubeMX-generated files untouched except in their designated
USER CODE BEGIN/ENDblocks; put application logic in separate files. - Initialize peripherals once — Centralize
HAL_*_Init()calls inmain()/MX_*_Init()and avoid ad hoc reconfiguration elsewhere in the code. - Write interrupt handlers — Keep ISRs (
HAL_*_Callbackfunctions,EXTI/DMA/timer IRQ handlers) short; set flags or push to a queue and defer real work to the main loop or an RTOS task. - Use DMA for high-throughput I/O — Configure DMA for UART/SPI/I2C/ADC transfers that would otherwise block or burn CPU cycles on polling.
- Add timeouts everywhere — Every blocking HAL call and every hardware wait loop needs a timeout and an explicit error path.
- Test in layers — Unit-test pure logic on a host build (no hardware dependency), then validate peripheral behavior with hardware-in-the-loop tests.
- Flash and debug — Use SWD/JTAG (ST-Link, OpenOCD, or J-Link) with a debugger, plus rate-limited serial logs, to verify behavior on real hardware.