Configure AUTOSAR swAddrMethod for global variables automatically generated
69 views (last 30 days)
Show older comments
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
Smita
on 17 Apr 2025
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.
Answers (2)
R
on 28 Dec 2023
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
Smita
on 17 Apr 2025
Hello,
Did anyone got the solution for the above issue. with above setting also issue persists.
Sean
on 14 May 2025
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.
Bence
2 minutes ago
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:
- Create a folder and name it '+myPackage'.
- Open the Custom Storage Class Designer (CSC Designer) by executing the following command:
cscdesigner('myPackage')
Configure Memory Sections:
- Go to the ‘Memory Section’ tab and create 'New Reference' memory section.
- Set 'Refer to memory section in package' to 'AUTOSAR'
- Set 'Memory section to reference' to 'SwAddrMethod'
- 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_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:

0 Comments
See Also
Categories
Find more on AUTOSAR Blockset 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!