To configure a model for code generation, follow the steps in Select a Solver That Supports Code Generation and Select a System Target File from STF Browser. When you select a system target file, other model configuration parameters change to serve requirements of the execution environment. For example:
Code interface parameters
Build process parameters, such as the toolchain or template makefile
Target hardware parameters, such as word size and byte ordering
After selecting a system target file, you can modify model configuration parameter settings.
You can switch between different system target files in a single workflow for different code generation purposes (for example, rapid prototyping versus production code deployment). To switch, set up different configuration sets for the same model and switch the active configuration set for the current operation. For more information on how to set up configuration sets and change the active configuration set, see Manage Configuration Sets for a Model.
To build a model, the model configuration must specify a solver that is compatible with code generation for the system target file. Few system target files support code generation with variable-step solvers or for models with a nonzero start time.
For GRT, ERT, and ERT-based system target files, set the
Type configuration parameter to
For Rapid Simulation (Rsim) or S-Function (rtwsfcn) system target files, set the
Type configuration parameter to
For more information about the requirement that you use a fixed-step solver to generate code for a realtime system target file, see Time-Based Scheduling and Code Generation.
The Rapid Simulation (RSim) system target file supports a nonzero start time when the
Solver selection configuration parameter is set to
Use Simulink solver module. Other system target files do not
support a nonzero start time –– the code generator does not produce code and the build
process produces an error.
After you select a solver (see Select a Solver That Supports Code Generation), specify a value for the System target file configuration parameter. Enter the name of your system target file directly in the field or use the System Target File Browser to select a file.
To use the System Target File Browser:
In the configuration parameters dialog box, next to the System target file field, click the Browse button. The browser displays a list of available system target files, including customizations.
From the list, select your file, for example, the GRT system target file
grt.tlc). The background of the list box turns yellow to
indicate that the choice is not applied. Click Apply or
System Target File Browser
You also can select a system target file programmatically from MATLAB® code, as described in Select a System Target File Programmatically.
After selecting a system target file, you can modify model configuration parameter settings. Selecting a system target file for your model selects either the toolchain approach or template makefile approach for build process control. For more information about these approaches, see Configure Toolchain or Template Makefile Build Process.
If you want to switch between different system target files in a single workflow for different code generation purposes, set up different configuration sets for the same model. Switch the active configuration set for the current operation. This approach is useful for switching between rapid prototyping and production code deployment. For more information on how to set up configuration sets and change the active configuration set, see Manage Configuration Sets for a Model.
Simulink® models store model-wide parameters and system target file-specific data in configuration sets. Every configuration set contains a component that defines the structure of a particular system target file and the current values of relevant options. Simulink loads some of this information from the system target file that you specify. You can configure models to generate alternative code by copying and modifying old or adding new configuration sets and browsing to select a new system target file. Then, you can interactively select an active configuration from among these sets (only one configuration set can be active at a given time).
Scripts that automate system target file selection must emulate this process.
To program system target file selection:
Obtain a handle to the active configuration set with a call to the
Define character vector variables that correspond to the required system target
file, toolchain or template makefile, and/or
make command settings.
For example, for the ERT system target file, you would define variables for the
Select the system target file with a call to the
switchTarget function. In the function call, specify the handle for the
active configuration set and the system target file.
configuration parameters to the corresponding variables created in step 2.
cs = getActiveConfigSet(model); stf = 'ert.tlc'; tmf = 'ert_default_tmf'; mc = 'make_rtw'; switchTarget(cs,stf,); set_param(cs,'TemplateMakefile',tmf); set_param(cs,'MakeCommand',mc);
For more information about selecting system target files programmatically, see
You can create your own system target files that interface with external code or operating environments.
For more information on how to make custom system target files appear in the System Target File Browser and display relevant controls, see Custom Targets and the topics it references.