domain-embedded
組み込みシステムやno_std環境のRust開発で、マイコンや周辺機器を制御するファームウェア、HAL、RTICなどのライブラリを活用し、割り込み処理やDMA転送などを実装する際に役立つSkill。
📜 元の英語説明(参考)
Use when developing embedded/no_std Rust. Keywords: embedded, no_std, microcontroller, MCU, ARM, RISC-V, bare metal, firmware, HAL, PAC, RTIC, embassy, interrupt, DMA, peripheral, GPIO, SPI, I2C, UART, embedded-hal, cortex-m, esp32, stm32, nrf, 嵌入式, 单片机, 固件, 裸机
🇯🇵 日本人クリエイター向け解説
組み込みシステムやno_std環境のRust開発で、マイコンや周辺機器を制御するファームウェア、HAL、RTICなどのライブラリを活用し、割り込み処理やDMA転送などを実装する際に役立つSkill。
※ jpskill.com 編集部が日本のビジネス現場向けに補足した解説です。Skill本体の挙動とは独立した参考情報です。
下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o domain-embedded.zip https://jpskill.com/download/9255.zip && unzip -o domain-embedded.zip && rm domain-embedded.zip
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/9255.zip -OutFile "$d\domain-embedded.zip"; Expand-Archive "$d\domain-embedded.zip" -DestinationPath $d -Force; ri "$d\domain-embedded.zip"
完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。
💾 手動でダウンロードしたい(コマンドが難しい人向け)
- 1. 下の青いボタンを押して
domain-embedded.zipをダウンロード - 2. ZIPファイルをダブルクリックで解凍 →
domain-embeddedフォルダができる - 3. そのフォルダを
C:\Users\あなたの名前\.claude\skills\(Win)または~/.claude/skills/(Mac)へ移動 - 4. Claude Code を再起動
⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。
🎯 このSkillでできること
下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。
📦 インストール方法 (3ステップ)
- 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
- 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
- 3. 展開してできたフォルダを、ホームフォルダの
.claude/skills/に置く- · macOS / Linux:
~/.claude/skills/ - · Windows:
%USERPROFILE%\.claude\skills\
- · macOS / Linux:
Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。
詳しい使い方ガイドを見る →- 最終更新
- 2026-05-18
- 取得日時
- 2026-05-18
- 同梱ファイル
- 1
📖 Skill本文(日本語訳)
※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。
プロジェクトのコンテキスト (自動注入)
ターゲット構成:
!cat .cargo/config.toml 2>/dev/null || echo "No .cargo/config.toml found"
組み込みドメイン
レイヤー 3: ドメイン制約
ドメイン制約 → 設計への影響
| ドメインルール | 設計制約 | Rust の影響 |
|---|---|---|
| ヒープなし | スタック割り当て | heapless, no Box/Vec |
| std なし | Core のみ | #![no_std] |
| リアルタイム | 予測可能なタイミング | 動的割り当てなし |
| リソース制限 | 最小限のメモリ | 静的バッファ |
| ハードウェアの安全性 | 安全なペリフェラルアクセス | HAL + 所有権 |
| 割り込み安全 | ISR でのブロッキングなし | Atomic, クリティカルセクション |
重要な制約
動的割り当てなし
RULE: ヒープを使用できない (アロケータなし)
WHY: 決定的なメモリ、OOM なし
RUST: heapless::Vec<T, N>, arrays
割り込み安全性
RULE: 共有状態は割り込み安全でなければならない
WHY: ISR はいつでもプリエンプトできる
RUST: Mutex<RefCell<T>> + クリティカルセクション
ハードウェアの所有権
RULE: ペリフェラルは明確な所有権を持つ必要がある
WHY: アクセスの競合を防ぐ
RUST: HAL が所有権を取得、シングルトン
トレースダウン ↓
制約から設計へ (レイヤー 2):
"no_std 互換のデータ構造が必要"
↓ m02-resource: heapless コレクション
↓ 静的サイジング: heapless::Vec<T, N>
"割り込み安全な状態が必要"
↓ m03-mutability: Mutex<RefCell<Option<T>>>
↓ m07-concurrency: クリティカルセクション
"ペリフェラルの所有権が必要"
↓ m01-ownership: シングルトンパターン
↓ m12-lifecycle: ハードウェアの RAII
レイヤースタック
| レイヤー | 例 | 目的 |
|---|---|---|
| PAC | stm32f4, esp32c3 | レジスタアクセス |
| HAL | stm32f4xx-hal | ハードウェア抽象化 |
| フレームワーク | RTIC, Embassy | 並行性 |
| トレイト | embedded-hal | ポータブルドライバ |
フレームワークの比較
| フレームワーク | スタイル | 最適な用途 |
|---|---|---|
| RTIC | 優先度ベース | 割り込み駆動型アプリ |
| Embassy | Async | 複雑なステートマシン |
| ベアメタル | 手動 | シンプルなアプリ |
主要なクレート
| 目的 | クレート |
|---|---|
| ランタイム (ARM) | cortex-m-rt |
| パニックハンドラ | panic-halt, panic-probe |
| コレクション | heapless |
| HAL トレイト | embedded-hal |
| ロギング | defmt |
| フラッシュ/デバッグ | probe-run |
デザインパターン
| パターン | 目的 | 実装 |
|---|---|---|
| no_std セットアップ | ベアメタル | #![no_std] + #![no_main] |
| エントリーポイント | 起動 | #[entry] または embassy |
| 静的状態 | ISR アクセス | Mutex<RefCell<Option<T>>> |
| 固定バッファ | ヒープなし | heapless::Vec<T, N> |
コードパターン: 静的ペリフェラル
#![no_std]
#![no_main]
use cortex_m::interrupt::{self, Mutex};
use core::cell::RefCell;
static LED: Mutex<RefCell<Option<Led>>> = Mutex::new(RefCell::new(None));
#[entry]
fn main() -> ! {
let dp = pac::Peripherals::take().unwrap();
let led = Led::new(dp.GPIOA);
interrupt::free(|cs| {
LED.borrow(cs).replace(Some(led));
});
loop {
interrupt::free(|cs| {
if let Some(led) = LED.borrow(cs).borrow_mut().as_mut() {
led.toggle();
}
});
}
}
よくある間違い
| 間違い | ドメイン違反 | 修正 |
|---|---|---|
| Vec の使用 | ヒープ割り当て | heapless::Vec |
| クリティカルセクションなし | ISR との競合 | Mutex + interrupt::free |
| ISR でのブロッキング | 割り込みの取りこぼし | メインループに委譲 |
| 安全でないペリフェラル | ハードウェアの競合 | HAL の所有権 |
レイヤー 1 へのトレース
| 制約 | レイヤー 2 のパターン | レイヤー 1 の実装 |
|---|---|---|
| ヒープなし | 静的コレクション | heapless::Vec<T, N> |
| ISR の安全性 | クリティカルセクション | Mutex<RefCell<T>> |
| ハードウェアの所有権 | シングルトン | take().unwrap() |
| no_std | Core のみ | #![no_std], #![no_main] |
関連スキル
| いつ | 参照 |
|---|---|
| 静的メモリ | m02-resource |
| 内部可変性 | m03-mutability |
| 割り込みパターン | m07-concurrency |
| ハードウェアに対する unsafe | unsafe-checker |
📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開
Project Context (Auto-Injected)
Target configuration:
!cat .cargo/config.toml 2>/dev/null || echo "No .cargo/config.toml found"
Embedded Domain
Layer 3: Domain Constraints
Domain Constraints → Design Implications
| Domain Rule | Design Constraint | Rust Implication |
|---|---|---|
| No heap | Stack allocation | heapless, no Box/Vec |
| No std | Core only | #![no_std] |
| Real-time | Predictable timing | No dynamic alloc |
| Resource limited | Minimal memory | Static buffers |
| Hardware safety | Safe peripheral access | HAL + ownership |
| Interrupt safe | No blocking in ISR | Atomic, critical sections |
Critical Constraints
No Dynamic Allocation
RULE: Cannot use heap (no allocator)
WHY: Deterministic memory, no OOM
RUST: heapless::Vec<T, N>, arrays
Interrupt Safety
RULE: Shared state must be interrupt-safe
WHY: ISR can preempt at any time
RUST: Mutex<RefCell<T>> + critical section
Hardware Ownership
RULE: Peripherals must have clear ownership
WHY: Prevent conflicting access
RUST: HAL takes ownership, singletons
Trace Down ↓
From constraints to design (Layer 2):
"Need no_std compatible data structures"
↓ m02-resource: heapless collections
↓ Static sizing: heapless::Vec<T, N>
"Need interrupt-safe state"
↓ m03-mutability: Mutex<RefCell<Option<T>>>
↓ m07-concurrency: Critical sections
"Need peripheral ownership"
↓ m01-ownership: Singleton pattern
↓ m12-lifecycle: RAII for hardware
Layer Stack
| Layer | Examples | Purpose |
|---|---|---|
| PAC | stm32f4, esp32c3 | Register access |
| HAL | stm32f4xx-hal | Hardware abstraction |
| Framework | RTIC, Embassy | Concurrency |
| Traits | embedded-hal | Portable drivers |
Framework Comparison
| Framework | Style | Best For |
|---|---|---|
| RTIC | Priority-based | Interrupt-driven apps |
| Embassy | Async | Complex state machines |
| Bare metal | Manual | Simple apps |
Key Crates
| Purpose | Crate |
|---|---|
| Runtime (ARM) | cortex-m-rt |
| Panic handler | panic-halt, panic-probe |
| Collections | heapless |
| HAL traits | embedded-hal |
| Logging | defmt |
| Flash/debug | probe-run |
Design Patterns
| Pattern | Purpose | Implementation |
|---|---|---|
| no_std setup | Bare metal | #![no_std] + #![no_main] |
| Entry point | Startup | #[entry] or embassy |
| Static state | ISR access | Mutex<RefCell<Option<T>>> |
| Fixed buffers | No heap | heapless::Vec<T, N> |
Code Pattern: Static Peripheral
#![no_std]
#![no_main]
use cortex_m::interrupt::{self, Mutex};
use core::cell::RefCell;
static LED: Mutex<RefCell<Option<Led>>> = Mutex::new(RefCell::new(None));
#[entry]
fn main() -> ! {
let dp = pac::Peripherals::take().unwrap();
let led = Led::new(dp.GPIOA);
interrupt::free(|cs| {
LED.borrow(cs).replace(Some(led));
});
loop {
interrupt::free(|cs| {
if let Some(led) = LED.borrow(cs).borrow_mut().as_mut() {
led.toggle();
}
});
}
}
Common Mistakes
| Mistake | Domain Violation | Fix |
|---|---|---|
| Using Vec | Heap allocation | heapless::Vec |
| No critical section | Race with ISR | Mutex + interrupt::free |
| Blocking in ISR | Missed interrupts | Defer to main loop |
| Unsafe peripheral | Hardware conflict | HAL ownership |
Trace to Layer 1
| Constraint | Layer 2 Pattern | Layer 1 Implementation |
|---|---|---|
| No heap | Static collections | heapless::Vec<T, N> |
| ISR safety | Critical sections | Mutex<RefCell<T>> |
| Hardware ownership | Singleton | take().unwrap() |
| no_std | Core-only | #![no_std], #![no_main] |
Related Skills
| When | See |
|---|---|
| Static memory | m02-resource |
| Interior mutability | m03-mutability |
| Interrupt patterns | m07-concurrency |
| Unsafe for hardware | unsafe-checker |