With Simulink Embedded Coder is it possible to change base workspace variables?
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,
RemiHi 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 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 ti, embedded coder, simulink, variables, code generation, matlab code MATLAB Answers — New Questions