Main Content

Model Advisor Checks

Simulink Coder Checks Overview

Use Simulink® Coder™ Model Advisor checks to configure your model for code generation.

See Also

Check reuse of subsystem code

Check ID: mathworks.codegen.SubsysCodeReuse

Identify CodeReuseSubsystem blocks that are not reusing code.

Results and Recommended Actions

ConditionRecommended Action
One or more CodeReuseSubsystem blocks in the model do not reuse code.Modify CodeReuseSubsystem blocks in the model so that they reuse code.

Capabilities and Limitations

You can:

  • Run this check on your library models.

  • Look under masks,

  • Exclude blocks and charts from this check if you have a Simulink Check™ license.

See Also

Check solver for code generation

Check ID: mathworks.codegen.SolverCodeGen

Check model solver and sample time configuration settings.

Description

Incorrect configuration settings can stop the code generator from producing code. Underspecifying sample times can lead to undesired results. Avoid generating code that might corrupt data or produce unpredictable behavior.

Available with Simulink Coder.

Results and Recommended Actions

ConditionRecommended Action
The solver type is set incorrectly for model level code generation.

In the Configuration Parameters dialog box, on the Solver pane, set Type to Fixed-step.

Multitasking diagnostic options are not set to error.

In the Configuration Parameters dialog box, on the Diagnostics pane, set

Tips

You do not have to modify the solver settings to generate code from a subsystem. The build process automatically changes Solver type to fixed-step when you right-click on the subsystem and select C/C++ Code > Build This Subsystem or C/C++ Code > Generate S-Function from the subsystem context menu.

See Also

Check for blocks not supported by code generation

Check ID: mathworks.codegen.codeGenSupport

Identify blocks not supported by code generation.

Description

This check partially identifies model constructs that are not suited for code generation as identified in the Simulink Block Support tables for Simulink Coder and Embedded Coder®. If you are using blocks with support notes for code generation, review the information and follow the given advice.

Available with Simulink Coder.

Results and Recommended Actions

ConditionRecommended Action
The model or subsystem contains blocks that should not be used for code generation.Consider replacing the blocks listed in the results. Click an element from the list of questionable items to locate condition.

Capabilities and Limitations

You can:

  • Run this check on your library models.

  • Analyzes content of library linked blocks.

  • Analyzes content in masked subsystems.

  • Exclude blocks and charts from this check if you have a Simulink Check license.

See Also

Check and update model to use toolchain approach to build generated code

Check ID: mathworks.codegen.toolchainInfoUpgradeAdvisor.check

Check if model uses Toolchain settings to build generated code.

Description

Checks whether the model uses the template makefile approach or the toolchain approach to build the generated code.

Available with Simulink Coder.

When you open a model created before R2013b that has System target file set to ert.tlc, ert_shrlib.tlc, or grt.tlc the software automatically tries to upgrade the model from using the template makefile approach to using the toolchain approach.

If the software does not upgrade the model, this check determines the cause, and if available, recommends actions you can perform to upgrade the model.

To determine which approach your model is using, you can also look at the Code Generation pane in the Configuration Parameters dialog box. The toolchain approach uses the following parameters to build generated code:

The template makefile approach uses the following settings to build generated code:

  • Compiler optimization level

  • Custom compiler optimization flags

  • Generate makefile

  • Template makefile

Results and Recommended Actions

ConditionRecommended ActionComment
Model is configured to use the toolchain approach.No action.The model was automatically upgraded.
Model is not configured to use the toolchain approach. Model cannot be automatically upgraded to use the toolchain approach.The system target file is not toolchain-compliant. Set System target file to a toolchain-compliant target, such as ert.tlc, ert_shrlib.tlc, or grt.tlc.
Model is not configured to use the toolchain approach. (Parameter values are not the default values.)Model can be automatically upgraded to use the toolchain approach. Click Update Model.The parameters are set to their default values, except Compiler Optimization Level, which is set to Optimizations on (faster runs). Clicking Update Model sets Compiler Optimization Level to its default value, Optimizations off (faster builds), and then upgrades the model. The upgraded model has Build Configuration set to Faster Builds. Saving the model makes the changes permanent.
Model is not configured to use the toolchain approach. (Parameter values are not the default values and model is configured to generate a Microsoft® Visual Studio® solution)Model can be automatically upgraded to use the toolchain approach. Click Update Model.

