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.

Local variables into FRAM

Other Parts Discussed in Thread: MSP430FR5969

Since the MSP430FR5969 has only 2kB of RAM, it'd be nice to be able to push buffers into FRAM instead. Now I can do this easily enough by making them globals, just stick them to the .TI.persistent data group with a pragma. However you cannot do that with static local variables.

Is there any reasonable way around this limitation? I know you could theoretically stick them to a defined memory location but that seems unnecessarily convoluted as you should then limit (somehow..) the memory area that the linker is using and assing part of the FRAM manually. 

There's the fram write function in the driverlibrary but it does not actually do malloc-like allocation i.e. you have to section "private" memory by yourself. 

I can just keep on using static globals although many programmers start to hyperventilate even on global structs.. And I can easily see potential for conflict in my code, better to give those buffers per-function names. 

  • I created the following example program for a MSP430FR5969 with two variables each of which are the size of the RAM:

    #include <msp430.h> 
    
    static char global_large_array[2048] = {1};
    
    /*
     * main.c
     */
    int main(void) {
        static char local_large_array[2048] = {2};
        WDTCTL = WDTPW | WDTHOLD;	// Stop watchdog timer
    	
    	return global_large_array[0] + local_large_array[0];
    }

    In the linker command file I added the following to the SECTIONS to cause the TI v16.9.0.LTS linker to place the two named variables into FRAM:

        FRAM_VARIABLES
        {
            *(*:global_large_array)
            *(*:local_large_array*)
        } > FRAM

    The use of wildcards on the object filename and section names means in the linker command file you don't have to specify the object filename or section prefix. Function local statics such as local_large_array have a suffix added by the compiler in the form $<number>. Defining a wildcard suffix on the local_large_array, i.e. local_large_array* avoids the need for the linker command file to change if the compiler changes the numeric suffix part of the symbol.

  • A variation to consider ...

    FRAM_VARIABLES
    {
       filename.obj(.data)
    } > FRAM

    This tells the linker to create an output section named FRAM_VARIABLES.  It has one input section, which is the .data section from filename.obj.  This output section is placed in the FRAM memory range.

    This method does not require naming any of the variables.  But it does require naming the file which contains them.  Use the method that is easier for you.

    Thanks and regards,

    -George

  • Thanks, that's very helpful! Perhaps SLAA628 should be amended?