Skip to Main Content Skip to Search
Product Documentation

Embedded Coder Checks

Checks Overview

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

See Also

Check solver for code generation

Check model solver and sample time configuration settings.

Description

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

Results and Recommended Actions

ConditionRecommended Action
The solver type is set incorrectly for model level code generation.Set Configuration Parameters > Solver >
  • Type to Fixed-step

  • Solver to Discrete (no continuous states)

Multitasking diagnostic options are not set to error.Set Configuration Parameters > Diagnostics >

Tips

You do not have to modify the solver settings to generate code from a subsystem. The Embedded Coder build process automatically changes Solver type to fixed-step when you select Code Generation > Build Subsystem or Code Generation > Generate S-Function from the subsystem context menu.

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 Simulink Coder software.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.

See Also

Supported Products and Block Usage

Identify lookup table blocks that generate expensive out-of-range checking code

Identify lookup table blocks that generate code to protect against out-of-range inputs for breakpoint or index values.

Description

This check verifies that the following blocks do not generate code to protect against inputs that fall outside the range of valid breakpoint values:

This check also verifies that Interpolation Using Prelookup blocks do not generate code to protect against inputs that fall outside the range of valid index values.

Following the recommended actions increases both execution and ROM efficiency of the generated code.

Results and Recommended Actions

ConditionRecommended Action

The lookup table block generates out-of-range checking code.

Change the setting on the block dialog box so that out-of-range checking code is not generated.

  • For the 1-D Lookup Table, 2-D Lookup Table, n-D Lookup Table, and Prelookup blocks, select the check box for Remove protection against out-of-range input in generated code.

  • For the Interpolation Using Prelookup block, select the check box for Remove protection against out-of-range index in generated code.

Action Results

Clicking Modify prevents lookup table blocks from generating out-of-range checking code, which makes the generated code more efficient.

See Also

Check output types of logic blocks

Identify logic blocks that do not use boolean for the output data type.

Description

This check verifies that the output data type of the following blocks is boolean:

Using output data type boolean increases execution efficiency of the generated code.

Results and Recommended Actions

ConditionRecommended Action
The output data type of a logic block is not boolean. In the block dialog box, set Output data type to boolean.

Action Results

Clicking Modify forces logic blocks to use boolean as the output data type. If a logic block uses uint8 for the output type, clicking Modify changes the output type to boolean.

Identify blocks using one-based indexing

Identify blocks using one-based indexing.

Description

Zero-based indexing is more efficient in the generated code than one-based indexing. This check identifies blocks using one-based indexing.

Using zero-based indexing increases execution efficiency of the generated code.

See cgsl_0101: Zero-based indexing.

Results and Recommended Actions

ConditionRecommended Action
The model or subsystem contains blocks configured for one-based indexing.Configure the blocks for zero-based indexing. Update the supporting blocks.
The model or subsystem contains blocks requiring one-based indexing.Evaluate the blocks to determine if one-based indexing is used. Consider replacing the blocks with Simulink basic blocks.

Check the hardware implementation

Identify inconsistent or underspecified hardware implementation settings

Description

The Simulink and Simulink Coder software require two sets of target specifications. The first set describes the final intended production target. The second set describes the currently selected target. If the configurations do not match, the code generator creates extra code to emulate the behavior of the production target. Inconsistencies or underspecification of hardware attributes can lead to inefficient or incorrect code generation for the target hardware.

Results and Recommended Actions

ConditionRecommended Action
Device type is set to Unspecified (assume 32-bit Generic).Set Configuration Parameters > Hardware Implementation > Device type to the target hardware.
Hardware implementation parameters are not set to recommended values.Specify the following Configuration Parameters > Hardware Implementation parameters:
  • Byte ordering

  • Signed integer division rounding

Hardware implementation Embedded hardware settings do not match Emulation hardware settings.Consider selecting the Configuration Parameters > Hardware Implementation > None check box, or modify the settings to match.

See Also

Making GRT-Based Targets ERT-Compatible

Identify questionable software environment specifications

Identify questionable software environment settings.

Description

Results and Recommended Actions

