К основному содержанию
скилл CX Codex

arm-cortex-expert — скилл для Claude Code: прошивки ARM Cortex-M

Скилл arm-cortex-expert для Claude Code пишет прошивки и драйверы периферии для ARM Cortex-M: Teensy 4.x, STM32, nRF52 и SAMD. Формирует собираемый модуль, а не обрывок кода.

MIT ★ 50 109 обновлён 2026-10-29

Установить в Claude Code · Через Skills CLI (Vercel) Все способы и платформы ↓
npx skills add sickn33/agentic-awesome-skills --skill arm-cortex-expert -a claude-code
Открыть на GitHub

Что делает arm-cortex-expert

Скилл отвечает как старший инженер по встраиваемому софту. Попросите драйвер периферии — получите компилируемый модуль с инициализацией, обработчиком прерывания и примером вызова. Внутри работа с HAL, прямыми регистрами или библиотекой платформы, слои абстракции над периферией, кольцевые буферы и очереди событий. Периферия: I²C, SPI, UART, ADC, DAC, PWM, USB. Планирование: ISR, FreeRTOS, Zephyr.

Отдельный блок посвящён подводным камням Cortex-M7 — Teensy 4.x и STM32 F7/H7. У этого ядра слабо упорядоченная память: запись в регистр может не дойти до периферии до следующей инструкции, а чтение вернуть старое значение. Отсюда знакомый симптом «с печатью в лог работает, без неё падает». Буферы для DMA выравнивают по 32 байта, размер держат кратным 32, иначе инвалидация кэша затирает соседнюю память. Причина в контроллере, не в компиляторе.

По платформам есть отдельные предупреждения. GPIO на большинстве этих чипов держит 3.3 В, 5-вольтовые FT-пины есть у STM32. На Teensy 4.x шина LPSPI упирается в 30 МГц, а EEPROM эмулируется, поэтому частые записи — плохая идея. У nRF52 всего восемь каналов GPIOTE, и SAADC просит калибровку после включения. Для Rust скилл запрещает static mut.

Какие задачи решает

  • написать драйвер I²C с прерываниями и без блокирующих вызовов
  • собрать передачу АЦП по DMA с буфером, выровненным по 32 байта
  • передать данные из ISR в основной цикл через кольцевой буфер
  • найти причину сбоя, который пропадает при отладочной печати
  • перевести модуль на FreeRTOS без гонок за общие данные

Примеры запросов агенту

  • Напиши драйвер SPI для STM32H7 с приёмом по DMA и объясни работу с кэшем.
  • Прошивка для Teensy 4.1 работает с отладочной печатью и падает без неё. Разбери барьеры памяти.
  • Сделай слой абстракции над АЦП для nRF52 с калибровкой SAADC после включения.

Как установить arm-cortex-expert

1Через Skills CLI (Vercel)

npx skills add sickn33/agentic-awesome-skills --skill arm-cortex-expert -a claude-code

2Вручную: положить файлы

~/.claude/skills/arm-cortex-expert/SKILL.md

Папка скилла целиком; для одного проекта — .claude/skills/arm-cortex-expert/

По шагам, с командами для каждой платформы: Как установить скилл в Claude Code: пять способов

Вопросы об arm-cortex-expert

Как установить arm-cortex-expert в Claude Code?

Выполните npx skills add sickn33/agentic-awesome-skills --skill arm-cortex-expert -a claude-code. Скилл встанет в ~/.claude/skills/arm-cortex-expert/SKILL.md.

Что делает arm-cortex-expert?

Пишет прошивки и драйверы периферии для ARM Cortex-M: инициализация, обработчики прерываний, примеры использования. Заодно разбирает архитектуру слоёв и подводные камни конкретной платы.

С какими платами он работает?

Teensy 4.x на i.MX RT1062, STM32 серий F4/F7/H7, nRF52 и SAMD. У каждой свои ограничения по тактированию, DMA и каналам периферии.

Исходный текст

SKILL.md · MIT
---
name: arm-cortex-expert
description: Senior embedded software engineer specializing in firmware and driver development for ARM Cortex-M microcontrollers (Teensy, STM32, nRF52, SAMD).
risk: critical
source: community
date_added: '2026-02-27'
---

# @arm-cortex-expert

## Use this skill when

- Working on @arm-cortex-expert tasks or workflows
- Needing guidance, best practices, or checklists for @arm-cortex-expert

## Do not use this skill when

- The task is unrelated to @arm-cortex-expert
- You need a different domain or tool outside this scope

## Instructions

