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.

MSP-EXP430FR2355: Regarding FRAM store in MSP430FR2355

Part Number: MSP-EXP430FR2355
Other Parts Discussed in Thread: MSP430FR2355

Hello team,

I want to store a value(type 'uint8_t') permanently in FRAM at address 0x001800 using DFWP or PFWP. I tried by using #pragma persistent()  but it is storing at 0x008000 location also after reset it is becoming 00 at same address. How can i store at particular location for msp430fr2355. below is the code i tried, can anyone help me in this issue.

#pragma PERSISTENT(gu8LogicalId)
volatile uint8_t gu8LogicalId = 0;

void main()

{
        // Add the variable Port_event in FRAM to record the button event
        // Write protection starts from the beginning of Program FRAM + 1024 bytes
        // Code start address + 1024 bytes, Linker command file should be modified
        SYSCFG0 = FRWPPW | FRWPOA0 | DFWP | PFWP; // Configure 1024 bytes for
                                                                                               //FRAM write
        gu8LogicalId = 1;

        SYSCFG0 = FRWPPW | DFWP | PFWP;       // Program FRAM write protected
                                                                              // (not writable)
}

  • Hi vamshi b,

    You need to provide a specific address.

    Example:

    #pragma PERSISTENT(peanut)
    #pragma LOCATION(peanut, 0x1800)
    uint16_t peanut = 0;

    See attached pdf and example code.

    1538.Write to FRAM example.pdf

    6281.main.c
    #include <msp430.h> 
    #include <stdint.h>
    
    /*
     * Notes: By default both data and program FRAM memory is enabled and must be
     * disabled in order to write to these sections.
     * For more information on this topic see section 5.12.22
     * https://www.ti.com/lit/ug/slau132v/slau132v.pdf
     *
     * Noinit and persistent variables behave identically with the exception of
     * whether or not they are initialized at load time.
     * The NOINIT pragma may be used only with uninitialized variables. It
     * prevents such variables from being set to 0 during a reset.
     * It may be used in conjunction with the LOCATION pragma to map variables
     * to special memory locations, like memory-mapped registers, without
     * generating unwanted writes.
     * The PERSISTENT pragma may be used only with statically-initialized variables.
     * It prevents such variables from being initialized during a reset.
     * Persistent variables disable startup initialization; they are given an
     * initial value when the code is loaded, but are never again initialized.
     * 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.
     */
    /*
     * Some easy to use #defines
     */
    #define DISABLE_PF_WRITE_PROTECT        SYSCFG0 = FRWPPW | DFWP
    #define DISABLE_DF_WRITE_PROTECT        SYSCFG0 = FRWPPW | PFWP
    #define DISABLE_PF_DF_WRITE_PROTECT     SYSCFG0 = FRWPPW
    #define DISABLE_ALL_WRITE_PROTECT       SYSCFG0 = FRWPPW
    
    #define ENABLE_PF_WRITE_PROTECT         SYSCFG0 = FRWPPW | PFWP
    #define ENABLE_DF_WRITE_PROTECT         SYSCFG0 = FRWPPW | DFWP
    #define ENABLE_PF_DF_WRITE_PROTECT      SYSCFG0 = FRWPPW | PFWP | DFWP
    #define ENABLE_ALL_WRITE_PROTECT        SYSCFG0 = FRWPPW | PFWP | DFWP
    
    /*
     * Example
     * Declare variable 'peanut' persistent in Info memory at location 0x1800.
     * (initialize only once at load time = 0)
     *
     */
    #pragma PERSISTENT(peanut)
    #pragma LOCATION(peanut, 0x1800)
    uint16_t peanut = 0;
    
    /*
     * Example
     * Declare variable 'peach' persistent in Program memory at location 0xE000.
     * (initialize only once at load time = 0x1234)
     *
     */
    #pragma PERSISTENT(peach)
    #pragma LOCATION(peach, 0xE002)
    uint16_t peach = 0x1234;
    
    
    /*
     * Example
     * Declare variable 'apple, compiler will place automatically
     * (initialize only once at load time = 0x55AA)
     */
    #pragma PERSISTENT(apple)
    uint16_t apple = 0x55AA;
    
    /*
     * Example
     * Declare variable 'walnut' noinit in Info memory at location 0x1802.
     * (is not initialized at reset)
     *
     */
    #pragma NOINIT(walnut)
    #pragma LOCATION(walnut, 0x1802)
    uint16_t walnut;
    
    uint16_t SYSCFG0_copy;
    
    int main(void)
    {
    	WDTCTL = WDTPW | WDTHOLD;	// stop watchdog timer
    
    	SYSCFG0_copy = SYSCFG0 & (PFWP | DFWP);     // let's first confirm FRAM protection is on by default
    
    	peanut = 1;                                 // won't work because DFWP is enabled by default
    
    	DISABLE_DF_WRITE_PROTECT;
    
    	peanut = 1;                                 // this time it worked
    
    	walnut = 2;                                 // verify we can change walnut
    
    	apple = 0x55AA;                             // won't work because PFWP is enabled by default
    
    	DISABLE_PF_WRITE_PROTECT;
    
    	apple = 0xAA55;                            // this time it worked
    	
    	peach = 0;                                 // verify we can change peach
    
    	DISABLE_ALL_WRITE_PROTECT;                 // Don't forget to protect when done.
    
    	while(1);
    
    }
    

  • Thank you for the reply Dennis,

    That resolved my issue with memory location but i want that location not disturbed even by flashing code. Can i secure a location from reprogramming ?

    uint16_t peanut = 0;  this is programming memory to 0 at every new program. can we avoid this?

    I wonder where i can get information regarding #pragma's like #pragma location() ?

  • Hi vamshi,

    What or how are you programming the target?

    Using CCS and MSP-FET430 for example?

  • Thank you Dennis,

    Your example code solved issue of re-initializing memory. Used NOINIT() resolved issue.

    I just want to know more about TI #pragma defines, Please point me to the right direction. 

  • Hi vamshi,

    All the #pragams are described in the MSP430 C/C++ compiler guilde.

  • Thank you Dennis.

**Attention** This is a public forum