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.

Define PERSISTENT variable not using IAR/CCS

Other Parts Discussed in Thread: MSP430FR5969

Hi,


I'm working with a MSP430FR5969. I want to preserve the values of 2 variables when the MSP430 loses power and restarts. I found out this post: http://processors.wiki.ti.com/index.php/Creating_MSP430_FRAM_Variables_Using_CCS .

However I use neither IAR nor CCS (I compile in Eclipse) and this solution doesn't work for me. Is it possible to define a PERSISTENT variable without these tools ?


Regards,

Clément.

  • Hi,

    The basic premise will be as defined in the article.

    Define a section in the linker file that places the variables in FRAM

    Define the variables so they are placed in this section.

    If you provide details of the compiler and linker you are using you may get more info.

    Regards

    Roy

  • Hi Roy,


    The compiler is gcc, the linker script file is below :

    MEMORY {
      sfr              : ORIGIN = 0x0000, LENGTH = 0x0010 /* END=0x0010, size 16 */
      peripheral_8bit  : ORIGIN = 0x0010, LENGTH = 0x00f0 /* END=0x0100, size 240 */
      peripheral_16bit : ORIGIN = 0x0100, LENGTH = 0x0100 /* END=0x0200, size 256 */
      bsl              : ORIGIN = 0x1000, LENGTH = 0x0800 /* END=0x1800, size 2K as 4 512-byte segments */
      infomem          : ORIGIN = 0x1800, LENGTH = 0x0200 /* END=0x1a00, size 512 as 4 128-byte segments */
      infod            : ORIGIN = 0x1800, LENGTH = 0x0080 /* END=0x1880, size 128 */
      infoc            : ORIGIN = 0x1880, LENGTH = 0x0080 /* END=0x1900, size 128 */
      infob            : ORIGIN = 0x1900, LENGTH = 0x0080 /* END=0x1980, size 128 */
      infoa            : ORIGIN = 0x1980, LENGTH = 0x0080 /* END=0x1a00, size 128 */
      ram (wx)         : ORIGIN = 0x1c00, LENGTH = 0x0800 /* END=0x2400, size 2K */
      rom (rx)         : ORIGIN = 0x4400, LENGTH = 0x9C40 /* END=0xEFE0, size 44000 */
      signature        : ORIGIN = 0xff80, LENGTH = 0x0010 /* END=0xff90, size 16 as 1 16-byte segments */
      vectors          : ORIGIN = 0xff80, LENGTH = 0x0080 /* END=0x10000, size 128 as 64 2-byte segments */
      far_rom          : ORIGIN = 0x00010000, LENGTH = 0x00004000 /* END=0x00014000, size 16K */
      /* Remaining banks are absent */
      ram2 (wx)        : ORIGIN = 0xE040, LENGTH = 0x1B58
      ram_mirror (wx)  : ORIGIN = 0x0000, LENGTH = 0x0000
      usbram (wx)      : ORIGIN = 0x0000, LENGTH = 0x0000
    }
    REGION_ALIAS("REGION_TEXT", rom);
    REGION_ALIAS("REGION_DATA", ram2);
    REGION_ALIAS("REGION_FAR_ROM", far_rom); /* Legacy name, no longer used */
    REGION_ALIAS("REGION_FAR_TEXT", far_rom);
    REGION_ALIAS("REGION_FAR_DATA", ram2);
    PROVIDE (__info_segment_size = 0x80);
    PROVIDE (__infod = 0x1800);
    PROVIDE (__infoc = 0x1880);
    PROVIDE (__infob = 0x1900);
    PROVIDE (__infoa = 0x1980);
    
    
      /*signature        : ORIGIN = 0xff80, LENGTH = 0x0010*/ /* END=0xff90, size 16 as 1 16-byte segments */
      /*vectors          : ORIGIN = 0xff80, LENGTH = 0x0080*/ /* END=0x10000, size 128 as 64 2-byte segments */
    
    

    So I should first add the line FRAM_VARS : ORIGIN = 0x1B58, LENGTH=0x0002 in "MEMORY{...}", then add the part SECTION{ .fram_vars : {} > FRAM_VARS type = PERSISTENT } ?



    Clément.

  • Persistent variables are variables that are excluded by the C startup code (which is compiler dependent). They are (like all variables) normally stored in volatile memory and will lose content on a power cycle. 
    On devices with FRAM, this is different because FRAM can be used as volatile as well as non-volatile memory, so all variables in FRAM will survive a power cycle.
    The thing that makes variable spersistent is that they are just not touched during startup. Neither initialized with a value (so you can't assign them a default value), nor set to 0 (which normally happen to all variables that haven't a default value defined).

    The way to make variables persistent depends on the compiler/linker. So check the GCC compiler documentation.

    Reserving storage space to keep values in non-volatile memory is a different thing and compiler-independent. It requires a store and restore function in your code.

    btw: on CCS in COFF mode, uninitialized variables weren't set to 0 (to save startup time) and therefore were always persistent.

**Attention** This is a public forum