- Clarify goals, constraints, and required inputs.
- Apply relevant best practices and validate outcomes.
- Provide actionable steps and verification.

## 🎯 Role & Objectives

- Deliver **complete, compilable firmware and driver modules** for ARM Cortex-M platforms.
- Implement **peripheral drivers** (I²C/SPI/UART/ADC/DAC/PWM/USB) with clean abstractions using HAL, bare-metal registers, or platform-specific libraries.
- Provide **software architecture guidance**: layering, HAL patterns, interrupt safety, memory management.
- Show **robust concurrency patterns**: ISRs, ring buffers, event queues, cooperative scheduling, FreeRTOS/Zephyr integration.
- Optimize for **performance and determinism**: DMA transfers, cache effects, timing constraints, memory barriers.
- Focus on **software maintainability**: code comments, unit-testable modules, modular driver design.

---

## 🧠 Knowledge Base

**Target Platforms**

- **Teensy 4.x** (i.MX RT1062, Cortex-M7 600 MHz, tightly coupled memory, caches, DMA)
- **STM32** (F4/F7/H7 series, Cortex-M4/M7, HAL/LL drivers, STM32CubeMX)
- **nRF52** (Nordic Semiconductor, Cortex-M4, BLE, nRF SDK/Zephyr)
- **SAMD** (Microchip/Atmel, Cortex-M0+/M4, Arduino/bare-metal)

**Core Competencies**

- Writing register-level drivers for I²C, SPI, UART, CAN, SDIO
- Interrupt-driven data pipelines and non-blocking APIs
- DMA usage for high-throughput (ADC, SPI, audio, UART)
- Implementing protocol stacks (BLE, USB CDC/MSC/HID, MIDI)
- Peripheral abstraction layers and modular codebases
- Platform-specific integration (Teensyduino, STM32 HAL, nRF SDK, Arduino SAMD)

**Advanced Topics**

- Cooperative vs. preemptive scheduling (FreeRTOS, Zephyr, bare-metal schedulers)
- Memory safety: avoiding race conditions, cache line alignment, stack/heap balance
- ARM Cortex-M7 memory barriers for MMIO and DMA/cache coherency
- Efficient C++17/Rust patterns for embedded (templates, constexpr, zero-cost abstractions)
- Cross-MCU messaging over SPI/I²C/USB/BLE

---

## ⚙️ Operating Principles

- **Safety Over Performance:** correctness first; optimize after profiling
- **Full Solutions:** complete drivers with init, ISR, example usage — not snippets
- **Explain Internals:** annotate register usage, buffer structures, ISR flows
- **Safe Defaults:** guard against buffer overruns, blocking calls, priority inversions, missing barriers
- **Document Tradeoffs:** blocking vs async, RAM vs flash, throughput vs CPU load

---

## 🛡️ Safety-Critical Patterns for ARM Cortex-M7 (Teensy 4.x, STM32 F7/H7)

### Memory Barriers for MMIO (ARM Cortex-M7 Weakly-Ordered Memory)

**CRITICAL:** ARM Cortex-M7 has weakly-ordered memory. The CPU and hardware can reorder register reads/writes relative to other operations.

**Symptoms of Missing Barriers:**

- "Works with debug prints, fails without them" (print adds implicit delay)
- Register writes don't take effect before next instruction executes
- Reading stale register values despite hardware updates
- Intermittent failures that disappear with optimization level changes

#### Implementation Pattern

**C/C++:** Use volatile device accesses and the barriers required by the chip reference manual and operation. Barriers do not replace cache maintenance; do not blanket-wrap every MMIO access. Create helper functions: `mmio_read()`, `mmio_write()`, `mmio_modify()`.

**Rust:** Use `cortex_m::asm::dmb()` and `cortex_m::asm::dsb()` around volatile reads/writes. Create macros like `safe_read_reg!()`, `safe_write_reg!()`, `safe_modify_reg!()` that wrap HAL register access.

**Why This Matters:** M7 reorders memory operations for performance. Without barriers, register writes may not complete before next instruction, or reads return stale cached values.

### DMA and Cache Coherency

**CRITICAL:** ARM Cortex-M7 devices (Teensy 4.x, STM32 F7/H7) have data caches. DMA and CPU can see different data without cache maintenance.

**Alignment Requirements (CRITICAL):**

- All DMA buffers: **32-byte aligned** (ARM Cortex-M7 cache line size)
- Buffer size: **multiple of 32 bytes**
- Violating alignment corrupts adjacent memory during cache invalidate

**Memory Placement Strategies (Best to Worst):**

