embedded-stm32-hal

embedded-stm32-hal is a cursor rule for Cursor from PatrickJS/awesome-cursorrules. It costs 0 tokens per session (515 once invoked), scanned A, original, CC0-1.0.

A set of rules for embedded C and C++ projects built around STM32 microcontrollers and the STM32 hardware-abstraction library. It covers peripherals, interrupts, DMA, memory, timing, and hardware-focused testing.

In plain words
What is it for?
Use it to structure STM32 firmware, separate generated and handwritten code, configure peripherals, handle interrupts and DMA, manage shared data, and test logic without physical hardware.
Why use it?
It helps prevent common embedded-system problems such as unsafe interrupt work, unchecked hardware errors, unclear DMA buffer ownership, and timing or memory failures.

Cursor rule for Cursor

Written for Cursor: a Cursor rule (.mdc).

Good fit Use it to structure STM32 firmware, separate generated and handwritten code, configure peripherals, handle interrupts and DMA, manage shared data, and test logic without physical hardware.

Compare 6 cursor rules from other repositories ↓
Install with agentmods
npx agentmods add rules/patrickjs/awesome-cursorrules/embedded-stm32-hal
About the project

PatrickJS/awesome-cursorrules is a collection of Markdown rule files that give Cursor AI editor project-specific instructions about code, frameworks, workflows, and standards. Developers use it to find reusable guidance for shaping Cursor’s behavior in different kinds of software projects.

PatrickJS/awesome-cursorrules · 40,914 stars · on GitHub

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Clone the repo
git clone --depth 1 https://github.com/PatrickJS/awesome-cursorrules

Made for: Cursor.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for embedded-stm32-hal

README.md
[![agentmods](https://agentmods.dev/badge/rules/patrickjs/awesome-cursorrules/embedded-stm32-hal/github.svg)](https://agentmods.dev/rules/patrickjs/awesome-cursorrules/embedded-stm32-hal)
Your own site
<a href="https://agentmods.dev/rules/patrickjs/awesome-cursorrules/embedded-stm32-hal"><img src="https://agentmods.dev/badge/rules/patrickjs/awesome-cursorrules/embedded-stm32-hal/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for embedded-stm32-hal

Your own site · 80×15
<a href="https://agentmods.dev/rules/patrickjs/awesome-cursorrules/embedded-stm32-hal"><img src="https://agentmods.dev/badge/rules/patrickjs/awesome-cursorrules/embedded-stm32-hal.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 515 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00000 $0.00515
Opus 5.5 $0.00000 $0.00206
Sonnet 5.5 $0.00000 $0.00103
Haiku 4.5 $0.00000 $0.00052

Measured 1mo ago against content hash 390be7b4dfb8, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, from the pricing page.

Security

Grade A, and why

embedded-stm32-hal scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 1mo ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

rules/embedded-stm32-hal.mdc · 56 lines

How it starts

The opening of the file, as written. The whole thing — 56 lines — stays where its author put it; the contents beside it link to each section on GitHub.

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.

Read the full file on GitHub · 56 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 1mo ago First seen · 56 lines · 0 tokens per session scan A 390be7b4dfb8

Subscribe to this mod's changes

embedded-stm32-hal is a cursor rule published in the GitHub repository PatrickJS/awesome-cursorrules (40,914 stars, last pushed 4mo ago), licensed CC0-1.0. It costs nothing until one of its globs matches a file; then it loads 515 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.