Codegeneration Issue, parameters replaced by constants.

11 vues (au cours des 30 derniers jours)
Samuel Narcisse
Samuel Narcisse le 25 Oct 2023
We have been trying to update some autogenerated code we had in matlab2013a to matlab2022b version, because we changed toolchain and dependencies.
To do so, we opened the configuration parameter window codegeneration pane from the old matlab 2013a project, took note of everything that was checked, and tryed to add it to the default ert code generation project added by matlab2022b.
function [] = setCodeGenSettings2022(cs)
%%%% Mainly to set all configs to match 2013 codegen project setting,
%%%% starting from normal template.
% Data Type Replacement
set_param(cs,'EnableUserReplacementTypes','on');
struc = get_param(cs,'ReplacementTypes');
struc.double = 'tmc_real_T';
struc.single = 'tmc_real32_T';
struc.int32 = 'tmc_int32_T';
struc.int16 = 'tmc_int16_T';
struc.int8 = 'tmc_int8_T';
struc.uint32 = 'tmc_uint32_T';
struc.uint16 = 'tmc_uint16_T';
struc.uint8 = 'tmc_uint8_T';
struc.boolean = 'tmc_bolean_T';
set_param(cs,'ReplacementTypes',struc);
% Code Placement
set_param(cs,'ERTFilePackagingFormat','Modular');
% Templates
%%No Tomcat_code_template.cgt available, we use the default
%%ert_code_template.cgt.2013-2022 Diff
% Verification
%%Exactly the same
% Code Style
%%2013-2022 Diff
set_param(cs,'SuppressUnreachableDefaultCases','off')
set_param(cs,'ConvertIfToSwitch','off')
%%2022 New
%%set_param(cs,'PreserveStaticInFcnDecls','true') %% Doesn't exist in 2013,
%%but seems useful.
% Interface
%%2013-2022 Diff
set_param(cs,'SupportNonFinite','off')
set_param(cs,'SupportComplex','off')
set_param(cs, 'CodeInterfacePackaging', 'Reusable function')
set_param(cs, 'RootIOFormat', 'Structure reference')
% Custom Code
%%Exactly the same
% Identifier
%%Exactly the same
% Comments
%%2013-2022 Diff
set_param(cs, 'StateflowObjectComments', 'on') ;
set_param(cs, 'ShowEliminatedStatement', 'off') ;
set_param(cs, 'ForceParamTrailComments', 'off') ;
set_param(cs, 'OperatorAnnotations', 'off') ;
%%2022 New
%%Kept Simulink block Description,Simulink Data Object and State flow
%%Object Description. Seems Relevant.
% set_param(cs, 'InsertBlockDesc', 'off') ;
% set_param(cs, 'SimulinkDataObjDesc', 'off') ;
% set_param(cs, 'SFDataObjDesc', 'off') ;
% Report
%%Exactly the same
% Optimization
%%2013-2022 Diff
set_param(cs,'DefaultParameterBehavior','Inline');
set_param(cs,'OptimizationCustomize','on');
set_param(cs,'DifferentSizesBufferReuse','off');
set_param(cs,'GlobalVariableUsage','None');
set_param(cs,'OptimizeBlockOrder','off');
% Code Generation - Main
%%2013-2022 Diff
set_param(cs,'PackageGeneratedCodeAndArtifacts','on');
set_param(cs,'BuildConfiguration','Faster Runs')
set_param(cs,'ObjectivePriorities', 'MISRA C:2012 guidelines')
end
The result is showed below. The only issue we are having is some simulink named constants blocks (parameters) previously saved as variable parameters in C code, are now saved as hard coded constant parameters. We were wondering, why is this hapenning? What option has not been checked in the configuration parameter ? Or is it something else? Please advise?
Current Code on the left. 2013 code on the right.

Réponse acceptée

Samuel Narcisse
Samuel Narcisse le 25 Oct 2023
ot a answer from Mathworks!
Thx a lot Jason Chen.
To have the parameters stored in variables in the generated code, change the default parameter behavior from "Inlined" to "Tunable". From your MATLAB Answers post, I see the line
set_param(cs,'DefaultParameterBehavior','Inline');
This option will cause Embedded Coder to generate block parameters as constants in order to reduce RAM usage. You can change this line to
set_param(cs,'DefaultParameterBehavior','Tunable');
to have the parameters stored as variables again. See this documentation page for more information: Represent numeric block parameters in generated code - MATLAB (mathworks.com).

Plus de réponses (0)

Catégories

En savoir plus sur Simulink Coder dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by