Matlab Deploy Embedded Code logo

Matlab Deploy Embedded Code

OrganizationPopular
matlab
matlab-deploy-embedded-code

Deploy MATLAB-generated code to embedded hardware using Embedded Coder. Use when configuring code generation for microcontrollers (STM32, Raspberry Pi, ARM Cortex), setting up PIL/SIL verification, disabling dynamic memory allocation, or configuring hardware-specific code generation settings. Covers ERT-based configurations, processor-in-the-loop testing, memory constraints, and the MEX→SIL→PIL verification progression.

Overview

Publishermatlab
Repositorymatlab-agentic-toolkit
Skill namematlab-deploy-embedded-code
Stars
1.2K
Forks
138
Bundled files
3
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • 3 bundled files

    Scripts, templates, and references the model can read while it works. Files are read-only and never executed.

  • Open source

    Published by matlab on GitHub. Read the source before you install it.

Installation

Install the Matlab Deploy Embedded Code AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
    https://github.com/matlab/matlab-agentic-toolkit/tree/main/skills-catalog/code-generation/matlab-deploy-embedded-code
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/matlab/matlab-agentic-toolkit.git /tmp/matlab-agentic-toolkit
mkdir -p .claude/skills
cp -r /tmp/matlab-agentic-toolkit/skills-catalog/code-generation/matlab-deploy-embedded-code .claude/skills/matlab-deploy-embedded-code
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Matlab Deploy Embedded Code in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Matlab Deploy Embedded Code on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Matlab Deploy Embedded Code is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

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, trigger matlab-deploy-embedded-ai first
  • Selecting a hardware target board (STM32, Raspberry Pi)

When NOT to Use

  • Generating MEX or desktop libraries — use standard codegen workflows
  • Simulink-based deployment — use Simulink Coder / Embedded Coder workflows directly
  • GPU code generation (CUDA) — use GPU Coder

Workflow

1. Create an ERT-Based Configuration

matlab
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:

matlab
cfg.Hardware = coder.hardware("STM32F746G-Discovery");

Without the support package, configure hardware manually:

matlab
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

matlab
cfg.EnableDynamicMemoryAllocation = false;
cfg.StackUsageMax = 512;
  • EnableDynamicMemoryAllocation = false — disables malloc/free for 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):

matlab
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:

matlab
cfg.InstructionSetExtensions = 'Neon v7';  % ARM Cortex-A (128-bit, 4x float32)
TargetValueNotes
ARM Cortex-A (Raspberry Pi)'Neon v7'128-bit SIMD
ARM Cortex-MDo not set — use CodeReplacementLibrary insteadDifferent 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:

matlab
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):

matlab
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):

matlab
cfg.VerificationMode = "PIL";
cfg.Hardware.PILInterface = "Serial";
cfg.Hardware.PILCOMPort = "COM4";  % adjust to your system

Cortex-A / Raspberry Pi (SSH transport):

matlab
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

matlab
cfg.TargetLang = "C";
codegen -config cfg -args {inputArgs} myEntryPoint

7. Verify with the MEX → SIL → PIL Progression

For confidence in deployment, follow this sequence:

  1. MEX — verify on host, fast iteration
  2. SIL (Software-in-the-Loop) — run generated code on host, compare to MATLAB
  3. PIL (Processor-in-the-Loop) — run on actual hardware, compare to MATLAB
matlab
cfgSil = coder.config("lib", "ecoder", true);
cfgSil.VerificationMode = "SIL";
codegen -config cfgSil -args {inputArgs} myEntryPoint

Key Properties

PropertyValuesPurpose
VerificationMode"PIL", "SIL", "None"Enable in-the-loop verification
Hardwarecoder.hardware(boardName)Select target board
Hardware.PILInterface"Serial"PIL communication type
Hardware.PILCOMPort"COM4", "/dev/ttyACM0"Serial port
EnableDynamicMemoryAllocationtrue (default), falseMaster switch for heap
DynamicMemoryAllocationThresholdnumeric (bytes), default 65536Arrays above this use heap
LargeConstantGeneration"KeepInSourceFiles", "WriteOnlyDNNConstantsToDataFiles"Where to put large constants
StackUsageMaxnumeric (bytes)Stack limit for generated code (Simulink: MaxStackSize)
EnableOpenMPbooleanOpenMP 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 via set_param(modelName, 'PropertyName', value) directly on the model name. See references/simulink-config.md for the full Simulink Coder property mapping and code examples.

Common Mistakes

MistakeWhy It's WrongCorrect Approach
DynamicMemoryAllocation = "Off"Wrong property name and typeEnableDynamicMemoryAllocation = false (boolean)
Skipping SIL before PILPIL failures on hardware are harder to debugAlways validate with SIL first
Not setting StackUsageMaxDefault may exceed target SRAMSet explicitly based on hardware constraints
Using cfg = coder.config("lib") without "ecoder", trueCreates a generic config, not ERT-basedAlways 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's EnableDynamicMemoryAllocation)
  • Prefer: TargetLang = "C" for Cortex-M targets (smaller code footprint)

References

  • references/supported-hardware.md — board specs, support packages, and PIL interface details
  • references/simulink-config.md — Simulink Coder property naming, set_param patterns, and slbuild code examples

See Also

  • matlab-generate-code — generic codegen foundation: coder directives, screener, MEX generation, SIL, config tuning, SIMD/OpenMP for non-embedded targets
  • matlab-deploy-ai-model — full AI model codegen pipeline (load, verify, generate MEX/lib)

Copyright 2026 The MathWorks, Inc.


Bundled files

The model reads these on demand while the skill is loaded. They are exposed as readable files and are never executed.

Frequently asked questions

What does the Matlab Deploy Embedded Code AI skill do?

Deploy MATLAB-generated code to embedded hardware using Embedded Coder. Use when configuring code generation for microcontrollers (STM32, Raspberry Pi, ARM Cortex), setting up PIL/SIL verification, disabling dynamic memory allocation, or configuring hardware-specific code generation settings. Covers ERT-based configurations, processor-in-the-loop testing, memory constraints, and the MEX→SIL→PIL verification progression.

Why use Matlab Deploy Embedded Code on TypingMind?

Because you install it once and use it with any model. Matlab Deploy Embedded Code is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Matlab Deploy Embedded Code in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/matlab/matlab-agentic-toolkit/tree/main/skills-catalog/code-generation/matlab-deploy-embedded-code. TypingMind reads its SKILL.md and bundles its files and installs it as a skill you can enable per chat.

Which AI models can use Matlab Deploy Embedded Code?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Matlab Deploy Embedded Code?

As many as you like. As long as a model supports skills, you can use Matlab Deploy Embedded Code with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Matlab Deploy Embedded Code AI skill free?

It is published on GitHub by matlab. Check the repository for licensing terms. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