The parameters are set to their default values, except Compiler Optimization Level, which is set to Optimizations on (faster runs). Clicking Update Model sets Compiler Optimization Level to its default value, Optimizations off (faster builds), and then upgrades the model. The upgraded model uses a CMake toolchain and Build Configuration is set to:

  • Specify if Compiler Optimization Level is Optimizations on (faster runs)

  • Debug if Compiler Optimization Level is Optimizations off (faster builds)

Saving the model makes the changes permanent.

Model is not configured to use the toolchain approach. (Parameter values are not the default values.)Model cannot be automatically upgraded to use the toolchain approach.

One or more of the following parameters is not set to its default value:

  • Generate makefile (default: Enabled)

  • Template makefile (default: Target-specific default TMF)

  • Compiler optimization level (default: Optimizations off (faster builds))

  • Make command (default: make_rtw without arguments)

See Upgrade Model to Use Toolchain Approach

Action Results

Clicking Update model upgrades the model to use the toolchain approach to build generated code.

See Also

Check whether model might require LCC compiler

Check ID: mathworks.codegen.LCCCheck.check

Check whether LCC is the default compiler.

Description

Check whether LCC is the default compiler for simulation workflows and generated code compilation on the MATLAB® computer.

Available with Simulink Coder.

Results and Recommended Actions

ConditionRecommended Action
LCC is the compiler for model simulation and generated code compilation.Specify another compiler. For example, by using the Toolchain configuration parameter.
LCC is not the compiler for model simulation and generated code compilation. No action.

See Also

Check and update embedded target model to use ert.tlc system target file

Check ID: mathworks.codegen.codertarget.check

Check and update the embedded target model to use ert.tlc system target file.

Description

Check and update models whose System target file is set to a file other than ert.tlc and whose target hardware is one of the supported Texas Instruments® C2000™ processors to use ert.tlc and similar settings.

Available with Simulink Coder.

Results and Recommended Actions

ConditionRecommended Action
System target file is set to ert.tlc - Embedded Coder.No action

System target file is set to a file other than ert.tlc and Hardware board parameter is set to a processor that is supported by the Embedded Coder Support Package for Texas Instruments C2000 Processors.

Run the corresponding check in Upgrade Advisor:

  1. In the Modeling tab of Simulink Editor, click Model Advisor.

  2. Open the Upgrade Advisor pane and select check Check and update embedded target model to use ert.tlc system target file.

  3. Right-click on the check and select Run This Check.

  4. After the check passes, open the Configuration Parameters dialog box, go to Hardware Implementation pane and confirm that the correct Hardware board is selected.

Action Results

Clicking Run This Check automatically sets the following parameters on the Code Generation pane in the model Configuration Parameters dialog box:

  • System target file parameter to ert.tlc.

  • Toolchain parameter to match the previous toolchain.

  • Build configuration parameter to match the build configuration.

Capabilities and Limitations

The new workflow uses the toolchain approach, which relies on enhanced makefiles to build generated code. It does not provide an equivalent to setting the Build format parameter to Project in the previous configuration. Therefore, the new workflow cannot automatically generate IDE projects within the CCS 3.3 IDE.

See Also

Code Compilation Customization

Check and update models that are using targets that have changed significantly across different releases of MATLAB

Check ID: mathworks.codegen.realtime2CoderTargetInfoUpgradeAdvisor.check

Check and update models with Simulink targets that have changed significantly across different releases of MATLAB.

Description

Save a model that you have updated to work with the current installation of MATLAB.

Available with Simulink Coder.

Results and Recommended Actions

