This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
I've defined a persistent variable in my code using the __attribute__((persistent)) directive. In the code I initialize the variable count to zero. It compiles and it's value persists across power loss as I would expect but count's initial value after flashing the device is 0xFF and not zero. It doesn't matter what I set the initial value to in the code it always ends up as 0xFF. I'm using the GCC compiler and MSPFlasher on linux. Any suggestions as to what is causing the initial value to be wrong?
__attribute__ ((persistent)) uint8_t count = 0;
Here is example code which should show you how to use data in FRAM.
#include <msp430.h> #define WRITE_SIZE 128 void FRAMWrite(void); unsigned char count = 0; unsigned long data; #if defined(__TI_COMPILER_VERSION__) #pragma PERSISTENT(FRAM_write) unsigned long FRAM_write[WRITE_SIZE] = {0}; #elif defined(__IAR_SYSTEMS_ICC__) __persistent unsigned long FRAM_write[WRITE_SIZE] = {0}; #elif defined(__GNUC__) unsigned long __attribute__((persistent)) FRAM_write[WRITE_SIZE] = {0}; #else #error Compiler not supported! #endif int main(void) { WDTCTL = WDTPW | WDTHOLD; // Stop WDT // Configure GPIO P1OUT &= ~BIT0; // Clear P1.0 output latch for a defined power-on state P1DIR |= BIT0; // Set P1.0 to output direction // Disable the GPIO power-on default high-impedance mode to activate // previously configured port settings PM5CTL0 &= ~LOCKLPM5; // Initialize dummy data data = 0x00010001; while(1) { data += 0x00010001; FRAMWrite(); count++; if (count > 100) { P1OUT ^= 0x01; // Toggle LED to show 512K bytes count = 0; // ..have been written data = 0x00010001; } } } void FRAMWrite(void) { unsigned int i = 0; for (i = 0; i < WRITE_SIZE; i++) { FRAM_write[i] = data; } }
The ordering of the type and attribute made no difference. I updated the gcc compiler to the latest version and that fixed the issue.
**Attention** This is a public forum