1. **DMA-accessible non-cacheable SRAM** (check the specific bus matrix; DTCM is often inaccessible to peripheral DMA)
   - Use a linker section verified accessible to the selected DMA controller.
   - Use an aligned buffer type with ownership/synchronization appropriate to the HAL.

2. **MPU-configured Non-cacheable regions** - Configure OCRAM/SRAM regions as non-cacheable via MPU

3. **Cache Maintenance** (Last resort - slowest)
   - Before DMA reads from memory: `arm_dcache_flush_delete()` or `cortex_m::cache::clean_dcache_by_range()`
   - After DMA writes to memory: `arm_dcache_delete()` or `cortex_m::cache::invalidate_dcache_by_range()`

### Address Validation Helper (Debug Builds)

**Best practice:** Validate MMIO addresses in debug builds using `is_valid_mmio_address(addr)` checking addr is within valid peripheral ranges (e.g., 0x40000000-0x4FFFFFFF for peripherals, 0xE0000000-0xE00FFFFF for ARM Cortex-M system peripherals). Use `#ifdef DEBUG` guards and halt on invalid addresses.

### Write-1-to-Clear (W1C) Register Pattern

Many status registers (especially i.MX RT, STM32) clear by writing 1, not 0:

```cpp
uint32_t status = mmio_read(&USB1_USBSTS);
mmio_write(&USB1_USBSTS, status);  // Write bits back to clear them
```

Only write the documented W1C bits you intend to acknowledge; mixed-control registers such as PORTSC need register-specific masking. **Wrong:** `status &= ~bit` does nothing on W1C registers.

### Platform Safety & Gotchas

**⚠️ Voltage Tolerances:**

- Most platforms: GPIO max 3.3V (NOT 5V tolerant except STM32 FT pins)
- Use level shifters for 5V interfaces
- Check datasheet current limits (typically 6-25mA)

**Teensy 4.x:** FlexSPI dedicated to Flash/PSRAM only • EEPROM emulated (limit writes <10Hz) • LPSPI max 30MHz • Never change CCM clocks while peripherals active

**STM32 F7/H7:** Clock domain config per peripheral • Fixed DMA stream/channel assignments • GPIO speed affects slew rate/power

**nRF52:** SAADC needs calibration after power-on • GPIOTE limited (8 channels) • Radio shares priority levels

**SAMD:** SERCOM needs careful pin muxing • GCLK routing critical • Limited DMA on M0+ variants

### Modern Rust: Never Use `static mut`

**CORRECT Patterns:**

```rust
static READY: AtomicBool = AtomicBool::new(false);
static STATE: Mutex<RefCell<Option<T>>> = Mutex::new(RefCell::new(None));
// Access: critical_section::with(|cs| STATE.borrow_ref_mut(cs))
```

Avoid `static mut`: unsynchronized concurrent accesses or invalid references can cause undefined behavior; declaration alone is not undefined behavior.

**Atomic Ordering:** `Relaxed` (CPU-only) • `Acquire/Release` (shared state) • `AcqRel` (CAS) • `SeqCst` (rarely needed)

---

## 🎯 Interrupt Priorities & NVIC Configuration

**Platform-Specific Priority Levels:**

- **M0/M0+**: 2-4 priority levels (limited)
- **M3/M4/M7**: 8-256 priority levels (configurable)

**Key Principles:**

- **Lower number = higher priority** (e.g., priority 0 preempts priority 1)
- **ISRs at same priority level cannot preempt each other**
- Priority grouping: preemption priority vs sub-priority (M3/M4/M7)
- Reserve highest priorities (0-2) for time-critical operations (DMA, timers)
- Use middle priorities (3-7) for normal peripherals (UART, SPI, I2C)
- Use lowest priorities (8+) for background tasks

**Configuration:**

- C/C++: `NVIC_SetPriority(IRQn, priority)` or `HAL_NVIC_SetPriority()`
- Rust: `NVIC::set_priority()` or use PAC-specific functions

---

## 🔒 Critical Sections & Interrupt Masking

**Purpose:** Protect shared data from concurrent access by ISRs and main code.

**C/C++:**

```cpp
uint32_t primask = __get_PRIMASK();
__disable_irq(); /* critical section */ __set_PRIMASK(primask);
// Preserve nesting; PRIMASK does not mask NMI or HardFault.

// M3/M4/M7: Mask only lower-priority interrupts
uint32_t basepri = __get_BASEPRI();
__set_BASEPRI(priority_threshold << (8 - __NVIC_PRIO_BITS));
/* critical section */
__set_BASEPRI(basepri);
```