ConditionRecommended Action
The maximum identifier length does not conform with industry standards for C. Set the Configuration Parameters > Code Generation > Symbols > Maximum identifier length parameter to 31 characters.
Configuration Parameters > Code Generation > Interface parameters are not set to recommended values.Clear the following parameters on the Configuration Parameters > Code Generation > Interface pane:
  • Support: continuous time

  • Support: non-finite numbers

  • Support: non-inlined S-functions

Configuration Parameters > Code Generation > Symbols parameters are not set to recommended values.Set the Configuration Parameters > Code Generation > Symbols > Generate scalar inlined parameters as parameter to Literals.
Support: variable-size signals is selected. This might lead to inefficient code.If you do not intend to support variable-sized signals, clear the Code Generation > Interface > Support: variable-size signals check box in the Configuration Parameters dialog box.
The model contains Stateflow charts with weak Simulink I/O data type specifications.Select the Stateflow chart property Use Strong Data Typing with Simulink I/O. You might need to adjust the data types in your model after selecting the property.

Limitations

A Stateflow license is required when using Stateflow charts.

See Also

Strong Data Typing with Simulink I/O

Identify questionable code instrumentation (data I/O)

Identify questionable code instrumentation.

Description

Results and Recommended Actions

ConditionRecommended Action
Interface parameters are not set to recommended values.Set the Configuration Parameters > Code Generation > Interface parameters to the recommended values.
Blocks generate assertion code.Set the Configuration Parameters > Diagnostics > Data Validity > Model Verification block enabling parameter to Disable All on a block-by-block basis or globally.
Block output signals have one or more test points and the Ignore test point signals check box is cleared in the Code Generation pane of the Configuration Parameters dialog box .

Remove test points from the specified block output signals. For each signal, in the Signal Properties dialog box, clear the Test point check box.

Alternatively, if the model is using an ERT-based system target file, select the Ignore test point signals check box in the Code Generation pane of the Configuration Parameters dialog box to ignore test points during code generation.

Check for blocks that have constraints on tunable parameters

Identify blocks with constraints on tunable parameters.

Description

Lookup Table and Lookup Table (2-D) blocks have strict constraints when they are tunable. If you violate lookup table block restrictions, the generated code produces wrong answers.

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.

See Also

Check for blocks not recommended for MISRA-C:2004 compliance

Identify blocks that are not supported or recommended for MISRA-C:2004 compliant code generation.

Description

Following the recommendations of this check increases the likelihood of generating MISRA-C:2004 compliant code for embedded applications.

See hisl_0020: Blocks not recommended for MISRA-C:2004 compliance.

Results and Recommended Actions

ConditionRecommended Action
Blocks that are not supported or recommended for MISRA-C:2004 compliant code generation were found in the model or subsystem. For a list of blocks, see hisl_0020: Blocks not recommended for MISRA-C:2004 compliance.Consider replacing the specified blocks.

Limitations

This check does not review libraries.

See Also

Check configuration parameters for MISRA-C:2004 compliance

Identify configuration parameters that might impact MISRA-C:2004 compliant code generation.

Description

Following the recommendations of this check increases the likelihood of generating MISRA-C:2004 compliant code for embedded applications.

See hisl_0060: Configuration parameters that improve MISRA-C:2004 compliance.

Results and Recommended Actions

ConditionRecommended Action
Model Verification block enabling is set to Use local settings or Enable All.In the Configuration Parameters dialog box, on the Diagnostics > Data Validity pane, set Model Verification block enabling to Disable All.
System target file is set to a GRT-based target.In the Configuration Parameters dialog box, on the Code Generation > General pane, set System target file to an ERT-based target.
Code Generation > Interface parameters are not set to the recommended values.In the Configuration Parameters dialog box, on the Code Generation > Interface pane:
  • Clear Support: non-finite numbers

  • Clear Support: continuous time (ERT-based target only)

  • Clear Support: non-inlined S-functions (ERT-based target only)

  • Clear MAT-file logging

  • Set Code replacement library to C89/C90 (ANSI)

Parenthesis level is not set to Maximum (Specify precedence with parentheses).In the Configuration Parameters dialog box, on the Code Generation > Code Style pane, set Parenthesis level to Maximum (Specify precedence with parentheses).
Maximum identifier length is not set to 31.In the Configuration Parameters dialog box, on the Code Generation > Symbols pane, set Maximum identifier length to 31.

