
Simulink Embedded Coder: need to define code generation storage class for a block that is part of a library
6 views (last 30 days)
Show older comments
Hello experts,
I am reorganizing an existing Simulink model and would like to move parts of it to a library file so it can be reused.
The model is used to generate C code that runs on a TI C2000 microcontroller. We make use of C2000 Control Law Accelerator (CLA), which requires that variables be placed in certain memory sections - otherwise they are not accessible by the CLA. Note that by default, all variables go in to main microcontroller RAM, which is NOT accessible by the CLA.
My main problem is with "Unit Delay" blocks in the model, which have an internal state variable. Currently, for each Unit Delay block in the project, a "State name" is defined in block parameters. Once "State name" is defined, "Signal object class" and "Code generation storage class" dropdowns become enabled, and it's possible to select a CLA-accessible memory section for the state variable. Everything compiles and works properly this way.
However, some parts of our models are duplicated, and making them part of a library would really help with managing complexity. Once block becomes part of the library, it is no longer possible to define a state name, as they are required to be unique.
We do define a custom storage class, but it has multiple memory sections. To place state variable where it needs to be, it needs to go to a specific memory section within our custom storage class (i.e., "Code generation storage class"). But once I leave "State name" textbox blank, "Code generation storage class" resets to "Auto", and the state variable is not placed in CLA-accessible section of RAM.
Is there a recommended way for handling these situations? Should I define a custom storage class with only one memory section?
Thanks in advance!
1 Comment
Matthew Englehart
on 7 Jul 2025
Edited: Matthew Englehart
on 7 Jul 2025
Hi Pavel, once you place an instance of the library block in the model, you can define a code mapping in the model (not in the library) for that Unit Delay state, specifying both the identifier and storage class for that state.

Answers (1)
Mark McBroom
on 17 May 2025
You could try putting a mask on the library block and adding a mask argument for the State. Then, create a Simuilnk.Signal to represent the state, and set the appropriate storage class settings. Use this new Simulink.Signal as the argument for your newly created masked subsystem.
Thanks.
Mark.
0 Comments
See Also
Categories
Find more on Deployment, Integration, and Supported Hardware in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!