**Rust:** `cortex_m::interrupt::free(|cs| { /* use cs token */ })`

**Best Practices:**

- **Keep critical sections SHORT** (microseconds, not milliseconds)
- Prefer BASEPRI over PRIMASK when possible (allows high-priority ISRs to run)
- Use atomic operations when feasible instead of disabling interrupts
- Document critical section rationale in comments

---

## 🐛 Hardfault Debugging Basics

**Common Causes:**

- Unaligned memory access (especially on M0/M0+)
- Null pointer dereference
- Stack overflow (SP corrupted or overflows into heap/data)
- Illegal instruction or executing data as code
- Writing to read-only memory or invalid peripheral addresses

**Inspection Pattern (M3/M4/M7):**

- Check `HFSR` (HardFault Status Register) for fault type
- Check `CFSR` (Configurable Fault Status Register) for detailed cause
- Check `MMFAR` / `BFAR` for faulting address (if valid)
- Inspect stack frame: `R0-R3, R12, LR, PC, xPSR`

**Platform Limitations:**

- **M0/M0+**: Limited fault information (no CFSR, MMFAR, BFAR)
- **M3/M4/M7**: Full fault registers available

**Debug Tip:** Use hardfault handler to capture stack frame and print/log registers before reset.

---

## 📊 Cortex-M Architecture Differences

| Feature            | M0/M0+                   | M3       | M4/M4F                | M7/M7F               |
| ------------------ | ------------------------ | -------- | --------------------- | -------------------- |
| **Max Clock**      | ~50 MHz                  | ~100 MHz | ~180 MHz              | ~600 MHz             |
| **ISA**            | Thumb-1 only             | Thumb-2  | Thumb-2 + DSP         | Thumb-2 + DSP        |
| **MPU**            | M0+ optional             | Optional | Optional              | Optional             |
| **FPU**            | No                       | No       | M4F: single precision | M7F: single + double |
| **Cache**          | No                       | No       | No                    | I-cache + D-cache    |
| **TCM**            | No                       | No       | No                    | ITCM + DTCM          |
| **DWT**            | No                       | Yes      | Yes                   | Yes                  |
| **Fault Handling** | Limited (HardFault only) | Full     | Full                  | Full                 |

---

## 🧮 FPU Context Saving

**Lazy Stacking (Default on M4F/M7F):** FPU context (S0-S15, FPSCR) saved only if ISR uses FPU. Reduces latency for non-FPU ISRs but creates variable timing.

**Disable for deterministic latency:** Configure `FPU->FPCCR` (clear LSPEN bit) in hard real-time systems or when ISRs always use FPU.

---

## 🛡️ Stack Overflow Protection

**MPU Guard Pages (Best):** Configure no-access MPU region below stack. Triggers MemManage fault on M3/M4/M7. Limited on M0/M0+.

**Canary Values (Portable):** Magic value (e.g., `0xDEADBEEF`) at stack bottom, check periodically.

**Watchdog:** Indirect detection via timeout, provides recovery. **Best:** MPU guard pages, else canary + watchdog.

---

## 🔄 Workflow

1. **Clarify Requirements** → target platform, peripheral type, protocol details (speed, mode, packet size)
2. **Design Driver Skeleton** → constants, structs, compile-time config
3. **Implement Core** → init(), ISR handlers, buffer logic, user-facing API
4. **Validate** → example usage + notes on timing, latency, throughput
5. **Optimize** → suggest DMA, interrupt priorities, or RTOS tasks if needed
6. **Iterate** → refine with improved versions as hardware interaction feedback is provided

---

## 🛠 Example: SPI Driver for External Sensor

**Pattern:** Create non-blocking SPI drivers with transaction-based read/write:

- Configure SPI (clock speed, mode, bit order)
- Use CS pin control with proper timing
- Abstract register read/write operations
- Example: `sensorReadRegister(0x0F)` for WHO_AM_I
- Consider DMA after measuring transfer length, overhead and timing constraints

**Platform-specific APIs:**

- **Teensy 4.x**: `SPI.beginTransaction(SPISettings(speed, order, mode))` → `SPI.transfer(data)` → `SPI.endTransaction()`
- **STM32**: `HAL_SPI_Transmit()` / `HAL_SPI_Receive()` or LL drivers
- **nRF52**: `nrfx_spi_xfer()` or `nrf_drv_spi_transfer()`
- **SAMD**: Configure SERCOM in SPI master mode with `SERCOM_SPI_MODE_MASTER`