Action Results

Clicking Modify All changes the parameter values to the recommended values.

Limitations

This check does not review referenced models.

See Also

Check for model reference configuration mismatch

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.

Results and Recommended Actions

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

See Also

Model Referencing Configuration Parameter Requirements

Identify blocks that generate expensive saturation and rounding code

Check for blocks that generate expensive saturation or rounding code.

Description

Results and Recommended Actions

ConditionRecommended Action
Blocks generate expensive saturation code.Check whether your application requires setting Function Block Parameters > Signal Attributes > Saturate on integer overflow. Otherwise, clear the Saturate on integer overflow parameter for the most efficient implementation of the block in the generated code.
Generated code is inefficient.Set the Function Block Parameters > Integer rounding mode parameter to the recommended value.

Check sample times and tasking mode

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.

Results and Recommended Actions

ConditionRecommended Action
The model represents a multirate system but is not configured for multitasking.Set the Configuration Parameters > Solver > Tasking mode for periodic sample times parameter as recommended.
The model is configured for multitasking, but multitasking is not desirable on the target hardware.Set the Configuration Parameters > Solver > Tasking mode for periodic sample times parameter to SingleTasking, or change the Configuration Parameters > Hardware Implementation settings.

See Also

Single-Tasking and Multitasking Execution Modes

Identify questionable subsystem settings

Identify questionable subsystem block settings.

Description

Subsystem blocks implemented as void/void functions in the generated code use global memory to store the subsystem I/O.

Results and Recommended Actions

ConditionRecommended Action
Subsystem blocks have the Subsystem Parameters > Function packaging option set to Function.Set the Subsystem Parameters > Function packaging parameter to Auto.

See Also

Subsystem block

Identify questionable fixed-point operations

Identify fixed-point operations that can lead to nonoptimal results.

Description

The following operations can lead to nonoptimal results:

Results and Recommended Actions

ConditionsRecommended Action
Integer division generated code is large.Set the Configuration Parameters > Hardware Implementation > Signed integer division rounds to parameter to the recommended value.
Protection code generated as part of the division operation is redundant.Verify that your model cannot cause exceptions in division operations and then remove redundant protection code by setting the Configuration Parameters > Optimization > Remove code that protects against division arithmetic exceptions parameter.
Generated code is inefficient.Set the Function Block Parameters > Integer rounding mode parameter to the recommended value.
Lookup Table vector of input values is not evenly spaced.If breakpoint data is nontunable, adjust the data to have even, power of 2 spacing. See fixpt_look1_func_approx.
Lookup Table vector of input values is not evenly spaced when quantized, but it is very close to being evenly spaced.If breakpoint data is nontunable, adjust the data to have even, power of 2 spacing. See fixpt_evenspace_cleanup.
Lookup Table vector of input values is evenly spaced, but the spacing is not a power of 2.If breakpoint data is nontunable, adjust the data to have even, power of 2 spacing. See fixpt_look1_func_approx.
For a Prelookup or n-D Lookup Table block, Index search method is Evenly spaced points. Breakpoint data does not have power of 2 spacing.If breakpoint data is nontunable, adjust the data to have even, power of 2 spacing. Otherwise, in the block parameter dialog box, specify a different Index search method to avoid the computation-intensive division operation.
n-D Lookup Table breakpoint data is not evenly spaced and Index search method is not Evenly spaced points.If breakpoint data is nontunable, adjust the data to have even, power of 2 spacing and then set Index search method to Evenly spaced points.
n-D Lookup Table breakpoint data is evenly spaced and Index search method is Evenly spaced points. But the spacing is not a power of 2.If breakpoint data is nontunable, adjust the data to have even, power of 2 spacing. See fixpt_look1_func_approx.
n-D Lookup Table breakpoint data is evenly spaced, but the spacing is not a power of 2. Also, Index search method is not Evenly spaced points.Set Index search method to Evenly spaced points. Also, if the data is nontunable, consider an even, power of 2 spacing.
n-D Lookup Table breakpoint data is evenly spaced, and the spacing is a power of 2. But the Index search method is not Evenly spaced points.Set Index search method to Evenly spaced points.
Blocks require cumbersome multiplication. Restrict multiplication operations:
  • So the product integer size is not larger than the target integer size.

  • To the recommended size.

