Embedded Mcu Stm32 And Hal Rules

Embedded C/C++ rules for MCU, STM32, HAL, interrupts, DMA, memory constraints, and hardware-focused testing

From PatrickJS/awesome-cursorrules·0 agent reads / 30d·0 saves·

Embedded MCU, STM32, and HAL Rules

Project Structure

  • Keep board support, drivers, middleware, application logic, and tests separate.
  • Isolate generated CubeMX or vendor code from hand-written application code.
  • Put hardware abstraction behind narrow interfaces so logic can be tested without hardware.
  • Document clock tree, pin mappings, peripheral ownership, and interrupt priorities.

STM32 HAL and Peripherals

  • Initialize peripherals in one place and avoid hidden reconfiguration.
  • Check return values from HAL calls and handle timeout/error cases.
  • Keep blocking HAL calls out of time-critical paths.
  • Use DMA for high-throughput UART, SPI, I2C, ADC, or timer capture paths when appropriate.
  • Document buffer ownership and lifetime for DMA operations.
  • Use volatile only for memory shared with ISRs or hardware registers.

Interrupts and Concurrency

  • Keep ISRs short and deterministic.
  • Defer heavy work from interrupts to the main loop, RTOS task, or event queue.
  • Protect shared data with critical sections, atomics, queues, or RTOS primitives.
  • Avoid dynamic allocation in interrupts.
  • Make interrupt priority decisions explicit.

Memory and Timing

  • Avoid heap allocation in firmware unless the project explicitly allows it.
  • Check stack usage for ISRs and RTOS tasks.
  • Keep lookup tables const so they can live in flash.
  • Use fixed-width integer types for hardware-facing code.
  • Add timeouts for hardware waits.
  • Treat watchdog configuration as part of application design, not a late add-on.

Testing and Debugging

  • Unit test pure logic on host builds.
  • Use hardware-in-the-loop tests for peripheral behavior.
  • Add assertions for impossible hardware states in debug builds.
  • Use SWD/JTAG, logic analyzers, and serial logs with rate limits.
  • Keep fault handlers useful: capture reset reason, fault registers, and build version when possible.

Common Mistakes

  • Do not modify generated files unless the workflow preserves changes.
  • Do not busy-wait forever on hardware flags.
  • Do not share buffers between DMA and CPU without synchronization.
  • Do not assume peripheral reset state after low-power modes.

More on the bench

SKILL▲0

Observability Designer

Design production-ready observability strategies combining metrics, logs, and traces. Includes SLI/SLO design, golden-signals monitoring, alert optimization. Use when adding observability to a new service, refactoring alerting that is too noisy, or designing an SLO program before scaling production load.

software-engineering+2
⊙ 2
SKILL▲0

Skill Tester

Validate, test, and score the quality of skills within the claude-skills ecosystem. Comprehensive meta-skill: structure validation, Python script testing (syntax + imports + runtime + output format), multi-dimensional quality scoring with letter grades and tier classification (BASIC/STANDARD/POWERFUL). Use when authoring a new skill, auditing existing skills for tier promotion, setting up pre-commit hooks for skill quality, or integrating skill QA into CI.

software-engineering+2
⊙ 1
SKILL▲0

Ros And Ros2 Rules

ROS and ROS2 rules for packages, nodes, launch files, messages, services, actions, simulation, and testing

software-engineering+1
⊙ 0