ConditionRecommended Action
Model uses a target that has changed significantly since the release of MATLAB in which it was originally saved.Save model
Model does not use a Simulink target or is using the latest version of the target.No action
Model is automatically updated.Save model
Invalid external mode configuration.In the Configuration Parameters > Interface pane, update the external mode parameter settings to match characteristics of your host-target connection.

Model is corrupted.

Close and reopen the model. If the issue persists, reset Configuration Parameters > Hardware Implementation > Hardware board.

Action Results

Clicking Save model updates the model to work with the current installation of MATLAB and saves the model.

See Also

Configure Production and Test Hardware

Check for blocks that have constraints on tunable parameters

Check ID: mathworks.codegen.ConstraintsTunableParam

Identify blocks with constraints on tunable parameters.

Description

Lookup Table blocks have strict constraints when they are tunable. If you violate lookup table block restrictions, the generated code produces incorrect answers.

Available with Simulink Coder.

Results and Recommended Actions

ConditionRecommended Action
Lookup Table blocks have tunable parameters.

When tuning parameters during simulation or when running the generated code, you must:

  • Preserve monotonicity of the setting for the Vector of input values parameter.

  • Preserve the number and location of zero values that you specify for Vector of input values and Vector of output values parameters if you specify multiple zero values for the Vector of input values parameter.

Lookup Table (2-D) blocks have tunable parameters.

When tuning parameters during simulation or when running the generated code, you must:

  • Preserve monotonicity of the setting for the Row index input values and Column index of input values parameters.

  • Preserve the number and location of zero values that you specify for Row index input values, Column index of input values, and Vector of output values parameters if you specify multiple zero values for the Row index input values or Column index of input values parameters.

Lookup Table (n-D) blocks have tunable parameters.When tuning parameters during simulation or when running the generated code, you must preserve the increasing monotonicity of the breakpoint values for each table dimension Breakpoints n.

Capabilities and Limitations

If you have a Simulink Check license, you can exclude blocks and charts from this check.

See Also

Check for model reference configuration mismatch

Check ID: mathworks.codegen.MdlrefConfigMismatch

Identify referenced model configuration parameter settings that do not match the top model configuration parameter settings.

Description

The code generator cannot create code for top models that contain referenced models with different, incompatible configuration parameter settings.

Available with Simulink Coder.

Results and Recommended Actions

ConditionRecommended Action
The top model and the referenced model have inconsistent model configuration parameter settings. Modify the specified model configuration settings.

See Also

Check sample times and tasking mode

Check ID: mathworks.codegen.SampleTimesTaskingMode

Set up the sample time and tasking mode for your system.

Description

Incorrect tasking mode can result in inefficient code execution or incorrect generated code.

Available with Simulink Coder.

Results and Recommended Actions

ConditionRecommended Action
The model represents a multirate system but is not configured for multitasking.Select model configuration parameter  Treat each discrete rate as a separate task. When you select the parameter, multitasking execution is applied for a multirate model. For more information, see Time-Based Scheduling and Code Generation.
The model is configured for multitasking, but multitasking is not desirable on the target hardware. For example, the operating system does not support multiprocessing or the target hardware is bare metal (is not running an operating system) and the application does not provide for a multitasking execution scheme.Clear model configuration parameter  Treat each discrete rate as a separate task. When you clear the parameter, single-tasking execution is applied. For more information, see Time-Based Scheduling and Code Generation.

See Also

Time-Based Scheduling and Code Generation

Check for code generation identifier formats used for model reference

Check ID: mathworks.codegen.ModelRefRTWConfigCompliance

Checks for referenced models in a model referencing hierarchy for which code generation changes configuration parameter settings that involve identifier formats.

Description

In referenced models, if the following Configuration Parameters > Code Generation > Identifiers parameters have settings that do not contain a $R token (which represents the name of the reference model), code generation prepends the $R token to the identifier format.

  • Global variables

  • Global types

  • Subsystem methods

  • Constant macros

Available with Simulink Coder.

Results and Recommended Actions

ConditionRecommended Action

A script that operates on generated code uses model names that code generation changes.

