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.

CCS/MSP430FR5739: How to have bytes in .data remain available after unplug

Part Number: MSP430FR5739

Tool/software: Code Composer Studio

Hi there,

I am working in assembly on the MSP430FR5739 experimenter board and having issues using .data. I would like to save some bytes in a table. I have found that I can program the MSP and data in the table can be read even after a reset, but not after I unplug the board. My impression was that data included in the .data section would be loaded from ROM into RAM. Does that only happen when the device is being programmed? How do I ensure that the .data section is available even after a board unplug?

Minimal viable code for this below. In this code, I use a byte to set the LEDS 1-4 on. This works fine using the debugger and after a reset, but does not work if I unplug the board and plug it back in.

Thanks!

; MSP430 Assembler Code Template for use with TI Code Composer Studio
;-------------------------------------------------------------------------------
.cdecls C,LIST,"msp430.h" ; Include device header file

;-------------------------------------------------------------------------------
.def RESET ; Export program entry-point to
; make it known to linker.
;-------------------------------------------------------------------------------
.text ; Assemble into program memory.
.retain ; Override ELF conditional linking
; and retain current section.
.retainrefs ; And retain any sections that have
; references to current section.
;-------------------------------------------------------------------------------
RESET mov.w #__STACK_END,SP ; Initialize stackpointer
StopWDT mov.w #WDTPW|WDTHOLD,&WDTCTL ; Stop watchdog timer
;-------------------------------------------------------------------------------
; Main loop here
;-------------------------------------------------------------------------------

mov.b #0Fh,&PJDIR ; set LED1-LED4 to output
mov #label,R4
mov.b @R4,&PJOUT
jmp $

.data
label .byte 0Fh,02h

;-------------------------------------------------------------------------------
; Stack Pointer definition
;-------------------------------------------------------------------------------
.global __STACK_END
.sect .stack
;-------------------------------------------------------------------------------
; Interrupt Vectors
;-------------------------------------------------------------------------------
.sect ".reset" ; MSP430 RESET Vector
.short RESET

  • Hi Margaret,

    Looking at the .cmd file for the FR5739 shows that the .data section is stored directly in the device RAM when the program is loaded onto the MCU which explains why the data disappears after the device is unplugged.

        .data       : {} > RAM                /* Global & static vars              */

    If you would like the data to persist after device power down, you may want to store and load the data from FRAM instead by storing it at a set FRAM address.

    An example of writing to FRAM in assembly for the FR5739 can be found here.

    Regards,

    Ryan

  • Gotcha, as I suspected. Thank you Ryan!

  • Ryan,

    After trying this, I have been successful at writing to the FRAM. However, I am having two issues:

    The first one is that the FRAM is cleared when I enter the debugger. I would like to be able to flash data into the FRAM and then load a separate program that then uses data from the FRAM. I found that I could work around this by changing the debug settings for my project to only do a differential download.

    However, the second issue is that even if i can get the FRAM to persist through a debug session, I can't get it to persist through an unplug. Is there something else I'm missing here?

    Thanks!
  • Hi Margaret,

    After looking deeper into how to create persistent data in assembly, your best bet seems to be to update the .cmd file to directly load whatever data you want into the program image. This can be somewhat complicated but is outlined in the MSP430 Assembly Language Tools User's Guide.

    However, there is a much simpler way to do it in C. You can declare the data as persistent to keep it around after power down, and the compiler will automatically correctly allocate memory for it. An example of this is shown in the FRAM write example here. It should look something like this:

    #if defined(__TI_COMPILER_VERSION__)
    #pragma PERSISTENT(Data)
    unsigned int Data = {0x1234};
    #elif defined(__IAR_SYSTEMS_ICC__)
    __persistent unsigned int Data = {0x1234};
    #elif defined(__GNUC__)
    unsigned int __attribute__((persistent)) Data = {0x1234};
    #else
    #error Compiler not supported!
    #endif

    The value in the curly braces will be loaded into the variable every time the program is loaded onto the MCU.

    Regards,

    Ryan