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.

MSP430FR5992: write to flash or fram or any non volatile memory

Part Number: MSP430FR5992


Good morning / afternoon, 

I have a few variables that needs to stay in memory even after a reset. So I though of flash or Fram. 

I'm having a lot of trouble using flash or fram. 

I found this : https://e2e.ti.com/support/microcontrollers/msp-low-power-microcontrollers-group/msp430/f/msp-low-power-microcontroller-forum/720929/ccs-msp430fr2433-how-to-write-to-and-read-from-fram but for whatever reason, the "FRAMWrite()" do not work as SYSCFG0 is undefined, while I did include msp430.h ..

Regarding flash, I have a hard time finding flash register and or how to use them. 

Can someone help me please

Thank you

  • #include <msp430.h>
    
    #define FRAM_INFORMATION_MEMORY_START 0x1800
    #define DFWP                             (0x0002)        /* */
    #define PFWP                             (0x0001)        /* */
    
    #pragma PERSISTENT(Count)
    unsigned char Count = 0;
    
    void Reset_ISR();
    void main (void) {
    
       WDTCTL = WDTPW | WDTHOLD;   // stop watchdog timer
       Reset_ISR();
       // Initialize GPIO
       while( 1 )
       {
           __no_operation();
       }
    }
    
    void Reset_ISR(void) {
        unsigned char *FRAM_write_ptr;
    
        SYSCFG0 = FRWPPW;
        FRAM_write_ptr = (unsigned char *)FRAM_INFORMATION_MEMORY_START;
        *(FRAM_write_ptr+Count) = SYSRSTIV;
        if(Count<200)
    	{
    	   Count++;
    	}
        SYSCFG0 = FRWPPW | DFWP | PFWP;
    }
    

    You can refer to this code.

  • Thank you for your quick reply. 

    I'm still having issue with syscfg0 being undefined while I do include msp430.h . 

    Could you help me find where is this SYSCFG0 declared please ? 

    Thanks

  • This part has no SYSCFG0. Why do you think you need to mess with it? To disable FRAM write protection?

    There is quite a bit of variability in hardware between parts. Some have special FRAM write protection while some like the fr5992 use the Memory Protection Unit. Which has to be enabled to do anything.

  • I though I needed to do that to write in FRAM, but you are right, there is no SYSCFG0

    I'm now trying to follow : https://dev.ti.com/tirex/explore/node?node=AHxspo0JbT95EYoCPigAAw__IOGqZri__LATEST&search=MSP430FR5992

    However, FRAM_write is defined at 0x4000. At this address, I have my application code. 

    A little more information on what I have and what I'm trying to do : 

     - I have a custom bootloader in my application, which will load an application at this location 0x4000. 

     - If there is code at this location, the bootloader will boot to it, if not, it will wait for the code. So far, so good. 

     - In this application, I have 4 variables I need to store in Flash or FRAM (or any non volatile memory, doesn't really matter which one it is) ; Those 4 variables are unsigned char GCR[250], unsigned char alarm[250], unsigned long timer1 and unsigned int time2

    When those 4 variables are set, I need to store them. When the app is loading (after initializing the clock and gpio and all that), I need to recover the previous values of those 4 variables from Flash or FRAM (or whatever). 

    following https://dev.ti.com/tirex/explore/node?node=AHxspo0JbT95EYoCPigAAw__IOGqZri__LATEST&search=MSP430FR5992, FRAM_write is writing at 0x4000 which is not acceptable in my application as my code is there. 

    Question : 

     - How can I write in Flash or FRAM, at a specific location (or at least, not at 0x4000)

     - How can I recover those values at init ? 

    Thank you

  • No special library function is required to write to FRAM.

    With FRAM, just declaring your variables as persistent will place them in FRAM. Initialized (or not) at program load but not at reset.

  • WAIT WHAT ? 

    You, David Schultz, made my day ! 

    THANK YOU ! 

    P.D. : I change the linker to put the data in FRAM out of my code and it actually works ! 

    THANK YOU AGAIN ! 

  • David, thank you for the great help!

**Attention** This is a public forum