Configure Basic Code Generation Settings - MATLAB & Simulink (original) (raw)
Main Content
Configure the general settings for your models based on your code generation and deployment goals. Once you specify these settings, Embedded Coder® provides additional options to configure your models and generated code in ways that are specific to your deployment case.
Select Basic Settings for the Code Generation Target
For this example, configure the model to generate C code that you can deploy on your host computer as an example target, prioritizing execution efficiency, then ROM efficiency, then RAM efficiency.
- Open the model
EvPowertrainController
and open the Embedded Coder app.
openExample("EvPowertrainController") - On the C Code tab, clickSettings.
- In the Configuration Parameters dialog box, set these parameters according to your target deployment goals.
- Hardware Implementation pane — These parameters specify your target hardware device. For this example, set these to match your host computer (the computer running Embedded Coder) so you can build and run the example code without using a separate target:
* Hardware board —None
* Device vendor — Vendor of your host computer
* Device type — Type of your host computer - Code Generation pane — These parameters specify basic settings for code generation.
* System target file — This parameter controls the code generation stage of the build process and enables additional configuration parameters for code optimization and customization. Common options include:
*ert.tlc
(used for this example) — Code generation for embedded deployment using Embedded Coder. This system target file enables additional code optimization and customization options.
*grt.tlc
— Code generation for rapid prototyping using Simulink® Coder™.
*rsim.tlc
— Rapid simulation.
*speedgoat.tlc
— Code generation for rapid prototyping and hardware-in-the-loop testing using Simulink Real-Time™.
*autosar.tlc
— Code generation using AUTOSAR Blockset.
* Shared coder dictionary — This parameter specifies an Embedded Coder Dictionary that defines the interfaces for your generated code, such as the service interfaces of your target platform. You configure this step later after you create the Embedded Coder Dictionary.
* Language — Programming language of the generated code, either C or C++. For this example, selectC
.
* Language standard — Language standard supported by your compiler. For this example, selectC89/C90 (ANSI)
.
* Generate code only — Option to generate an executable after generating the code. For this example, keep the option selected.
- Hardware Implementation pane — These parameters specify your target hardware device. For this example, set these to match your host computer (the computer running Embedded Coder) so you can build and run the example code without using a separate target:
Many code generation configuration options depend on the target runtime environment in which you intend to deploy your generated code. Because of this, you specify your target hardware or environment options first. For more information, see Configure Run-Time Environment Options.
Target Hardware
For many target hardware devices, Embedded Coder provides support packages that help to automate integration, execution, and verification of generated code for the processors and devices. For more information, see Embedded Coder Supported Hardware.
Select Optimization Settings
The configuration parameters include many options for optimizing the generated code for different goals. You can manually configure the parameters or you can choose from predefined objectives to automatically configure the parameters according to your goals.
- On the C Code tab, clickSettings.
- On the > pane, in the Optimization levels section, set these parameters according to your optimization goals.
- Level — The level of optimizations to apply to the generated code. For this example, keep the parameter at
Maximum
. - Priority — The type of optimization to prioritize. For this example, keep the parameter at
Balance RAM and speed
.
When you specify an optimization level and priority, Embedded Coder automatically sets the parameters for specific optimizations accordingly. Later in the code generation workflow you can asses the performance of the generated code and manually customize optimizations.
- Level — The level of optimizations to apply to the generated code. For this example, keep the parameter at
You can also check your model configuration settings against your code generation objectives by using the Code Generation Advisor.
- On the Code Generation pane, click Set objectives.
- For this example, select the code generation objectives
Execution efficiency
,ROM efficiency
, andRAM efficiency
.
Each objective checks the current model configuration parameters against the recommended values of the objectives. Each objective also includes a set of Code Generation Advisor checks. You can use these additional checks to verify that the model configuration parameters are set to create code that meets the objectives. - To apply the objectives, clickOK. Then clickOK in the Configuration Parameters dialog box.
- You can run the Code Generation Advisor to check the model based on the specified objectives. To open the Code Generation Advisor, on theC Code tab, clickC/C++ Code Advisor.
- Select the model
EvPowertrainController
from the system hierarchy and clickOK. The Code Generation Advisor creates a list of checks based on the objectives that you select. - The first check reviews current values of the model configuration parameters and suggests alternative values based on the objectives. To run the check, select the check in the left pane and click Run this check.
The check provides an automated method for setting the parameters to recommended values.
For more information about using the optimization parameters and the Code Generation Advisor, see:
- Model Configuration Parameters: Code Generation Optimization
- Configure Model for Code Generation Objectives by Using Code Generation Advisor
- Check Model and Configuration for Code Generation
Share Code Generation Settings Among the Model Hierarchy
You can save the values of the model configuration parameters separately from the model by saving the configuration set in a Simulink data dictionary. Models that are linked to the data dictionary can use the same configuration set by referencing it. Sharing the configuration set can help you to standardize the parameter settings across models within a system. Standardizing configurations is particularly helpful for models in the same hierarchy, which must use the same settings for many of the parameters.
For this example, the linked data dictionaryevModelingData.sldd
already contains a configuration set that uses the settings that you specified earlier. It also contains a configuration reference,ActiveSharedReference
, that points to the configuration set. To use the shared configuration set for the models in the hierarchy:
- Open the Model Explorer. On theModeling tab, in theDesign section, clickModel Explorer.
- In the Model Hierarchy pane, expand the top model,
EvPowertrainController
. In the list, select theConfigurations node and select > . - In the middle pane, click the reference
Reference
. On the right pane, in the Name field, selectActiveSharedReference
, then click Apply. This configuration reference is stored in the data dictionaryevModelingData.sldd
that the model is linked to and points to the configurationControllerConfig
, which is also stored in the data dictionary. - Activate the configuration reference. In the middle pane, right-click
Reference
and click . - The model file now contains a configuration reference that points to the configuration set that is contained in the data dictionary.
- In the center pane, right-click the active configuration reference,
Reference (Active)
, and click Propagate to Referenced Models. - Click Propagate. In the Propagation Confirmation dialog box, clickOK.
- In the Configuration Reference Propagation to Referenced Models dialog box, the Propagation Report is updated and theStatus for each referenced model is marked as
Converted
.
Now:
- The Simulink data dictionary contains the configuration set.
- The data dictionary contains a configuration reference,
ActiveSharedReference
, that points to the configuration. - Each model in the hierarchy references the reference in the data dictionary, which references the freestanding configuration.
When you need to maintain multiple different configurations for the hierarchy, you store them in the data dictionary and switchActiveSharedReference
to point to the active configuration.
For more information about sharing configuration sets among models, see:
- Share a Configuration with Multiple Models
- Manage Configuration Sets for a Model
- Use Configuration Reference to Select Code Generation Target
Configure Models Programmatically
An alternative way to configure your models is to set model configuration parameters programmatically. You can create scripts that automatically configure models to use specific configuration parameter values or to use shared configuration sets. For more information, see Automate Model Configuration by Using a Script and Configure Code Generation Objectives Programmatically.