{"id":61,"date":"2014-06-06T18:23:21","date_gmt":"2014-06-06T16:23:21","guid":{"rendered":"http:\/\/pustekuchen.xn--burkfrulein-q8a.de\/?p=61"},"modified":"2014-06-06T18:23:21","modified_gmt":"2014-06-06T16:23:21","slug":"xc32-persistent-variable","status":"publish","type":"post","link":"https:\/\/blog.bur-k.de\/?p=61","title":{"rendered":"XC32 persistent Variable"},"content":{"rendered":"

Hello,<\/p>\n

today i was trying to create a persistent variable (A variable wich get not initialized on startup). I tried many ways like:
\n<\/code><\/p>\n

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

So the solution is the following declaration:
\n
\n<\/code><\/p>\n

BOOL __attribute__((persistent, section(\".persist\"))) my_pers_var;<\/pre>\n

Explaination:<\/strong> The Attribute ‚persistent‘ marks the variable as persistant.
\nThe section „.persist“ let the memory be saved in the persists section.<\/p>\n

Should the section attribute not be enought?<\/strong>No, because its a special marked memory range which only stores persistent variables.
\nNow the map file looks how i want it to be \ud83d\ude42
\n<\/code><\/p>\n

.persist        0xa0000000        0x4\n0xa0000000                _persist_begin = .\n*(.persist .persist.*)\n.persist.my_pers_var\n0xa0000000        0x4 build\/XC32_PIC32MX460F512L\/production\/_ext\/906281160\/main.o\n0xa0000000                my_pers_var\n*(.pbss .pbss.*)\n0xa0000004                . = ALIGN (0x4)\n0xa0000004                _persist_end = .<\/pre>\n

I’am using
\nXC32 v1.31<\/i>
\nPIC32MX450F256L<\/i>
\nMPLAB X IDE v2.10<\/i><\/p>\n

I hope i could help someone with this \ud83d\ude42<\/p>\n

<\/div>