MISRA rules violations of Generated Code for Embedded Coder

13 views (last 30 days)
Hi,
I am using Embedded Coder to generate C source code from a Simulink model, selecting MISRA-C compliance objective, and when I run Polyspace analysis, I get lots of MISRA rules violations.
How can this be fixed?
Regards.

Answers (3)

Anirban
Anirban on 4 Oct 2018
In addition to the previous answer, another possibility can be that you ran Polyspace for MISRA rules meant for handwritten code and not generated code. MISRA C:2012 (Appendix E) moves several rules from the Required category to the Advisory or Readability category if the code is generated from a model. If you ran Polyspace with the Required subset of MISRA C:2012 checkers for handwritten code, you might get more violations compared to the Required subset for generated code.
To run Polyspace with the MISRA C:2012 checker for generated code, use the Polyspace option Use generated code requirements ( -misra3-agc-mode). See documentation for the option . If you run Polyspace directly from Simulink, this option gets enabled automatically.

Prakhar Jain
Prakhar Jain on 25 Sep 2018
The rules of MISRA C:2012 often gets updated with newer releases and a variety of reasons can be responsible for the violation. Please find the below rules for violation scenarios which has been made for the later releases and may be causing violations.
1) If there are identifiers beginning with underscore
2) If a reserved identifier or macro name is declared
Note: The above possible workaround may/may not work for your case.
In case you only expect to remove the warnings, you can always uncheck rules in the Coding Rules & Code Metrics in the configuration pane. Follow the below steps:
1) Open configuration pane
2) Click on the edit button as seen in the screenshot in red
3) Go to let's say rule no 21.2 and uncheck it as shown in screenshot in red
Here is an attached link for the same.
The above remove warnings can also be unchecked for other rule violations if required.

Michael Burke
Michael Burke on 2 Dec 2019
Note: one thing that you should look at is the model configuration parameters. This link provides a good overview of what you should do to configure your model:

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!