Configure and Optimize Model with Configuration Wizard Blocks
The Embedded Coder® software provides a library of Configuration Wizard blocks and scripts to help you configure and optimize code generation from your models.
Configuration Wizard Block Library
The library provides a Configuration Wizard block that you can customize. It also provides four preset Configuration Wizard blocks that update the active configuration parameters for a specified goal.
|Custom MATLAB file||Update active configuration parameters of parent model by using a custom file|
|ERT (optimized for fixed-point)||Update active configuration parameters of parent model for ERT fixed-point code generation|
|ERT (optimized for floating-point)||Update active configuration parameters of parent model for ERT floating-point code generation|
|GRT (debug for fixed/floating-point)||Update active configuration parameters of parent model for GRT fixed- or floating-point code generation with debugging enabled|
|GRT (optimized for fixed/floating-point)||Update active configuration parameters of parent model for GRT fixed- or floating-point code generation|
When you add one of the preset Configuration Wizard blocks to your model and double-click it, a predefined MATLAB® file script configures parameters of the active configuration set without manual intervention. The preset blocks optimally configure the parameters for one of the following cases:
Fixed-point code generation with the ERT target
Floating-point code generation with the ERT target
Fixed-point or floating-point code generation with TLC debugging parameters enabled, with the GRT target.
Fixed-point or floating-point code generation with the GRT target
The Custom block provides an example MATLAB file script that you can adapt to your requirements.
You can also set up the Configuration Wizard blocks to invoke the build process after configuring the model.
Add a Configuration Wizard Block
The Configuration Wizard blocks are available in the Embedded Coder block library. To use a Configuration Wizard block:
Open the model that you want to configure.
Open the Embedded Coder block library by typing the command
Double-click the Configuration Wizards icon. The Configuration Wizards sublibrary opens.
Select the Configuration Wizard block that you want to use and drag it into your model. This model contains the
ERT (optimized for fixed-point)Configuration Wizard block.
If you want the Configuration Wizard block to invoke the build process after configuration, right-click the Configuration Wizard block in your model, and select Mask > Mask Parameters from the context menu. Then, select the Invoke build process after configuration parameter. Do not change the Configure the model for block parameter, unless you want to create a custom block and script. In that case, see Create a Custom Configuration Wizard Block.
Click Apply and close the Mask Parameters dialog box.
Save the model.
Use Configuration Wizard Blocks to Configure Your Model
After you add a Configuration Wizard block to your model, to configure your model, double-click the block. The script associated with the block sets parameters of the active configuration set that are relevant to code generation (including selection of the target). You can see that the parameters have changed by opening the Configuration Parameters dialog box and examining the parameter settings.
If you selected the Invoke build process after configuration block parameter, the script also initiates the code generation and build process.
To provide a quick way to switch between configurations, you can add more than one Configuration Wizard block to your model.
Create a Custom Configuration Wizard Block
The Custom Configuration Wizard block and the associated MATLAB file script,
, provide a
starting point for customization.
Set Up a Configuration Wizard Block
Set up a custom Configuration Wizard block and link it to a script. If you want to use the block in more than one mode, it is advisable to create a Simulink® library to contain the block.
To begin, make a copy of the example script for later customization:
To store your custom script, create a folder. This folder must not be anywhere inside the MATLAB folder structure (that is, it must not be under
The example refers to this folder as
Add the folder to the MATLAB path. Save the path for future sessions.
Copy the example script
rtwsampleconfig.min the folder
(open) to the
/my_wizardsfolder that you created. Then, rename the script. This example uses the name
Open the example script into the MATLAB editor. Scroll to the end of the file and enter the following line of code:
disp('Custom Configuration Wizard Script completed.');
This statement is used later as a test to see that your custom block has executed the script.
Save your script and close the MATLAB editor.
The next task is to create a Simulink library and add a custom block to it.
Open the Embedded Coder block library and the Configuration Wizards sublibrary, as described in Add a Configuration Wizard Block.
On the Library tab, select New > Library. From the Simulink Start Page, choose a Blank Library. An empty library window opens.
Select the Custom MATLAB file block from the Configuration Wizards sublibrary and drag it into the empty library window.
To distinguish your custom block from the original, edit the Custom MATLAB file label under the block.
On the Library tab, select Save > Save as. Save the library to the
/my_wizardsfolder, under your library name of choice. In this figure, the library is saved as
ex_custom_buttonand the block is labeled
The next task is to link the custom block to the custom script:
Right-click the block in your model and select Mask > Mask Parameters from the context menu. The Configure the model for menu is set to
Customis selected, the Configuration function edit field is enabled so that you can enter the name of a custom script.
In the Configuration function field, enter the name of your custom script . (Do not enter the
.mfile name extension, which is implicit.)
By default, the Invoke build process after configuration parameter is cleared. You can change the default for your custom block by selecting this option. For now, leave this parameter cleared.
Click Apply and close the Mask Parameters dialog box.
Save the library.
Close the Embedded Coder block library and the Configuration Wizards sublibrary. Leave your custom library open for use in the next task.
Test your block and script in a model.
vdpmodel by typing the command:
Open the Configuration Parameters dialog box and view the parameters by clicking Code Generation in the list in the left pane of the dialog box.
vdpis configured, by default, for the GRT target. Close the Configuration Parameters dialog box.
Select your custom block from your custom library. Drag the block into the
vdpmodel, double-click your custom block.
In the MATLAB window, you see the test message that you previously added to your script:
Custom Configuration Wizard Script completed.
The test message indicates that the custom block executed the script.
Reopen the Configuration Parameters dialog box and view the Code Generation pane again. The model is now configured for the ERT target.
Before applying further edits to your custom script, proceed to the next section to learn about the operation and conventions of Configuration Wizard scripts.
Create a Configuration Wizard Script
Create your custom Configuration Wizard script by copying and
modifying the example script,
The Configuration Function. The example script implements a single function
without a return value. The function takes a single
cs is a handle to a
proprietary object that contains information about
the active configuration set. The Simulink software obtains this handle and
passes it in to the configuration function when you
double-click a Configuration Wizard block.
Your custom script must conform to this prototype.
Your code must use
cs as a
“black-box” object that transmits
information to and from the active configuration
Option names are passed in to
get_param as character vectors
specifying an internal option
name. The internal option name can be
different from the option label on the UI (for
example, the Configuration Parameters dialog box).
The example configuration accompanies each
get_param call with a comment
that correlates internal option names to UI option
labels. For example:
set_param(cs,'LifeSpan','1'); % Application lifespan (days)
To obtain the current setting of an option in the
active configuration set, call
get_param. Pass in the
cs object as the first
argument, followed by the internal option name. For
example, the following code excerpt tests the
setting of the Create code generation
if strcmp(get_param(cs, 'GenerateReport'), 'on') ...
To set an option in the active configuration set, call
set_param. Pass in the
cs object as the first
argument, followed by one or more parameter/value
pairs that specify the internal option name and its
value. For example, the following code excerpt turns
off the Support absolute
Select a Target. A Configuration Wizard script must select a target configuration. The example script uses the ERT target as a default. The script first stores character vector variables that correspond to the required System target file, Template makefile, and Make command settings:
stf = 'ert.tlc'; tmf = 'ert_default_tmf'; mc = 'make_rtw';
You select the system target file by passing the
cs object and the
stf character vector to the
Set the template makefile and make command options by
To select a target, your custom script must set up the
character vector variables
and pass them to the calls.
Obtain Target and Configuration Set
Information. The following utility functions and properties are
provided so that your code can obtain information
about the current target and configuration set with
isValidParam(cs, 'option'): The
optionargument is an internal option name.
isValidParamreturns true if
optioncan be accessed by using the
get_paramfunction in the context of the active configuration set.
getPropEnabled(cs, 'option'): The
optionargument is an internal option name. Returns true if this
optionis enabled (that is, writable).
IsERTTargetproperty: Your code can detect whether the currently selected target is derived from the ERT target by checking the
IsERTTargetproperty, as follows:
isERT = strcmp(get_param(cs,'IsERTTarget'),'on');
You can use this information to determine whether the script must configure ERT-specific parameters, for example:
if isERT set_param(cs,'ZeroExternalMemoryAtStartup','off'); set_param(cs,'ZeroInternalMemoryAtStartup','off'); set_param(cs,'InitFltsAndDblsToZero','off'); set_param(cs,'NoFixptDivByZeroProtection','on') end
Invoke a Configuration Wizard Script from the Command Line
Configuration Wizard scripts can be run from the MATLAB command line.
Before invoking the script, you must open a model and
cs object to pass in as an
argument to the script. After running the script, you can
invoke the build process with the
command. The following example opens, configures, and builds
open my_model; cs = getActiveConfigSet ('my_model'); rtwsampleconfig(cs); slbuild('my_model');