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.

MSP430FR2355: Energia + CCS - Unable to get .noinit variables to be stored in FRAM instead of RAM

Part Number: MSP430FR2355
Other Parts Discussed in Thread: ENERGIA

I have been trying for the life of me to properly set up variables in FRAM that persist between power cycles AND flash uploads.

The problem, from what I can tell, is that .noinit in energia is in RAM, not FRAM.

After trying many different combinations, I can get the variables to persist between power cycles if I put them in .text. For example:  unsigned long __attribute__((section(".text"))) persist;

I have tried nearly all combinations I can find online of settings to try and get .noinit to work.

Here are a few, all in one sketch:

#include <Energia.h>
#include <Arduino.h>
#include <msp430.h>

// most launchpads have a red LED
#define LED RED_LED


//https://e2e.ti.com/support/microcontrollers/msp-low-power-microcontrollers-group/msp430/f/msp-low-power-microcontroller-forum/769095/msp430fr6989-need-read-and-write-example-code-for-fram-on-the-msp-device-for-energia?tisearch=e2e-sitesearch&keymatch=MSP-FRAM-UTILITIES
//https://github.com/energia/msp430-lg-core/issues/70
int i PLACE_IN_FRAM;

//https://forum.43oh.com/topic/6230-saving-variable-value-in-fram-msp430fr5969/
//https://forum.43oh.com/topic/10186-how-to-save-variables-in-fram-msp430fr4133/
uint8_t lo __attribute__((section(".infomem")));

//https://www.element14.com/community/people/baldengineer/blog/2018/07/10/msp430fr2633-fram

//#pragma PERSISTENT(var)  
#pragma NOINIT(var)  
unsigned long var=0;  

//https://forum.43oh.com/topic/40515-persistent-variables-on-msp430fr5994/
//stealing the noinit from https://www.element14.com/community/people/baldengineer/blog/2018/07/10/msp430fr2633-fram
unsigned long __attribute__((section(".noinit"))) persist;


#pragma NOINIT(thingsToStore)
#pragma DATA_SECTION(thingsToStore, ".text")

uint16_t __attribute__((section(".text"))) thingsToStore[10] ;





// the setup routine runs once when you press reset:
void setup()
{
  
  //this breaks the code
  //WDTCTL = WDTPW | WDTHOLD; // Stop WDT
  
  // initialize the digital pin as an output.
  Serial1.begin(9600);
  pinMode(LED, OUTPUT);
  delay(100);
  Serial1.println("hello world!");

    
  disableWatchDog();
    i = 0;
    enableWatchDog();
  //i = 0;
}

// the loop routine runs over and over again forever:
void loop()
{
  disableWatchDog();
  //https://github.com/energia/msp430-lg-core/issues/70
  Serial1.print("hello world! ");
  Serial1.println(i++);
  enableWatchDog();


disableWatchDog();
//https://forum.43oh.com/topic/10186-how-to-save-variables-in-fram-msp430fr4133/
 SYSCFG0 &= ~PFWP;                   // Program FRAM write enable
        lo = lo + 1;                       // Record in FRAM
        SYSCFG0 |= PFWP;                    // Program FRAM write protected (not writable)

  Serial1.print("lo and behold: ");
  Serial1.println(lo);
enableWatchDog();

//https://www.element14.com/community/people/baldengineer/blog/2018/07/10/msp430fr2633-fram
//this at least increments, but gets erased on startup
SYSCFG0 = FRWPPW | DFWP;            // Program FRAM write enable  
var++;                             // Increment the variable (aka, treat it like any other variable)  
SYSCFG0 = FRWPPW | PFWP | DFWP;     // Program FRAM write protected (not writable)  


  Serial1.print("no show: ");
  Serial1.println(var);

//https://forum.43oh.com/topic/40515-persistent-variables-on-msp430fr5994/

//it seems that messing with the wdt isn't needed :)
//disableWatchDog();
SYSCFG0 = FRWPPW | DFWP;   
 persist++;
    Serial1.print("does percistance pay: ");
  Serial1.println(persist);
 //enableWatchDog();

  thingsToStore[0]++;
  Serial1.print("in the first box: ");
  Serial1.println(thingsToStore[0]);
  Serial1.print("and in the second... ");
  Serial1.println(thingsToStore[5],HEX);
SYSCFG0 = FRWPPW | PFWP | DFWP;  
  //this is no logic to what the initial values are if they weren't stored correctly


  digitalWrite(LED, HIGH); // turn the LED on (HIGH is the voltage level)
  delay(1000);             // wait for a second
  digitalWrite(LED, LOW);  // turn the LED off by making the voltage LOW
  delay(1000);             // wait for a second

  
}

In the application note about storing variables in FRAM they discuss needing to modify the linker file to move .init into FRAM.

This seems straightforward enough for regular CCS projects where the .cmd file matches the one in the example.

But I have no clue how to modify the msp430.x/memory.x files that seem to be the memory maps for Energia.

TL:DR: If I need to modify the linker to get noinit to work correctly, then how do I do it (for Energia)? If not, What is the best way?

Thanks,

Matt

**Attention** This is a public forum