Hello,

today i was trying to create a persistent variable (A variable wich get not initialized on startup). I tried many ways like:

BOOL __attribute__((persistent)) my_pers_var;
BOOL __attribute__((__persistent)) my_pers_var;
BOOL __attribute__ ((noload)) my_pers_var; /* Like in www.microchip.com/support/KBArticle.aspx?KBID=KB100239 */
BOOL __attribute__((persistent), address(0xA0001000) my_pers_var; /* This worked either, but is not very dynamic */

So the solution is the following declaration:

BOOL __attribute__((persistent, section(".persist"))) my_pers_var;

Explaination: The Attribute ‚persistent‘ marks the variable as persistant.
The section „.persist“ let the memory be saved in the persists section.

Should the section attribute not be enought?No, because its a special marked memory range which only stores persistent variables.
Now the map file looks how i want it to be 🙂

.persist        0xa0000000        0x4
0xa0000000                _persist_begin = .
*(.persist .persist.*)
.persist.my_pers_var
0xa0000000        0x4 build/XC32_PIC32MX460F512L/production/_ext/906281160/main.o
0xa0000000                my_pers_var
*(.pbss .pbss.*)
0xa0000004                . = ALIGN (0x4)
0xa0000004                _persist_end = .

I’am using
XC32 v1.31
PIC32MX450F256L
MPLAB X IDE v2.10

I hope i could help someone with this 🙂