Configure AUTOSAR swAddrMethod for global variables automatically generated

In our Simulink model mapped to AUTOSAR I could mapped each Function to the specific swAddrMethod and I get the code I expected:
/* SwAddrMethod QM_PERIODICAL_CODE for Runnable */
#define MySWComponent_START_SEC_QM_PERIODICAL_CODE
#include "MySWComponent_MemMap.h"
void MyFunc(void)
{
/*****/
}
#define MySWComponent_STOP_SEC_QM_PERIODICAL_CODE
#include "MySWComponent_MemMap.h"
I also create a swAddrMethod = QM_VAR_INIT (sectionType = var)
but how can I map the global variable automatically created after code generation in a specific memory section?
For example after code generation I found the following global struct
/* PublicStructure Variables for Internal Data */
ARID_DEF_CtApOutputSignal_T CtApOutputSignal_ARID_DEF;
and I would like to get something like:
/* SwAddrMethod QM_RTE_VAR_INIT for Internal Data */
#define MySWComponent_START_SEC_QM_VAR_INIT
#include "MySWComponent_MemMap.h"
ARID_DEF_CtApOutputSignal_T CtApOutputSignal_ARID_DEF;
#define MySWComponent_STOP_SEC_QM_VAR_INIT
#include "MySWComponent_MemMap.h"

1 Comment

Hello Elisa,
Did the issue got resolved? I have the same issue. not able to get the solution. If you have any solution got please suggest me.

Sign in to comment.

Answers (2)

Hi Elisa,
Enabling the 'Generate separate internal data per entry-point function' in the model's config settings allows for assigning memory sections to internal data:
This separation results in distinct structures for the internal data of each runnable. By specifying the SwAddrMethod for internal data of individual runnables as needed, you can generate the desired pragmas/memory sections for internal data.
Please see below screenshots for detailed steps:
Hope this helps!

4 Comments