Blocks multiply signals with nonzero bias.Insert a Data Type Conversion block before and after the block containing the multiplication operation.
Product blocks are multiplying signals with mismatched slope adjustment factors.Change the scaling of the output so that its slope adjustment factor is the product of the input slope adjustment factors.
Product blocks are multiplying signals with mismatched slope adjustment factors. The net slope correction uses multiplication followed by shifts, which is inefficient for some target hardware.Select Use integer division to handle net slopes that are reciprocals of integers if the net slope is the reciprocal of an integer and division is more efficient than multiplication and shifts on the target hardware.

    Note   This optimization takes place only if certain simplicity and accuracy conditions are met. For more information, see Handle Net Slope Correction in the Simulink Fixed Point documentation.

Product blocks are configured to do multiple division operations.Multiply all the denominator terms together, and then do a single division using cascading Product blocks.
Product blocks are configured to do many multiplication or division operations.Split the operations across several blocks, with each block performing one multiplication or one division operation.
Product blocks are configured with a divide operation for the first input and a multiply operation for the second input. Reverse the inputs so the multiply operation occurs first and the division operation occurs second.
An input with an invariant constant value is used as the denominator in an online division operation. Change the operation to multiplication, and replace the invariant input by its reciprocal.
The data type range of the inputs of Sum blocks exceeds the data type range of the output, which can cause overflow or saturation.

Change the output and accumulator data types so the range equals or exceeds all input ranges.

For example, if the model has two inputs

  • int8 (–128 to 127)

  • uint8 (0 to 255)

The data type range of the output and accumulator must equal or exceed –128 to 255. A int16 (–32768 to 32767) data type meets this condition.

A Sum block has an input with a slope adjustment factor that does not equal the slope adjustment factor of the output.Change the data types so the inputs, outputs, and accumulator have the same slope adjustment factor.
The net sum of the Sum block input biases does not equal the bias of the output. Change the bias of the output scaling, making the net bias adjustment zero.
The inputs of the Relational Operator block have different data types.
  • Change the data type and scaling of the invariant input to match other inputs.

  • Insert Data Type Conversion blocks before the Relational Operator block to convert both inputs to a common data type.

The inputs of the Relational Operator block have different slope adjustment factors.Change the scaling of either input.
The output of the Relational Operator block is constant. This might result in dead code which will be eliminated by Simulink Coder.Review your model design and either remove the Relational Operator block or replace it with the constant.
The input and output of the MinMax block have different data types.Change the data type of the input or output.
The input of the MinMax block has a different slope adjustment factor than the output. Change the scaling of the input or the output.
The initial condition of the Discrete-Time Integrator block is used to initialize both the state and the output. Set the Function Block Parameters > Use initial condition as initial and reset value for parameter to State only (most efficient).
Parameter overflow occurred for the Compare to Zero block. This block uses the input data type to represent zero. The input data type cannot represent zero exactly, so the input value was compared to the closest representable value of zero.Select an input data type that can represent zero.
Parameter overflow occurred for the following Compare to Constant block. This block uses the input data type to represent its Constant value parameter. The Constant value parameter is outside the range that the input data type can represent. The input signal was compared to the closest representable value of the Constant value parameter.Choose an input data type that can represent the Constant value parameter or change the Constant value parameter to match the input data type.

Limitations

A Simulink Fixed Point license is required to generate fixed-point code.

See Also

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 changes the parameter values to the recommended values.

See Also

Check for efficiency optimization parameters

Identify optimization parameters that depend on the Execution efficiency or ROM efficiency objectives.

Description

Setting the optimization parameter Use memcpy for vector assignment to the recommended value increases the execution efficiency and reduces ROM usage.

Results and Recommended Actions

ConditionRecommended Action
The model specifies an execution or ROM efficiency objective and the Use memcpy for vector assignment parameter is cleared.In the Configuration Parameters dialog box, on the Optimization > Signals and Parameters pane, select Use memcpy for vector assignment.

Action Results

Clicking Modify changes the parameter value to the recommended value.

Limitations

This check is in the Code Generation Advisor only.

See Also

  


Related Products & Applications

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.

 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS