If you just want have to have variable in flash, it cannot be done just because variable suppose its location in volatile memory, whilst flash is non-volatile memory.
Here I have described how it is possible to relocate code to the RAM:
https://community.nxp.com/t5/MPC5xxx/MPC560xB-Copy-a-code-from-flash-to-RAM-for-executing-it-in-RAM/...
Similar approach can be used with data as well but
- variable is already located in RAM whilst its default value is being loaded from flash during init, thus I don’t see any reason for relocation
int i = 10;
- if you need specific alignment, use pragma aligned like this (aligns to 8 bytes)
vuint32_t test[2] __attribute__ ((aligned (8))) =
{
0xBABADEDA,
0xABBAABBA
};
- if you really need to access specific address, you can do it as follows where 0x40000000 specifies address (don’t forget to reserve space in linker command file) for this accesses:
*(unsigned int*)0x40000000 = 0x44444444;