If you have Simulink® Coder™ or Embedded Coder®, you can generate C or C++ code from Simulink models that include Stateflow® blocks.
|Use||Required Software License||Description|
|Rapid prototyping||Simulink Coder||Generate source code that you can use for real-time and nonreal-time applications, including simulation acceleration, rapid prototyping, and hardware-in-the-loop testing.|
|Production code deployment||Embedded Coder||Generate readable, compact, and fast code for use on embedded processors, on-target rapid prototyping boards, and microprocessors used in mass production.|
The generated code does not contain code to interface with other blocks in a Simulink model or the MATLAB® base workspace. You cannot generate code only for the Stateflow blocks in a library model. First create a link to the library block in your main model and then generate code for the main model.
This table directs you to information about code generation based on your goals.
Simulink Coder Documentation
Embedded Coder Documentation
Generate C/C++ source code
Code Generation Basics (Simulink Coder)
Code Generation Basics (Embedded Coder)
Generate C/C++ source code and build executable
Build Process (Simulink Coder)
Build Process (Embedded Coder)
Integrate external code
External Code Integration (Simulink Coder)
External Code Integration (Embedded Coder)
Include external code only for library charts in a portable, self-contained library for use in multiple models
Integrate External Code for Library Charts (Simulink Coder)
Integrate External Code for Library Charts (Embedded Coder)
Optimize generated code
Traceability comments provide a way to:
Verify generated code. You can identify which Stateflow object corresponds to a line of code and track code from different objects that you have or have not reviewed.
Include comments in code generated for large-scale models. You can identify objects in generated code and avoid manually entering comments or descriptions.
To enable traceability comments, you must have Embedded
Coder or HDL Coder™ software. For C/C++ code generation, comments appear in the generated
code for embedded real-time (
ert) based targets only. For more
information, see Trace Stateflow Elements in Generated Code (Embedded Coder) and Navigate Between Simulink Model and HDL Code by Using Traceability (HDL Coder).