Model configuration for code generation helps set up how your Simulink model turns into code. It makes sure the generated code works well and fits your needs.
Model configuration for code generation in Simulink
1. Open your Simulink model. 2. Go to the menu: Simulation > Model Configuration Parameters. 3. In the Configuration Parameters window, select Code Generation. 4. Set the System target file (e.g., ert.tlc for embedded code). 5. Adjust settings like Optimization, Interface, and Toolchain. 6. Click Apply and OK to save.
You can save your configuration settings as a preset for reuse.
Some options depend on the target hardware and code generator you choose.
System target file: ert.tlc Optimization: Execution efficiency Toolchain: GNU GCC Embedded
System target file: grt.tlc Generate code only: Enabled Interface: Model reference
This MATLAB script opens a Simulink model named 'simple_model', sets code generation options for embedded C code, builds the model to generate code, and then closes the model.
% Open Simulink model model = 'simple_model'; open_system(model); % Set code generation parameters set_param(model, 'SystemTargetFile', 'ert.tlc'); set_param(model, 'GenerateReport', 'on'); set_param(model, 'Toolchain', 'GNU GCC Embedded'); set_param(model, 'Optimization', 'Execution efficiency'); % Build the model to generate code rtwbuild(model); % Close the model close_system(model, 0);
Always verify your code generation settings before building to avoid errors.
Generated code can be large; use optimization settings to reduce size if needed.
Use the Simulink Coder documentation for detailed explanations of each option.
Model configuration sets how Simulink generates code from your model.
You choose target hardware, optimization, and interface options.
Proper configuration helps create efficient and usable code for your project.