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.

  1. Open the modelEvPowertrainController and open the Embedded Coder app.
    openExample("EvPowertrainController")
  2. On the C Code tab, clickSettings.
  3. 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 boardNone
      * 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, select C.
      * Language standard — Language standard supported by your compiler. For this example, select C89/C90 (ANSI).
      * Generate code only — Option to generate an executable after generating the code. For this example, keep the option selected.

    Configuration parameters showing the Code Generation pane.

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.

  1. On the C Code tab, clickSettings.
  2. 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 atMaximum.
    • Priority — The type of optimization to prioritize. For this example, keep the parameter at Balance RAM and speed.
      Configuration parameters showing the optimization level set to Maximum and priority set to 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.

You can also check your model configuration settings against your code generation objectives by using the Code Generation Advisor.

  1. On the Code Generation pane, click Set objectives.
  2. For this example, select the code generation objectives Execution efficiency, ROM efficiency, and RAM efficiency.
    Set Objectives dialog box. The objectives Execution efficiency, ROM efficiency, and RAM efficiency are selected in the right side.
    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.
  3. To apply the objectives, clickOK. Then clickOK in the Configuration Parameters dialog box.
  4. 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.
  5. Select the modelEvPowertrainController from the system hierarchy and clickOK. The Code Generation Advisor creates a list of checks based on the objectives that you select.
  6. 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.
    Code generation advisor showing the results from the check that checks model configuration settings against code generation objectives.
    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:

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:

  1. Open the Model Explorer. On theModeling tab, in theDesign section, clickModel Explorer.
  2. In the Model Hierarchy pane, expand the top model,EvPowertrainController. In the list, select theConfigurations node and select > .
  3. In the middle pane, click the referenceReference. On the right pane, in the Name field, selectActiveSharedReference, then click Apply. This configuration reference is stored in the data dictionary evModelingData.sldd that the model is linked to and points to the configuration ControllerConfig, which is also stored in the data dictionary.
    Model Explorer showing the configuration reference that points to ActiveSharedReference.
  4. Activate the configuration reference. In the middle pane, right-clickReference and click .
  5. The model file now contains a configuration reference that points to the configuration set that is contained in the data dictionary.
  6. In the center pane, right-click the active configuration reference, Reference (Active), and click Propagate to Referenced Models.
  7. Click Propagate. In the Propagation Confirmation dialog box, clickOK.
  8. In the Configuration Reference Propagation to Referenced Models dialog box, the Propagation Report is updated and theStatus for each referenced model is marked asConverted.
    Configuration reference propagation dialog box.

Now:

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:

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.