Hello, I have the same issue. I tryed the described configurations in Code generation settings for Interface. But I get still the same result.
All functions and variables are mapped correctlictly. But the only chart inside of a subsystem is defined as a publicstructure variable for internal data in the generated c-code, which is not mapped (memory section) at all.
Is there any specific configuration parameter for stateflow logics in code generation section?
#include "CtAp_EMES.h"
#include "Platform_Types.h"
#include "Rte_Type.h"
/* Named constants for Chart: '<S1>/Chart' */
#define CtAp_EMES_IN_InitMode ((uint8)1U)
#define CtAp_EMES_IN_NotReadyMode ((uint8)2U)
*****************************************************************************
*****************************************************************************
/* PublicStructure Variables for Internal Data */
ARID_DEF_CtAp_EMES_T CtAp_EMES_ARID_DEF;/* '<S1>/Chart' */
*****************************************************************************
*****************************************************************************
*** This part is not mapped in memory section.
/* Model step function for TID1 */
/* SwAddrMethod OSCORE1_CODE_1MS for Runnable */
#define CtAp_EMES_START_SEC_OSCORE1_CODE_1MS
#include "CtAp_EMES_MemMap.h"
void EMES_1ms(void) /* Explicit Task: EMES_1ms */
{
float32 tmp;
uint8 EMES_ECUSt;
/* RootInportFunctionCallGenerator generated from: '<Root>/EMES_1ms' incorporates:
* SubSystem: '<Root>/EMES_1ms_sys'
*/
/* Chart: '<S1>/Chart' incorporates:
* Inport: '<Root>/R_IIAL_IDcMeasd_IIAL_IDcMeasd'
* Inport: '<Root>/R_IIAL_bAcvBusWup_IIAL_bAcvBusWup'
* Sum: '<S3>/Add'
*/
if (CtAp_EMES_ARID_DEF.is_active_c3_CtAp_EMES == 0U) {
CtAp_EMES_ARID_DEF.is_active_c3_CtAp_EMES = 1U;
CtAp_EMES_ARID_DEF.is_c3_CtAp_EMES = CtAp_EMES_IN_InitMode;
CtAp_EMES_ARID_DEF.Tick = 0.0F;
CtAp_EMES_ARID_DEF.Time = 4.0F;
CtAp_EMES_ARID_DEF.b = 0U;
EMES_ECUSt = SMECU_Init;
} else if (CtAp_EMES_ARID_DEF.is_c3_CtAp_EMES == CtAp_EMES_IN_InitMode) {
EMES_ECUSt = SMECU_Init;
/* Outputs for Atomic SubSystem: '<S1>/Subsystem' */
/* Sum: '<S3>/Add' incorporates:
* Inport: '<Root>/R_IIAL_IDcMeasd_IIAL_IDcMeasd'
*/
tmp = Rte_IRead_EMES_1ms_R_IIAL_IDcMeasd_IIAL_IDcMeasd();
if ((Rte_IRead_EMES_1ms_R_IIAL_bAcvBusWup_IIAL_bAcvBusWup() == 1) &&
(CtAp_EMES_ARID_DEF.b == 1) && (tmp + tmp > tmp)) {
CtAp_EMES_ARID_DEF.is_c3_CtAp_EMES = CtAp_EMES_IN_NotReadyMode;
CtAp_EMES_ARID_DEF.Tick = 0.0F;
CtAp_EMES_ARID_DEF.b = 0U;
EMES_ECUSt = SMECU_NotReady;
} else {
if (CtAp_EMES_ARID_DEF.Time <= CtAp_EMES_ARID_DEF.Tick) {
CtAp_EMES_ARID_DEF.b = 1U;
}
CtAp_EMES_ARID_DEF.Tick += 0.001F;
}
/* End of Outputs for SubSystem: '<S1>/Subsystem' */
} else {
/* case IN_NotReadyMode: */
EMES_ECUSt = SMECU_NotReady;
if ((Rte_IRead_EMES_1ms_R_IIAL_bAcvBusWup_IIAL_bAcvBusWup() == 0) &&
(CtAp_EMES_ARID_DEF.b == 1)) {
CtAp_EMES_ARID_DEF.is_c3_CtAp_EMES = CtAp_EMES_IN_InitMode;
CtAp_EMES_ARID_DEF.Tick = 0.0F;
CtAp_EMES_ARID_DEF.Time = 4.0F;
CtAp_EMES_ARID_DEF.b = 0U;
EMES_ECUSt = SMECU_Init;
} else {
if (CtAp_EMES_ARID_DEF.Time <= CtAp_EMES_ARID_DEF.Tick) {
CtAp_EMES_ARID_DEF.b = 1U;
}
CtAp_EMES_ARID_DEF.Tick += 0.001F;
}
}
/* End of Chart: '<S1>/Chart' */
/* End of Outputs for RootInportFunctionCallGenerator generated from: '<Root>/EMES_1ms' */
/* Outport: '<Root>/P_EMES_CtrlMode_EMES_CtrlMode' */
Rte_IWrite_EMES_1ms_P_EMES_CtrlMode_EMES_CtrlMode(U_CONTROL);
/* Outport: '<Root>/P_EMES_ECUSt_EMES_ECUSt' */
Rte_IWrite_EMES_1ms_P_EMES_ECUSt_EMES_ECUSt(EMES_ECUSt);
/* Outport: '<Root>/P_EMES_EnControl_EMES_EnControl' */
Rte_IWrite_EMES_1ms_P_EMES_EnControl_EMES_EnControl(Disabled);
/* Outport: '<Root>/P_EMES_RespSst_EMES_RespSst' */
Rte_IWrite_EMES_1ms_P_EMES_RespSst_EMES_RespSst(0U);
/* Outport: '<Root>/P_EMES_StBswShtdnReq_EMES_StBswShtdnReq' */
Rte_IWrite_EMES_1ms_P_EMES_StBswShtdnReq_EMES_StBswShtdnReq(0U);
/* Outport: '<Root>/P_EMES_StCanRdy_EMES_StCanRdy' */
Rte_IWrite_EMES_1ms_P_EMES_StCanRdy_EMES_StCanRdy(0U);
/* Outport: '<Root>/P_EMES_StInin_EMES_StInin' */
Rte_IWrite_EMES_1ms_P_EMES_StInin_EMES_StInin(0U);
/* Outport: '<Root>/P_EMES_StOperModeForCus_EMES_StOperModeForCus' */
Rte_IWrite_EMES_1ms_P_EMES_StOperModeForCus_EMES_StOperModeForCus(0U);
/* Outport: '<Root>/P_EMES_SwRst_EMES_SwRst' */
Rte_IWrite_EMES_1ms_P_EMES_SwRst_EMES_SwRst(0U);
/* Outport: '<Root>/P_EMES_TempWarnSts_EMES_TempWarnSts' */
Rte_IWrite_EMES_1ms_P_EMES_TempWarnSts_EMES_TempWarnSts(0U);
}
#define CtAp_EMES_STOP_SEC_OSCORE1_CODE_1MS
#include "CtAp_EMES_MemMap.h"
/* Model initialize function */
/* SwAddrMethod OSCORE1_CODE_INIT for Runnable */
#define CtAp_EMES_START_SEC_OSCORE1_CODE_INIT
#include "CtAp_EMES_MemMap.h"
void EMES_Init(void)
{
/* SystemInitialize for RootInportFunctionCallGenerator generated from: '<Root>/EMES_1ms' incorporates:
* SubSystem: '<Root>/EMES_1ms_sys'
*/
/* SystemInitialize for Outport: '<Root>/P_EMES_ECUSt_EMES_ECUSt' incorporates:
* Chart: '<S1>/Chart'
*/
Rte_IWrite_EMES_Init_P_EMES_ECUSt_EMES_ECUSt(SMECU_Init);
/* End of SystemInitialize for RootInportFunctionCallGenerator generated from: '<Root>/EMES_1ms' */
}
#define CtAp_EMES_STOP_SEC_OSCORE1_CODE_INIT
#include "CtAp_EMES_MemMap.h"
Thanks a lot for any help!
Hi,Samin,I have the same problem as you,Did you solve it?
Hello,
Did anyone got the solution for the above issue. with above setting also issue persists.
I have the same issue on a model using the Autosar coder. It's generated a structure to store some unit delays in my model. Because they're inside a For-Each subsystem, I can't map them to StaticMemory, as I get an error about an unstructured storage class when I try to generate the code. I applied the settings shown above but it makes no difference.

