Code Generation error for data type inside Stateflow Chart

7 views (last 30 days)
Why do not the options specified in the Custom Code pane of the Simulation target allow my model to compile in Simulink?
I am calling a custom C function from a Stateflow chart. I am specifying the source file in the custom code section of the Simulation target. The model does not compile. I have the following C function declaration in the Source file pane.
 
real_T SquareMe(real_T xs);
However, if the same options are specified in the Custom Code pane of the Simulink Coder, it generates correct code. I am wondering why do the same options not work for Simulation target.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 3 Mar 2014
Stateflow requires having function declarations in a header file since they apply code generation in the background. A code will need its input or outputs defined during compilation. This is the reason #include becomes mandatory for Stateflow. If all usages of the variable from inside the Stateflow chart as well as its definition in Model Workspace are removed OR if there is no physical connection to and from the chart to the data types, be it custom type, simulation will work.
This header file should be included in the header file pane of the custom code section. Simulink Coder generates a single model.c file and having the function declaration in the source code section works. However, Stateflow generates one C file for the chart and some other C files all of which need the declaration of the custom function. Therefore having a header file is a best practice while declaring a custom C function. Please refer to the attached models for examples.

More Answers (0)

Categories

Find more on Simulink Coder in Help Center and File Exchange

Tags

No tags entered yet.

Products


Release

R2012b

Community Treasure Hunt

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

Start Hunting!