Main Content

Evaluate Your Generated Code for MISRA C:2012 Compliance

It is important to check that C code generated by Embedded Coder® from Simulink® and Stateflow® complies with MISRA C:2012 coding standards. This workflow illustrates the process of evaluating your generated code for compliance to MISRA C:2012 guidelines.

  1. Design your model in Simulink or Stateflow.

  2. Open the Model Advisor and run the MISRA C:2012 checks (Simulink Check), which are available in By Task > Modeling Standards for MISRA C:2012.

  3. If necessary, modify the model to adhere to the Modeling Guidelines and Model Advisor Checks for Verifying Compliance with MISRA C:2012.

  4. After the MISRA C:2012 checks pass, generate code by using Embedded Coder.

    To avoid possible name clashes, multiple functions definitions, and multiple data definitions, use one of these code generation approaches:

    • Single model: Generate code from a single model, including submodels, by using Model blocks.

    • Multiple models: Generate code from multiple models, including:

      • A shared utility folder to synchronize functions

      • Data ownership to control data definitions

      • Hand integration to manage code generated from various models

  5. Run the checkers for MISRA C:2012 Directives and Rules (Polyspace Bug Finder).

    For more information about running a Polyspace® analysis on your generated code, including analysis options and results, see:

  6. Justify violations to the MISRA C:2012 coding standards using Polyspace annotations (Polyspace Bug Finder).