Update the script to use the generated name (which includes an appended $R token).

Check for relative execution order change for Data Store Read and Data Store Write blocks

Check ID: mathworks.design.datastoresimrtwcmp

Checks that the execution order of Data Store Read and Data Store Write blocks does not change when a model is compiled for code generation.

Description

The execution order defines the sequence in which the Data Store Read and Data Store Write blocks access the Data Store Memory block. The Model Advisor check compares the execution order from prior to running the check (normal simulation mode) to the execution order after compiling the check (code generation mode). The check passes when the execution order is the same. When there are differences, the check issues a Warning and identifies the discrepancies in the results.

Available with Simulink Coder.

Results and Recommended Actions

ConditionRecommended Action

The execution order of the Data Store Read and Data Store Write blocks is different between simulation mode and code generation mode.

In the Model Advisor results, under Action, click Modify block priorities. The Model Advisor modifies the blocks so the execution order in simulation mode is the same as that in code generation mode.

See Also

Available Checks for Code Generation Objectives

Code generation objectives checks facilitate designing and troubleshooting Simulink models and subsystems that you want to use to generate code. For more information about code generation objectives, see Application Objectives Using Code Generation Advisor.

The Code Generation Advisor includes the following checks from Simulink, Simulink Coder, and Embedded Coder for each of the code generation objectives. Two checks unique to the Code Generation Advisor are included below the list.

CheckExecution efficiency
(all targets)
ROM efficiency
(ERT-based targets)
RAM efficiency
(ERT-based targets)
Safety precaution
(ERT-based targets)
Traceability
(ERT-based targets)
Debugging
(all targets)
MISRA C:2012 guidelines
(ERT-based targets)
Polyspace®
(ERT-based targets)
Check model configuration settings against code generation objectivesIncludedIncludedIncludedIncludedIncludedIncludedIncluded (see Note below)Included
Check for optimal bus virtualityIncludedIncludedIncludedN/AN/AN/AN/AN/A
Identify questionable blocks within the specified systemIncluded IncludedIncludedN/AN/AN/AN/AN/A
Check the hardware implementation (Embedded Coder)Included if Embedded Coder is availableIncluded if Embedded Coder is availableN/AN/AN/AN/AN/AN/A
Identify questionable software environment specifications (Embedded Coder)Included when Traceability is not a higher priority and Embedded Coder is availableIncluded when Traceability is not a higher priority and Embedded Coder is availableN/AN/AN/AN/AN/AN/A
Identify questionable code instrumentation (data I/O) (Embedded Coder)Included when Traceability or Debugging are not higher priorities and Embedded Coder is availableIncluded when Traceability or Debugging are not higher priorities and Embedded Coder is availableIncluded when Traceability or Debugging are not higher priorities and Embedded Coder is availableN/AN/AN/AN/AN/A
Identify questionable subsystem settings (Embedded Coder)N/AIncluded if Embedded Coder is availableIncluded if Embedded Coder is availableN/AN/AN/AN/AN/A
Identify blocks that generate expensive rounding code (Embedded Coder)Included if Embedded Coder is availableIncluded if Embedded Coder is availableN/AN/AN/AN/AN/AN/A
Identify questionable fixed-point operations (Embedded Coder)Included if Embedded Coder or Fixed-Point Designer™ is availableIncluded if Embedded Coder or Fixed-Point Designer is availableN/AN/AN/AN/AN/AN/A
Identify lookup table blocks that generate expensive out-of-range checking code (Embedded Coder)Included if Embedded Coder is availableIncluded if Embedded Coder is availableN/AN/AN/AN/AN/AN/A
Check output types of logic blocks (Embedded Coder)Included if Embedded Coder is availableN/AN/AN/AN/AN/AN/AN/A

Identify unconnected lines, input ports, and output ports

