How can I configure the Matlab coder to generate very simple C-code?

2 次查看(过去 30 天)
I have a relatively simple Simulink model that I would like to generate C-code for. When I run the code builder, I get an assortment of files that include many other functions and RAM structures that make reading and understanding the code more difficult. Is there a way to adjust the configuration parameters to generate a much simpler code with fewer files? And/or are there ways to configure the signals that would control how they are implemented in the code? Ideally I would like to see something that would resemble the "hand code" files that I would generate.

回答(1 个)

Abhas
Abhas 2024-10-29
To simplify the generated code to make it more straightforward and closer to hand-written code here are some suggestions:
  1. Choose the Right System Target File: If you have Embedded Coder, try using "ert.tlc" instead of "grt.tlc" for more streamlined code. You may refer to the below link to know more about the same: https://www.mathworks.com/help/ecoder/index.html#:~:text=Embedded%20Coder%C2%AE%20generates%20readable%2C%20compact%2C%20and%20fast%20C%20and%20C%2B%2B%20code%20for%20embedded%20processors%20used%20in%20mass%20production
  2. Simplify Function Packaging: Set the "Code interface packaging" to "Nonreusable function" to reduce the number of generated files. You can know more about it from the below link: https://www.mathworks.com/help/rtw/ref/codeinterfacepackaging.html
  3. Signal and Memory Management: Disable Signal "storage reuse" for clearer code, and enable "Remove unused functions" to avoid unnecessary code.
  4. Combine Functions: You can enable "Combine output" and "update functions" to minimize function calls in the code.
You may also refer to the below MATLAB Answers post to gain some more insights: https://www.mathworks.com/support/search.html/answers/764006-readability-of-matlab-code.html

类别

Help CenterFile Exchange 中查找有关 Simulink Coder 的更多信息

产品


版本

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by