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.

MSP430FR5994: Issues with #pragma NOINIT #pragma PERSISTENT FRAM

Part Number: MSP430FR5994

Tool/software:

#pragma NOINIT(damping)
unsigned char damping;

#pragma PERSISTENT(factor)
float factor=1;

Any change to damping does not survive a power off cycle looking at the lnk_msp430fr5994.cmd file it is set to RAM so moving this to the read write section with the persistent which also does not work I cannot change either variable.

These are always 255 or the initialised value. Unless stored in RAM as per the original .cmd file.

GROUP(READ_WRITE_MEMORY)
{

.TI.persistent : {} /* For #pragma persistent */
.TI.noinit : {} /* For #pragma noinit */
.cio : {} /* C I/O Buffer */
.sysmem : {} /* Dynamic memory allocation area */
} PALIGN(0x0400), RUN_START(fram_rw_start)

GROUP(IPENCAPSULATED_MEMORY)
{


I have tried disabling the memory protection unit MPU and tried putting above into FRAM2

But cannot change the values once initialised.

I am probably missing something very obvious but have tried everything I can think of.

any help most gratefully received

  • In "Project->Properties->Debug->MSP430 Flash Settings->Erase Options", make sure the option "Erase and download necessary segments only" is checked.

  • I have tried that but its not that. Once the .cmd file is changed so the variables are in fram I can not change the values in my program even if disabling the MPU the variables are at address 4000 and 4004 must be something else

  • 0x1E15 is in RAM, and 0x7B7A is not as close to 0x4000 as I would expect, so I think something else is going on.

    My test case:

    1) I started with this code:

    #include <msp430.h> 
    
    #pragma NOINIT(damping)
    unsigned char damping;
    
    #pragma PERSISTENT(factor)
    float factor=1;
    /**
     * main.c
     */
    int main(void)
    {
    	WDTCTL = WDTPW | WDTHOLD;	// stop watchdog timer
    	PM5CTL0 &= ~LOCKLPM5;       // Avoid warning
    	++damping;
    	++factor;
    	while (1) {LPM0;}
    	/*NOTREACHED*/
    	return 0;
    }
    

    2) I made the .cmd change you mentioned:

            GROUP(READ_WRITE_MEMORY)
            {
    
                .TI.persistent : {}              /* For #pragma persistent            */
                .TI.noinit  : {} /*> RAM */      /* For #pragma noinit                */
                .cio           : {}              /* C I/O Buffer                      */
                .sysmem        : {}              /* Dynamic memory allocation area    */
            } PALIGN(0x0400), RUN_START(fram_rw_start)
    

    3) I changed the Erase Options as above

    4) I didn't do anything with the MPU (I let the compiler/linker figure it out)

    I went through a few combinations of restart and re-download, and saw what I expected -- factor was re-initialized on each download, but retained its (incremented) value over a restart, and damping started out at some random value and kept incrementing (both cases).

    I'm not sure what we're doing differently.

  • thanks address were from an earlier test they are 4000 and 4004, ok so must be something else in my code or a setting stopping it?

  • One possibility that comes to mind (not that *I* have ever done this) is that, after a series of experiments, there's some forgotten leftover setting that's getting in your way.

    If feasible you might consider (a) creating a new project and copying your code into it and/or (b) following my test case above (it took me about 20 minutes) to see if you get the expected results.

**Attention** This is a public forum