N/AN/AN/AIncludedN/AN/AN/AN/A
Check Data Store Memory blocks for multitasking, strong typing, and shadowing issuesN/AN/AN/AIncludedN/AN/AN/AN/A
Identify block output signals with continuous sample time and non-floating point data typeN/AN/AN/AIncludedN/AN/AN/AN/A
Check for blocks that have constraints on tunable parametersN/AN/AN/AIncludedN/AN/AN/AN/A
Check if read/write diagnostics are enabled for data store blocksN/AN/AN/AIncludedN/AN/AN/AN/A
Check structure parameter usage with bus signalsN/AN/AN/AIncludedN/AN/AN/AN/A
Check data store block sample times for modeling errorsN/AN/AN/AIncludedN/AN/AN/AN/A
Check for potential ordering issues involving data store accessN/AN/AN/AIncludedN/AN/AN/AN/A
Check for blocks not recommended for C/C++ production code deployment (Embedded Coder)N/AN/AN/AN/AN/AN/AIncluded if Embedded Coder is availableN/A
Check for blocks not recommended for MISRA C:2012 (Embedded Coder)N/AN/AN/AN/AN/AN/AIncluded if Embedded Coder is availableN/A
Check for unsupported block names (Embedded Coder)N/AN/AN/AN/AN/AN/AIncluded if Embedded Coder is availableN/A
Check usage of Assignment blocks (Embedded Coder)N/AN/AN/AN/AN/AN/AIncluded if Embedded Coder is availableN/A
Check for bitwise operations on signed integers (Embedded Coder)N/AN/AN/AN/AN/AN/AIncluded if Embedded Coder is availableN/A
Check for recursive function calls (Embedded Coder)N/AN/AN/AN/AN/AN/AIncluded if Embedded Coder is availableN/A
Check for equality and inequality operations on floating-point values (Embedded Coder)N/AN/AN/AN/AN/AN/AIncluded if Embedded Coder is availableN/A
Check for switch case expressions without a default case (Embedded Coder)N/AN/AN/AN/AN/AN/AIncluded if Embedded Coder is availableN/A
Check configuration parameters for generation of inefficient saturation code (Embedded Coder)Included if Embedded Coder is availableIncluded if Embedded Coder is availableN/AIncluded if Embedded Coder is availableN/AN/AN/AN/A

Note

When the Code Generation Advisor checks your model against the MISRA C:2012 guidelines objective, the tool does not consider all of the configuration parameter settings that are checked by the MISRA C:2012 guidelines checks in the Model Advisor. For a complete check of configuration parameter settings:

  1. Open the Model Advisor.

  2. Navigate to By Task > Modeling Guidelines for MISRA C:2012.

  3. Run the checks in the folder.

For more information on using the Model Advisor, see Check Your Model Using the Model Advisor.

See Also

Identify questionable blocks within the specified system

Identify blocks not supported by code generation or not recommended for deployment.

Description

The code generator creates code only for the blocks that it supports. Some blocks are not recommended for production code deployment.

Results and Recommended Actions

ConditionRecommended Action
A block is not supported by the code generator.Remove the specified block from the model or replace the block with the recommended block.
A block is not recommended for production code deployment.Remove the specified block from the model or replace the block with the recommended block.
Check for Gain blocks whose value equals 1.Replace Gain blocks with Signal Conversion blocks.

Capabilities and Limitations

You can:

  • Run this check on your library models.

  • Exclude blocks and charts from this check if you have a Simulink Check license.

See Also

Use Products and Blocks Supported for Code Generation

Model Advisor Exclusion Overview (Simulink Check)

Check model configuration settings against code generation objectives

Check the configuration parameter settings for the model against the code generation objectives.

Description

Each parameter in the Configuration Parameters dialog box might have different recommended settings for code generation based on your objectives. This check helps you identify the recommended setting for each parameter so that you can achieve optimized code based on your objective.

Results and Recommended Actions

ConditionRecommended Action
Parameters are set to values other than the value recommended for the specified objectives.

Set the parameters to the recommended values.

Note

A change to one parameter value can impact other parameters. Passing the check might take multiple iterations.

Action Results

Clicking Modify Parameters under Action in the check window changes the parameter values to the recommended values.

See Also