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.

CCS/MSP430FR2422: #pragma PERSISTENT Variable is not placed in FRAM

Part Number: MSP430FR2422

Tool/software: Code Composer Studio

In the small program below the variable FramVar is not created in section .TI.persistent but in section .bss See extract from the map file at the bottom. I use CodeComposerStudio  Version: 9.3.0.00012

Any suggestions?

Best regards, Robert



#include <msp430.h> #pragma PERSISTENT (FramVar) unsigned int FramVar; void main(void) { WDTCTL = WDTPW | WDTHOLD; // stop watchdog timer SYSCFG0 = FRWPPW | DFWP; // Set FRAM write enable ++FramVar; SYSCFG0 = FRWPPW | PFWP | DFWP; // Set FRAM write protected (not writable) while(1) {} }


Extract from map-file:

SECTION ALLOCATION MAP

 output                                  attributes/
section   page    origin      length       input sections
--------  ----  ----------  ----------   ----------------
.TI.persistent
*          0    0000e300    00000000     UNINITIALIZED

.cinit     0    0000e300    00000012     
                  0000e300    00000006     (.cinit..bss.load) [load image, compression = zero_init]
                  0000e306    00000004     (__TI_handler_table)
                  0000e30a    00000008     (__TI_cinit_table)

.pinit     0    0000e312    00000000     UNINITIALIZED

.binit     0    0000e312    00000000     

.init_array
*          0    0000e312    00000000     UNINITIALIZED

.mspabi.exidx
*          0    0000e312    00000000     UNINITIALIZED

.mspabi.extab
*          0    0000e312    00000000     UNINITIALIZED

.const     0    0000e312    00000000     UNINITIALIZED

.text      0    0000e312    000000ce     
                  0000e312    0000006a     rts430x_lc_sd_eabi.lib : autoinit.c.obj (.text:__TI_auto_init_nobinit_nopinit_hold_wdt:__TI_auto_init_nobinit_nopinit_hold_wdt)
                  0000e37c    0000003e                            : copy_zero_init.c.obj (.text:decompress:ZI:__TI_zero_init_nomemset:__TI_zero_init_nomemset)
                  0000e3ba    0000001a     main.obj (.text:main)
                  0000e3d4    00000006     rts430x_lc_sd_eabi.lib : exit.c.obj (.text:abort)
                  0000e3da    00000004                            : pre_init.c.obj (.text:_system_pre_init)
                  0000e3de    00000002                            : startup.c.obj (.text:_system_post_cinit)

.text:_isr
*          0    0000e3e0    00000024     
                  0000e3e0    0000001c     rts430x_lc_sd_eabi.lib : boot.c.obj (.text:_isr:_c_int00_noargs)
                  0000e3fc    00000008                            : isr_trap.asm.obj (.text:_isr:__TI_ISR_TRAP)

.bss       0    00002000    00000002     UNINITIALIZED
                  00002000    00000002     (.common:FramVar)

.stack     0    00002760    000000a0     UNINITIALIZED
                  00002760    00000002     rts430x_lc_sd_eabi.lib : boot.c.obj (.stack)
                  00002762    0000009e     --HOLE--

  • When I build the code I get a diagnostic similar to  ...

    "main.c", line 2 (col. 14): warning: variable "FramVar" was declared persistent and should be explicitly initialized

    If I change the definition of FramVar to ...

    #pragma PERSISTENT (FramVar)
    unsigned int FramVar = 0;

    ... then no diagnostic is seen.  And the variable FramVar is allocated to the section .TI.persistent.

    Thanks and regards,

    -George

  • George,
    thanks for your answer!


    But doesn't that mean that the variable is initialized with 0 at every program start and thus is no longer persistent?

    Best regards,

    Robert

  • This quote is from the MSP430 compiler manual ...

    By default, noinit or persistent variables are placed in sections named .TI.noinit and .TI.persistent, respectively. The location of these sections is controlled by the linker command file. Typically .TI.persistent sections are placed in FRAM for devices that support FRAM and .TI.noinit sections are placed in RAM.

    If you use a linker command file supplied by TI, then the section .TI.persistent is allocated to FRAM.  It is programmed into memory just like other initialized sections like .text, which contains the program instructions.

    Thanks and regards,

    -George

  • The variable defined as persistent should keep its content even in case of power failure and continue with this content at the next poweron. In my opinion, this can only be achieved if the variable
    (a) is placed in the FRAM; and
    (b) is not initialised.

    Best regards
    Robert

  • Even though the #pragma PERSISTENT variable is initialized in the C source, this is still the case at runtime ...

    Robert Lang1 said:
    The variable defined as persistent should keep its content even in case of power failure and continue with this content at the next poweron.

    Thanks and regards,

    -George

  • Ok,
    I received my hardware and tried it out. It works as recommended by you. Thanks again for your help.

    Best regards,

    Robert