Sign in to comment.

Hello All,
I have only tested this workflow in the R2024b release. This involves creating a custom package and setting some hidden parameters of the model configuration set.
Creating the custom package:
  1. Create a folder and name it '+myPackage'.
  2. Open the Custom Storage Class Designer (CSC Designer) by executing the following command:
cscdesigner('myPackage')
Configure Memory Sections:
  1. Go to the ‘Memory Section’ tab and create 'New Reference' memory section.
  2. Set 'Refer to memory section in package' to 'AUTOSAR'
  3. Set 'Memory section to reference' to 'SwAddrMethod'
  4. Name the Memory Section with a name you would like to use in the memory mapping macro generated into the code, e.g.: "InternalDataMemorySection"
Set the Memory Sections for the Internal Data structure using these commands (see: Internal data):
set_param(mdlConfigSet,"MemSecPackage","myPackage"); % Set the memory section package to be used by the model/configSet
set_param(mdlConfigSet,'MemSecDataInternal',"InternalDataMemorySection");
After completing these steps, restart MATLAB to apply the changes to the custom package.
You can also find additional 'MemSec'-related configuration set parameters by typing 'memsec' in the MathWorks online documentation serach bar:

Categories

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

Asked:

on 13 Oct 2023

Answered:

on 5 Dec 2025

Community Treasure Hunt

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

Start Hunting!