matlab-deploy-embedded-code skill
ERTベースの構成とPIL検証を使用して、MATLABで生成したC/C++コードをSTM32やRaspberry Piなどの組み込みハードウェアにデプロイします。
- GitHubスター
- 1,293
- ファイル
- 4
- 最終コミット
- 2026年11月9日
- ライセンス
- See LICENSE
- 許可されたツール
- —
matlab-deploy-embedded-code skillは何をしますか
ERTベースの構成とPIL検証を使用して、MATLABで生成したC/C++コードをSTM32やRaspberry Piなどの組み込みハードウェアにデプロイします。
skillのSKILL.mdから生成された要約。
matlab-deploy-embedded-code skill について
プロダクション品質のCまたはC++コードを、STM32マイクロコントローラやRaspberry Piボードなどの組み込みハードウェアにデプロイすることが、このSKILLの主な機能です。MATLABのアルゴリズムから、ベアメタルまたは組み込みLinux環境へ移行する必要があるエンジニア向けに設計されています。ERTベースの構成でEmbedded Coderを使用することで、OSに依存せずに動作するコードを生成し、リソースの限られたデバイスへの適用を可能にします。
ユーザーは、非決定的なヒープ使用を防ぐための動的メモリ割り当ての無効化や、利用可能なSRAMに基づいた最大スタック制限の設定などにより、ハードウェア固有の制約を管理できます。また、ARM Cortex-Aターゲット向けのSIMDベクトル化や、ARM Cortex-A CMSISなどのCode Replacement Librariesの使用によるパフォーマンス最適化もサポートしています。物理ハードウェア上での数学的な正確性を確保するために、MEXおよびSoftware-in-the-Loop (SIL) から、シリアルまたはSSH接続を介してハードウェアの出力をMATLABの結果と比較するProcessor-in-the-Loop (PIL) テストへの検証プロセスを促進します。
エージェントができること
- 1ベアメタルCコード生成の構成OSに依存しないマイクロコントローラ用のCコードを生成するための、ERTベースの構成を設定します。
- 2ARMターゲット向けのパフォーマンス最適化高性能なARM Cortex-A処理のために、SIMDイントリンシックとベンダー最適化済みの数学ライブラリを有効にします。
- 3物理ハードウェア上でのコード検証Processor-in-the-Loopテストを実行し、実際のボード上で精度の違いやメモリの問題を検出します。
- 4マイクロコントローラ向けのメモリ管理ヒープのないターゲットにおいて、すべての配列がコンパイル時に境界確定されるよう、動的メモリ割り当てを無効にします。
skill の SKILL.md から作成されています。すべてのユースケースは、その引用と照合されています。
matlab-deploy-embedded-code skillのインストール方法
各コマンドはskillフォルダをクライアントのskillsディレクトリにコピーします。読み込むには、クライアントを再起動するか新しいセッションを開始してください。Claude Codeにmatlab-deploy-embedded-code skillをインストールする
~/.claude/skills/matlab-deploy-embedded-code/SKILL.md
$ npx degit matlab/matlab-agentic-toolkit/skills-catalog/code-generation/matlab-deploy-embedded-code ~/.claude/skills/matlab-deploy-embedded-codeClaude Code (project)にmatlab-deploy-embedded-code skillをインストールする
.claude/skills/matlab-deploy-embedded-code/SKILL.md
$ npx degit matlab/matlab-agentic-toolkit/skills-catalog/code-generation/matlab-deploy-embedded-code .claude/skills/matlab-deploy-embedded-codeCodexにmatlab-deploy-embedded-code skillをインストールする
~/.agents/skills/matlab-deploy-embedded-code/SKILL.md
$ npx degit matlab/matlab-agentic-toolkit/skills-catalog/code-generation/matlab-deploy-embedded-code ~/.agents/skills/matlab-deploy-embedded-codeGemini CLIにmatlab-deploy-embedded-code skillをインストールする
~/.gemini/skills/matlab-deploy-embedded-code/SKILL.md
$ npx degit matlab/matlab-agentic-toolkit/skills-catalog/code-generation/matlab-deploy-embedded-code ~/.gemini/skills/matlab-deploy-embedded-codeClaude.aiにmatlab-deploy-embedded-code skillをインストールする
npx degit matlab/matlab-agentic-toolkit/skills-catalog/code-generation/matlab-deploy-embedded-code matlab-deploy-embedded-code && zip -r matlab-deploy-embedded-code.zip matlab-deploy-embedded-code # claude.ai → Customize → Skills → + → Create skill → Upload a skill → matlab-deploy-embedded-code.zip
自動チェック
実行日 2026年11月15日完全なレポート →まだ検証されていません。スキルにはスコア 80、重大な指摘なし、チェックに十分なデータが必要です。 チェックの仕組み
- ソースリポジトリがリンクされており、アクセス可能matlab/matlab-agentic-toolkit/skills-catalog/code-generation/matlab-deploy-embedded-code is public and reachablegithub.com/matlab/matlab-agentic-toolkit/tree/HEAD/skills-ca ↗合格
- オープンソースライセンス (OSI)License named in a file, not as an SPDX id未チェック
- 過去1年以内にコミットまたはリリースありLast commit 2026-11-09github.com/matlab/matlab-agentic-toolkit/commits ↗合格
- スクリプトにダウンロード実行や認証情報の窃取がないNo scripts in the skill folder合格
- SKILL.md に隠れた指示がないNo override phrases, safeguard switches, credential requests or hidden charactersgithub.com/matlab/matlab-agentic-toolkit/blob/HEAD/skills-ca ↗合格
- 事前許可ツールが限定されているNo pre-approved tools; the agent asks before using onegithub.com/matlab/matlab-agentic-toolkit/blob/HEAD/skills-ca ↗合格
- SKILL.md が Agent Skills の形式に従っているValid name and description; says when to use it; 245 linesgithub.com/matlab/matlab-agentic-toolkit/blob/HEAD/skills-ca ↗合格
SKILL.md
GitHubで表示Deploy Embedded Code
Configure MATLAB Coder with Embedded Coder for production-quality code generation targeting embedded hardware, and verify correctness with processor-in-the-loop (PIL) testing.
When to Use
- Generating C/C++ code for a microcontroller or embedded Linux board
- Setting up PIL or SIL verification for generated code
- Configuring code generation with no dynamic memory allocation
- Configuring Embedded Coder for an AI model entry-point function prepared by
matlab-deploy-embedded-ai; for the full AI compression and model-loading workflow, triggermatlab-deploy-embedded-aifirst - Selecting a hardware target board (STM32, Raspberry Pi)
When NOT to Use
- Generating MEX or desktop libraries — use standard
codegenworkflows - Simulink-based deployment — use Simulink Coder / Embedded Coder workflows directly
- GPU code generation (CUDA) — use GPU Coder
Workflow
1. Create an ERT-Based Configuration
cfg = coder.config("lib", "ecoder", true);
The "ecoder", true flag creates an ERT-based (Embedded Real-Time) configuration
that generates production-quality code with no OS dependencies.
2. Select Target Hardware
With coder.hardware:
cfg.Hardware = coder.hardware("STM32F746G-Discovery");
Without the support package, configure hardware manually:
cfg.HardwareImplementation.ProdHWDeviceType = 'ARM Compatible->ARM Cortex-M';
cfg.HardwareImplementation.ProdBitPerFloat = 32;
cfg.HardwareImplementation.ProdBitPerDouble = 64;
See references/supported-hardware.md for the full list of supported boards and
their constraints.
3. Configure Memory for Bare-Metal Targets
cfg.EnableDynamicMemoryAllocation = false;
cfg.StackUsageMax = 512;
EnableDynamicMemoryAllocation = false— disablesmalloc/freefor targets where heap is unavailable or non-deterministic. All arrays must be bounded at compile time.StackUsageMax— set based on target SRAM. The code generation report shows actual usage after compilation.
For entry-points that use deep learning inference (invoke, predict):
cfg.DeepLearningConfig = coder.DeepLearningConfig('none');
cfg.LargeConstantGeneration = "KeepInSourceFiles";
DeepLearningConfig('none')— generates C with no external DL library dependencies (MKL-DNN, cuDNN, TensorRT). Required for bare-metal targets. Without this, codegen may attempt to link an unavailable library and fail.LargeConstantGeneration = "KeepInSourceFiles"— keeps weight constants in source files rather than separate data files. Needed for bare-metal targets where external data file linking is unsupported.
4. Configure Performance (SIMD and OpenMP)
SIMD vectorization for embedded ARM targets:
cfg.InstructionSetExtensions = 'Neon v7'; % ARM Cortex-A (128-bit, 4x float32)
| Target | Value | Notes |
|---|---|---|
| ARM Cortex-A (Raspberry Pi) | 'Neon v7' |
128-bit SIMD |
| ARM Cortex-M | Do not set — use CodeReplacementLibrary instead |
Different mechanism |
For non-embedded targets (Intel x86-64 and the full InstructionSetExtensions
ladder), OptimizeReductions, and OpenMP, see the matlab-generate-code skill.
For the MATLAB Coder ↔ Simulink Coder property naming duality, see
references/simulink-config.md.
Code replacement library (CRL) — routes supported ops to vendor-optimized math library implementations.
On Cortex-A: set BOTH InstructionSetExtensions AND a non-SIMD CodeReplacementLibrary.
They target different layers. ISE emits NEON SIMD intrinsics inline for
vectorizable loops in generated code. A non-SIMD CRL routes higher-level math
ops — trig, filtering, matrix — to library implementations you don't have to
generate. ARM Cortex-A CMSIS maps to the ARM CMSIS-DSP library (hand-tuned
Cortex-A kernels shipped by ARM); it does not itself emit NEON, so it composes
with an explicit InstructionSetExtensions = 'Neon v7'. Setting only one of
ISE or CRL leaves performance on the table:
cfg.HardwareImplementation.ProdHWDeviceType = 'ARM Compatible->ARM Cortex-A';
cfg.InstructionSetExtensions = 'Neon v7'; % SIMD intrinsics (also shown in §4 above)
cfg.CodeReplacementLibrary = 'ARM Cortex-A CMSIS'; % non-SIMD CRL — routes math ops to CMSIS-DSP
For Cortex-M, select the CRL matching your compiler (e.g. 'ARM Cortex-M' for
generic; vendor-specific CRLs are shipped with the corresponding support
package). Cortex-M does not use InstructionSetExtensions.
OpenMP — enable on multi-core targets (Cortex-A); disable on single-core (Cortex-M — no OS/threading support, will fail to compile):
cfg.EnableOpenMP = true; % multi-core targets (Cortex-A)
cfg.EnableOpenMP = false; % single-core targets (Cortex-M)
5. Set Up PIL Verification
PIL compiles the generated code, deploys it to the physical board, sends test vectors, and compares outputs against MATLAB. This catches precision differences, stack overflows, and memory issues that SIL cannot detect.
Cortex-M (serial transport):
cfg.VerificationMode = "PIL";
cfg.Hardware.PILInterface = "Serial";
cfg.Hardware.PILCOMPort = "COM4"; % adjust to your system
Cortex-A / Raspberry Pi (SSH transport):
cfg.VerificationMode = "PIL";
cfg.Hardware = coder.hardware("Raspberry Pi");
cfg.Hardware.DeviceAddress = "192.168.1.10";
cfg.Hardware.Username = "<your-pi-username>";
cfg.Hardware.Password = "<your-pi-password>";
cfg.Hardware.BuildDir = "/home/pi/mymodel"; % optional: defaults to /home/pi/MATLAB_ws/<release>
Pi PIL runs over SSH (not serial). The support package uses DeviceAddress,
Username, and Password to establish the SSH connection. BuildDir specifies
where the compiled binary is deployed on the target; if omitted, defaults to
/home/pi/MATLAB_ws/<release>/. Do not set PILInterface or PILCOMPort — those
are for serial-connected bare-metal boards only.
6. Generate Code
cfg.TargetLang = "C";
codegen -config cfg -args {inputArgs} myEntryPoint
7. Verify with the MEX → SIL → PIL Progression
For confidence in deployment, follow this sequence:
- MEX — verify on host, fast iteration
- SIL (Software-in-the-Loop) — run generated code on host, compare to MATLAB
- PIL (Processor-in-the-Loop) — run on actual hardware, compare to MATLAB
cfgSil = coder.config("lib", "ecoder", true);
cfgSil.VerificationMode = "SIL";
codegen -config cfgSil -args {inputArgs} myEntryPoint
Key Properties
| Property | Values | Purpose |
|---|---|---|
VerificationMode |
"PIL", "SIL", "None" |
Enable in-the-loop verification |
Hardware |
coder.hardware(boardName) |
Select target board |
Hardware.PILInterface |
"Serial" |
PIL communication type |
Hardware.PILCOMPort |
"COM4", "/dev/ttyACM0" |
Serial port |
EnableDynamicMemoryAllocation |
true (default), false |
Master switch for heap |
DynamicMemoryAllocationThreshold |
numeric (bytes), default 65536 | Arrays above this use heap |
LargeConstantGeneration |
"KeepInSourceFiles", "WriteOnlyDNNConstantsToDataFiles" |
Where to put large constants |
StackUsageMax |
numeric (bytes) | Stack limit for generated code (Simulink: MaxStackSize) |
EnableOpenMP |
boolean | OpenMP multi-threading (Simulink: MultiThreadedLoops) |
CodeReplacementLibrary |
"ARM Cortex-A CMSIS", "GCC ARM Cortex-A" (SIMD), "ARM Cortex-M", … |
Vendor-optimized op replacements. GCC ARM Cortex-A is a SIMD CRL — do not pair with an explicit ISE. MATLAB warns it is not recommended; use "ARM Cortex-A CMSIS" instead |
TargetLang |
"C", "C++" |
Output language |
Simulink Coder path (
slbuild): properties in the "Simulink:" column above are set viaset_param(modelName, 'PropertyName', value)directly on the model name. Seereferences/simulink-config.mdfor the full Simulink Coder property mapping and code examples.
Common Mistakes
| Mistake | Why It's Wrong | Correct Approach |
|---|---|---|
DynamicMemoryAllocation = "Off" |
Wrong property name and type | EnableDynamicMemoryAllocation = false (boolean) |
| Skipping SIL before PIL | PIL failures on hardware are harder to debug | Always validate with SIL first |
Not setting StackUsageMax |
Default may exceed target SRAM | Set explicitly based on hardware constraints |
Using cfg = coder.config("lib") without "ecoder", true |
Creates a generic config, not ERT-based | Always pass "ecoder", true for embedded targets |
Conventions
- Always: use
coder.config("lib", "ecoder", true)for embedded targets - Always: disable dynamic memory for bare-metal Cortex-M targets
- Always: follow MEX → SIL → PIL verification order
- Never: use
DynamicMemoryAllocation(wrong property name — it'sEnableDynamicMemoryAllocation) - Prefer:
TargetLang = "C"for Cortex-M targets (smaller code footprint)
References
references/supported-hardware.md— board specs, support packages, and PIL interface detailsreferences/simulink-config.md— Simulink Coder property naming,set_parampatterns, andslbuildcode examples
See Also
matlab-generate-code— generic codegen foundation: coder directives, screener, MEX generation, SIL, config tuning, SIMD/OpenMP for non-embedded targetsmatlab-deploy-ai-model— full AI model codegen pipeline (load, verify, generate MEX/lib)
Copyright 2026 The MathWorks, Inc.
このスキルのファイル
4matlab-deploy-embedded-code skillに関する質問
Claude Codeにmatlab-deploy-embedded-code skillをインストールするには
npx degit matlab/matlab-agentic-toolkit/skills-catalog/code-generation/matlab-deploy-embedded-code ~/.claude/skills/matlab-deploy-embedded-codeを実行してください。Claude Codeは~/.claude/skills(すべてのプロジェクト)または.claude/skills(単一プロジェクト)からskillsを読み込み、説明がタスクに一致する場合にskillを使用します。
matlab-deploy-embedded-code skillはどのクライアントで使用できますか
Agent Skills形式を読み込むすべてのクライアントで使用できます: Claude Code、Codex、Gemini CLI、claude.ai(ZIPとしてアップロード)。skill内のスクリプトは、クライアントがコード実行を許可した場合にのみ実行されます。
組み込みターゲット向けのERTベースの構成を作成するにはどうすればよいですか?
cfg = coder.config("lib", "ecoder", true); コマンドを使用して、OSに依存しないプロダクション品質のコードを生成するEmbedded Real-Time構成を作成します。
生成されたコードの推奨される検証手順は?
信頼性を最大限に高めるために、MEX → SIL (Software-in-the-Loop) → PIL (Processor-in-the-Loop) の順序に従ってください。
ベアメタルターゲットで動的メモリ割り当てを無効にするにはどうすればよいですか?
cfg.EnableDynamicMemoryAllocation = false; プロパティを設定して malloc/free を無効にします。これは、ヒープが利用できない、または非決定的なターゲットでは必要です。