| name | simulink-generate-embedded-code |
| description | Configure Simulink models for Embedded Coder (ERT) or AUTOSAR code generation. Use when the user asks to configure a model for production/ECU deployment, generate embedded C or C++ code, target ARM or x86 hardware, optimize code generation for speed or RAM, apply MISRA C/C++ compliance, or set up ERT, AUTOSAR, or shared-library targets — including running a full build or producing a code generation report. Handles target selection, optimization cascades, hardware mapping, model hierarchy propagation, and constraint introspection via the configure_for_codegen function. Do NOT use for Simulink Coder / GRT / grt.tlc / rapid-prototyping targets, DDS, or ROS — this skill is Embedded Coder and AUTOSAR only.
|
| license | https://www.mathworks.com/content/dam/mathworks/license/pmrl/license.md |
| metadata | {"author":"MathWorks","version":"1.0"} |
Generate Embedded Code from Simulink Models
Configure Simulink models for Embedded Coder code generation using the configure_for_codegen function.
When to Use
- User asks to configure a model for code generation, production deployment, or Embedded Coder
- User mentions ERT, AUTOSAR, ARM, embedded target, or production code
- User wants to optimize generated code for speed or RAM
- User asks for MISRA C or MISRA C++ compliance
- User describes a deployment target in domain language ("deploy to ECU", "minimize flash")
When NOT to Use
- Simulation-only tasks (running a model, tuning parameters, viewing signals)
- Data dictionary or bus object configuration (standalone, not as part of code-gen setup)
- Test harness creation or coverage analysis
- Simulink Coder (GRT) targets — this skill only handles Embedded Coder (ERT) and AUTOSAR
- DDS (Data Distribution Service) or ROS targets
- Modifying or formatting generated code files after code generation
Rules
-
Never expose the script's wrapper parameter names — describe the decision and its effect in domain terms. The configure_for_codegen wrapper parameter names (ConfigOnly, Build, Interface, OutputDir, Compliance, Objective, Target, Hardware, Language) are an implementation detail of the script — they must never appear in text you show the user, and neither should name="value" syntax. This prohibition covers only the wrapper arguments. It does not restrict describing what the configuration does at the model or ConfigSet level: you may and should explain the engineering substance of each choice in domain terms. Combine both — name the decision, then describe its effect. Tier-1 decision phrasing (safe as-is): "configured the model but did not build", "used a nonreusable function interface", "optimized for speed", "placed generated code next to the model". Concept-level effect phrasing (also safe, and expected on cascade-driven decisions): "optimizing for speed enables an execution-efficiency cascade — strength reduction, inlined parameters, and removal of division-by-zero protection"; "a reusable function interface produces multi-instance/reentrant code that passes state by pointer"; "a MISRA C profile drives specific style rules — casting mode, signed shifts, unreachable-default suppression". Caution: prefer engineering-concept language over raw Simulink ConfigSet parameter identifiers — say "inlines parameters," not "sets InlineInvariantSignals"; say "removes division-by-zero protection," not "sets NoFixptDivByZeroProtection". This applies to defaults, confirmations, follow-up questions, and error paraphrasing — everywhere except the phrase-mapping table below (which is your internal lookup, not user-facing).
-
Model must be open. The model must already be open in MATLAB before calling configure_for_codegen. If it is not, open it directly with open_system('<model>') via evaluate_matlab_code — no separate skill is needed for this.
-
Model must be saved to disk (or the user must supply a destination). The script writes generated code next to the model's .slx file. If the model is a fresh new_system/untitled window with no file on disk, the script cannot infer a location and returns success:false with a message asking the user to save the model or supply an explicit output directory. Relay that message verbatim and ask the user which they prefer — never guess a location on their behalf, and never call without permission (see "Do not save" rule below).
Script Interface
configure_for_codegen(model, Name=Value)
Atomic Embedded Coder configuration via ConfigSetManager. Configures the model (and all referenced sub-models) or reverts entirely on failure.
Positional input:
| Parameter | Description |
|---|
model | Open model name; the .slx/.mdl extension is optional — 'MyModel' and 'MyModel.slx' both work (string) |
Name-value arguments:
| Name | Required | Values | Default |
|---|
Target | Yes | "ert", "ert_shrlib", "autosar", "autosar_adaptive" | — |
Language | Yes | "C" or "C++" — autosar requires C, autosar_adaptive requires C++, ert_shrlib requires C | — |
Hardware | Yes | Device string (e.g. "ARM Compatible->ARM Cortex-A") | — |
Objective | Yes | "Speed", "RAM", or "Debug" | — |
Interface | No | "Nonreusable function", "Reusable function", "C++ class" (requires Language="C++") | "Nonreusable function" |
Build | No | true or false | false |
ConfigOnly | No | true or false | false |
Compliance | No | "MISRA C", "MISRA C++", or "" | "" |
OutputDir | No | Directory path for generated code | Model's directory |
Output: JSON string with fields: success, modelsConfigured, artifactsGenerated, reportPath, errors, parameterChanges, pendingSaves. parameterChanges is an array of {parameter, description, from, to} — one entry per ConfigSet parameter the script touched. Do not itemize this by default; render only when the user explicitly asks (see the "Only itemize parameterChanges" rule above). pendingSaves is an array of {kind, name, path} — kind is "model" or "dictionary"; use it to name files when offering to save and to pick the save mechanism (save_system vs Simulink.data.dictionary.open(...).saveChanges()).
Example call (invoked via evaluate_matlab_code with project_path set to this skill's scripts/ directory):
configure_for_codegen('mbasic', Target="ert", Language="C", Hardware="Intel->x86-64 (Linux 64)", Objective="Speed")
Copyright 2026 The MathWorks, Inc.