With Simulink Embedded Coder is it possible to change base workspace variables?
8 views (last 30 days)
Show older comments
Hi all,
We are developing a standalone application for an inverter using MATLAB/Simulink R2022b with Embedded Coder and TIs package for C2000 development. Our target is TIs Launchpad XL based on the F28379D CPU. My goal is to write a Simulink model that can modify onboard flash during runtime, so when power is lost certain calibration values are maintained.
My model currently implements a Simulink reference example: https://nl.mathworks.com/matlabcentral/fileexchange/92788-simulink-reference-application-examples-for-ti-c2000?s_tid=FX_rc1_behav
This works well, but has a major downside: it is only possible to modify the variables in the matlab workspace and then press Ctrl+d to update them on the target machine while connected in external mode over a serial connection. For our devices in the field, we want to get rid of the mandatory external mode and achieve the same over CAN bus.
I have already tried a bunch of things, but none of them yield the desired behavior:
- set_param(): will not work as the calibration values are stored in the MATLAB base workspace. I am not changing blocks.
- assignin(): gives the following error: The function <function_name> is not supported for code generation. Declaring the function as extrinsic via coder.extrinsic does not solve the problem.
- Parameter Writer block: In R2022b this can only modify variables in the model workspace, so I moved the flash related parameters accordingly. However, somehow the parameter writer block just won't find them. My guess is that it is because the parameters are defined in the base workspace as a specific storage class based on the tic2000demospkg.Parameter. In the Code Mappings interface they therefore show up as 'External Parameter Objects' instead of 'Model Parameters.' Based on this article: https://blogs.mathworks.com/simulink/2023/09/27/signals-vs-parameters-in-simulink-and-the-parameter-writer-block/
- MATLAB function block: I was hoping the parameters I defined in the base workspace could be called in a global context. Calling the matlab routine from Simulink showed me this is unfortunately not the case. Implicitly the variable was defined in local context and base variable remained unchanged. Inspecting gave clarity on this.
- For a fact I know that the variables that I want to tune are defined with the mp_ prefix because I configured the identifier for the custom storage class. However, I don't understand on how I want to change these.
Is it at all possible to modify variables? Can someone give me a heads up on how?
Thanks a lot in advance!
Kind regards,
Remi
0 Comments
Answers (1)
Akshat Dalal
on 16 Aug 2024
Hello Remi,
I believe you could try using Data-Stores for this usecase. They are quite useful when you want to have a common memory for reading and writing variables. They have proven useful to me when I wanted to communicate between my child model and test-harness during SIL simulation and might be useful to you too. Please refer the following documentation for more information: www.mathworks.com/help/releases/R2022b/simulink/slref/datastorememory.html
0 Comments
See Also
Categories
Find more on Simulink Coder in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!