How to place code generated from subsystem into RAM on Ti C2000?

I am trying to plase parts of the code generated from one of the subsystems into RAM to speed up execution. The help provided in Control Data and Function Placement in Memory by Inserting Pragmas is not sufficient.
Is there a better explanation on how to add #pragma CODE_SECTION(myCriticalTask, "ramfuncs") to the generated function?
Do I need to edit linker command file?
Do I need to add code to copy function from flash to RAM on power up?
Thanks.

Answers (2)

Hi @Valeriy,
Good question — this trips up a lot of people because the MathWorks documentation focuses on the pragma setup but glosses over the full picture. Let me try to fill in the gaps.
1. Adding the pragma to generated code
If you're on the C2000 Blockset, the easiest route is already built in. Run `cscdesigner` in MATLAB, select the `tic2000demospkg` package, and check the Memory Sections tab — you'll see `code_ramfuncs` already defined. To apply it to your subsystem, just right-click the subsystem → Block Parameters → Code Generation tab, and select `code_ramfuncs` under the execution functions memory section. No manual pragma writing needed.
If you're on a different target or want full control, you can create a custom memory section in the Embedded Coder Dictionary. Set the Pre Statement to `#pragma CODE_SECTION($N, "ramfuncs")` — the `$N` is a token that automatically gets replaced with the actual function name at code generation time.
2. Linker command file
You probably don't need to write one from scratch. The shipping `.cmd` file for your specific C2000 device already has a `ramfuncs` section defined. You can find and inspect it in Configuration Parameters → Hardware Implementation → Build Options → Linker command file → Edit. Just make sure the section name in your pragma matches what's in the `.cmd` file exactly.
3. Copying from flash to RAM at startup — yes, this is required This is the part that catches most people. The pragma and linker script set up the load/run addresses, but nothing moves the code automatically. You need to call memcpy in your startup code before any of those functions are ever invoked:
`memcpy(&RamfuncsRunStart, &RamfuncsLoadStart, (Uint32)&RamfuncsLoadSize);`
The symbols `RamfuncsRunStart`, `RamfuncsLoadStart`, and `RamfuncsLoadSize` are generated automatically by the linker based on your `.cmd` file. In a Simulink workflow, drop this into Configuration Parameters -> Code Generation -> Custom Code -> Initialize function section.
Hope this helps!
Umar,
Thank you for the prompt and detailed answer. You put me on the right path, but I am missing one step.
How do I get the values from tic2000demospkg to show in the memory selection field of my subsystem? I only have selection from the Simulink package:

2 Comments

Hi @Valeriy,
Glad you're making progress! The reason you're only seeing the Simulink package options (MemConst, MemVolatile, etc.) is that the tic2000demospkg package hasn't been loaded into your model yet — the dropdown only shows sections from packages that are actively registered with the model.
Here's how to fix it:
Step 1 — Load the package into your model
Open the Embedded Coder app, then go to C Code → Code Interface → Embedded Coder Dictionary. Inside the dictionary window, look for a "Manage Packages" option. If tic2000demospkg doesn't appear in the list, click Refresh to scan for installed packages, then load it.
Step 2 — Check "Function with separate data"
Looking at your screenshot, I can see the "Function with separate data" checkbox is unchecked. You'll want to tick that box — without it, the memory section fields for subsystem data either stay limited or inherit from the model level, and some options won't show up. Once checked, you'll get the full set of memory section dropdowns for both initialize/terminate and execution functions.
After both steps, code_ramfuncs should appear in the dropdown and you can apply it directly to the subsystem.
Let me know if it shows up after the refresh!
Hi @Valeriy, Please let me know if you need any further assistance.

Sign in to comment.

Categories

Find more on Deployment, Integration, and Supported Hardware in Help Center and File Exchange

Asked:

on 11 Mar 2026 at 19:05

Commented:

on 15 Mar 2026 at 6:27

Community Treasure Hunt

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

Start Hunting!