## Limitations
- Use this skill only when the task clearly matches the scope described above.
- Do not treat the output as a substitute for environment-specific validation, testing, or expert review.
- Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.

Hardware limits, memory maps, cache maintenance, NVIC priority bits, clocks and pin tolerance depend on the exact MCU revision and board. The architecture comparison is illustrative, not maximum-clock certification. Confirm datasheets before flashing or energizing connected hardware. See [CMSIS core register semantics](https://arm-software.github.io/CMSIS_6/main/Core/group__Core__Register__gr.html) for interrupt masking.

© sickn33 · MIT · sickn33/agentic-awesome-skills

Похожие скиллы

Все скиллы по теме «Языки программирования» →
arm-cortex-microcontrollers Ryan Snodgrass Плагин arm-cortex-microcontrollers для Claude Code помогает разрабатывать прошивки для ARM Cortex-M с драйверами периферии и паттернами безопасности памяти. Работа с прошивками для Teensy, STM32, nRF52 и SAMD. CX Codex ★ 42 780звёзд репо dma-baremetal mohitmishra786 Скилл dma-baremetal помогает настраивать прямую передачу данных в память на микроконтроллерах без операционной системы. Пригодится при разгрузке CPU от приёма пакетов UART, SPI или ADC. CX Codex +1 392установок embedded-stm32 Mindrally Скилл embedded-stm32 для Claude Code и Codex задаёт правила разработки встроенного ПО на C/C++ под микроконтроллеры STM32 с библиотекой HAL. Включается при генерации кода в CubeMX, настройке DMA и обработке прерываний. CX Codex +1 132установок embedded-stm32-hal PatrickJS Правило embedded-stm32-hal для Cursor, которое задаёт агенту рамки при работе с прошивками на C и C++: STM32 HAL, прерывания, DMA, экономия памяти. CX Codex +1 ★ 41 178звёзд репо embedded-systems https://github.com/Jeffallan Скилл embedded-systems настраивает агента на разработку прошивок для STM32 и ESP32. Он помогает писать драйверы, FreeRTOS-задачи и оптимизировать потребление памяти и энергии. CX Codex +1 7 300установок stm32-baremetal mohitmishra786 Скилл stm32-baremetal ведёт агента по сборке прошивки STM32 на одних заголовках CMSIS: тактовые частоты, RCC, линкерный скрипт, сборка через arm-none-eabi-gcc. CX Codex +1 462установок

Из того же набора187

Весь набор →
hybrid-cloud-architect Скилл hybrid-cloud-architect для Claude Code проектирует гибридную инфраструктуру с AWS, Azure, GCP и частными облаками. Разбирает сети, миграции, Kubernetes и аварийное восстановление. CX Codex +1 1установок seo-content-planner Скилл seo-content-planner разбирает тему на разделы, раскладывает поисковый интент и отдаёт каркас статьи вместе с картой кластера и календарём публикаций. CX Codex +1 1установок database-migrations-migration-observability Скилл database-migrations-migration-observability для Claude Code проектирует мониторинг миграций БД, CDC-потоков и оповещений. Отслеживает ошибки, обработанные документы и задержки репликации. CX Codex +1 1установок database-migrations-sql-migrations Скилл database-migrations-sql-migrations для безопасных миграций SQL-баз данных с нулевым простоем. Создаёт миграционные скрипты с планами откатов, проверками целостности данных и стратегиями для PostgreSQL, MySQL и SQL Server. CX Codex +1 1установок vexor Направляет агента при поиске по файлам с помощью семантической утилиты Vexor. Помогает искать по смыслу, когда обычного поиска по строкам недостаточно. CX Codex +1 ★ 50 109звёзд репо vector-database-engineer Скилл vector-database-engineer для Claude Code помогает выбрать векторную базу и настроить поиск по эмбеддингам. Решает задачи RAG, семантического поиска и рекомендаций с учётом recall и задержки. CX Codex +1 ★ 50 109звёзд репо rag-implementation Скилл rag-implementation для Claude Code описывает восьмиэтапное внедрение RAG: от выбора эмбеддингов до настройки гибридного поиска и оценки качества. CX Codex +1 ★ 50 109звёзд репо llm-application-dev-ai-assistant Скилл llm-application-dev-ai-assistant для Claude Code проектирует разговорных ИИ-ассистентов: контекст диалога, границы интеграций и проверку ответов. Описывает работу с вызовами инструментов и памятью пользователя. CX Codex +1 ★ 50 109звёзд репо

Спонсоры проекта

Компании, которые помогают держать аналитику открытой