ormus-solutions/libreembed-claude-code/cortex-m-patterns
- community
Checking that the SKILL.md file is still in the repository.
Cortex-M code patterns for SysTick, NVIC priority grouping, FPU enable, MPU regions, AAPCS inline assembly, DWT cycle counting, vector table relocation, and WFI sleep entry. Use when writing core-level Cortex-M code or checking it against a known-good pattern.
Install
npx vskill@latest install ormus-solutions/libreembed-claude-code/cortex-m-patternsSKILL.md
cortex-m-patterns
Knowledge Base
Real ARM Cortex-M patterns used in production firmware. All code targets C11 with arm-none-eabi-gcc unless noted.
Pattern 1: SysTick Configuration
SysTick is a 24-bit down-counter built into every Cortex-M. Used as the RTOS tick source or a simple 1ms timebase.
Key: SysTick_Config is CMSIS-Core, defined in core_cm4.h. The RELOAD value is (SystemCoreClock/ticks_per_sec) - 1.
Pattern 2: NVIC Priority Grouping
Priority grouping splits the 8-bit priority register into preempt bits and sub-priority bits.
Rule: FreeRTOS requires all ISRs that call FromISR API to have priority numerically >= configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY (lower urgency). Hardware-only ISRs (DMA completion triggering semaphore) can use any priority.
Pattern 3: Cortex-M4 FPU Enable
Must execute before any floating-point instruction, before FreeRTOS scheduler starts.
On STM32F4: called from SystemInit() in system_stm32f4xx.c if __FPU_PRESENT and __FPU_USED are defined. Verify with:
Pattern 4: MPU Region Setup (Cortex-M4)
Use MPU to catch stack overflows by placing a no-access region at the bottom of the stack.
Size field encodes as (log2(size_bytes) - 1). 32 bytes = 2^5, so SIZE = 4 (0x04).
Pattern 5: AAPCS Register Usage in Inline Assembly
AAPCS: R0 returns the result (single 32-bit return value). volatile on __asm prevents the compiler from removing or reordering it.
Pattern 6: DWT Cycle Counter for Timing
DWT (Data Watchpoint and Trace) provides a free-running 32-bit cycle counter on M3/M4/M7.
Note: DWT->CYCCNT is not available on Cortex-M0/M0+ (no DWT). Use SysTick reload difference instead.
Pattern 7: Vector Table Relocation
Bootloaders relocate the application vector table to SRAM or a different flash offset before jumping.
On Cortex-M0 (no VTOR): vector table is always at 0x00000000. Use memory remap if needed.
Pattern 8: Sleep Entry with WFI
Common mistake: forgetting __DSB()/__ISB() before __WFI(). Without them, pending register writes may not complete and the CPU may not enter sleep.
Anti-Patterns
- Missing `volatile` on hardware registers: Without
volatile, the compiler caches register reads in a CPU register and misses hardware updates. CMSIS device headers declare all peripheral structs asvolatile. - Unaligned 32-bit access on M0: Cortex-M0 does not support unaligned word access. Use
__UNALIGNED_UINT32_READmacro from CMSIS or byte-by-byte copy. - Calling `FromISR` API without FreeRTOS priority ceiling: ISR priority must be >=
configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY. Violating this causes silent corruption. - Not flushing pipeline after SCB->VTOR write: Always follow SCB register writes with
__DSB()+__ISB(). - Using SysTick for DMA timing on M4: DMA operates independently of CPU. Use DMA transfer-complete interrupt, not SysTick polling.
References
- ARM Cortex-M4 Technical Reference Manual (DDI0439)
- ARMv7-M Architecture Reference Manual (DDI0403)
- CMSIS-Core documentation: https://arm-software.github.io/CMSIS_5/Core/html/
- STM32F4 Reference Manual (RM0090)
Security
- Security scanPassed, 90 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingplugins/arm-cortex-m/skills/cortex-m-patterns/SKILL.md
Popularity
- 7-day trend score
- 0
Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/ormus-solutions/libreembed-claude-code/cortex-m-patterns)