Simulink Embedded Coder Zero Initialization of Local Variables Not Working

8 visualizzazioni (ultimi 30 giorni)
Hello, I am using Embedded Coder on Simulink Model (MATLAB 2022B). I want Local variables of generated code to be initialized to zero. I already unticked 'Remove root level I/O zero initialization' and 'Remove internal data zero initialization' so code shouldn't optimize initializations. These two settings initialize Global variables to zero, but don't initialize Local variables to zero. There is an example of generated code and how I want it to be. How can I do it? Thanks for your help.
How it is:
void step_function(uint16_t in1, uint16_t in2)
{
uint16_t Divide;
uint16_t UnitDelay1;
...
How it should be:
void step_function(uint16_t in1, uint16_t in2)
{
uint16_t Divide = 0;
uint16_t UnitDelay1 = 0;
...

Risposte (1)

Akshat Dalal
Akshat Dalal il 16 Ago 2024
Modificato: Akshat Dalal il 16 Ago 2024
Hi Furkan,
There can still be some other optimizations which can remove the zero-initialization code. You could either disable all optimizations, or a simpler approach would be unset the 'RemoveLocalVariableInitialization'. This would ensure no optimization removes the zero-initialization.
However, this is introduced in R2023b version of MATLAB. I would suggest you to update to R2023b or later releases to avail this feature.

Categorie

Scopri di più su Deployment, Integration, and Supported Hardware in Help Center e File Exchange

Prodotti


Release

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by