matlab-deploy-embedded-code
>
git clone --depth 1 https://github.com/matlab/matlab-agentic-toolkit /tmp/matlab-deploy-embedded-code && cp -r /tmp/matlab-deploy-embedded-code/skills-catalog/code-generation/matlab-deploy-embedded-code ~/.claude/skills/matlab-deploy-embedded-codeSKILL.md
# 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)
```
| 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:
```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.
##>
Import recorded driving sensor data (GPS, camera, lidar, actor tracks, lanes) into scenariobuilder.* objects (GPSData, CameraData, LidarData, ActorTrackData, Trajectory, laneData) and run preprocessing — synchronize, offset correction, crop, normalizeTimestamps, convertTimestamps. Also: compute actor tracks from lidar when no annotations exist, attach camera/lidar mounting + intrinsics, export to MAT/workspace/timetable/script. Use for raw driving dataset files (KITTI, nuScenes, Waymo, Pandaset, ROS/ROS2 bags, .mat, .csv, .mp4) or driving/vehicle/sensor logs that need wrapping. drivingLogAnalyzer (DLA) is OPT-IN ONLY — invoke only on explicit user request ('DLA', 'open in DLA', 'inspect/explore/analyze the recording') or reported sensor problem (sync drift, timestamp mismatch, overlay misalignment). NEVER auto-launch DLA after wrapping (Rule 0). For 'build scenario / export to RoadRunner / drivingScenario / OpenSCENARIO / Unreal / simulate', hand off to matlab-scenario-builder.
Generate driving scenes, scenarios, road surfaces, and 3D content from already-wrapped scenariobuilder.* sensor data (GPS, camera, lidar, actor tracks) using Scenario Builder for Automated Driving Toolbox. Use to BUILD, EXPORT, or AUGMENT a virtual scenario/scene/map: ego or actor trajectories, trajectory smoothing, OpenCRG road-surface extraction, 3D asset generation, static-object placement, point-cloud georeferencing + elevation, lane-based ego localization, sensor-fusion tracking, scenario-event extraction (cut-ins, hard brakes, near-misses, ADAS disengagements), or export to RoadRunner, drivingScenario, OpenDRIVE, OpenCRG, OpenSCENARIO, or Unreal Engine. Also: log-to-scenario, scenario harvesting, accident/near-miss reconstruction, SOTIF (ISO 21448) and ISO 26262 scenario coverage, USGS-aerial-lidar scene augmentation, traffic-sign placement from camera+lidar logs. NOT for raw-data import or multi-sensor sync/crop/offset/timestamp normalization — route those to matlab-driving-data-importer.
>
>
>
>
Build, modify, and diagram SimBiology models — API reference, helper functions, and layout patterns. Use when constructing or editing models programmatically or visually.