Hello! I use mpc5604p and now use CodeWarrior 10.6 compiler. I want to directly define variables in the specified flash area (the flash area is the start page) when compiling the program.
When I use ac512, @ can realize this function. However, mpc5604 failed and the compiler reported an error; Hope to get your help to realize this function, thank you
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:
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 __attribute__ ((aligned (8))) =
- 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;