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.

C2000WARE: TMS320F280023 : I want to make a global variable assigned to flash a persistent variable

Part Number: C2000WARE
Other Parts Discussed in Thread: TMS320F280023,

Hi everyone,

I am developing software using the TMS320F280023.
We would like to use variables stored in flash as persistent variables.

I have researched and found that I can declare a persistent variable in FRAM with the following program. Is there any way to create a persistent variable in flash as well?

"#pragma PERSISTENT(x)"

Best regards.

  • Hello,

    Our compiler expert is currently away and will return early next week. Please wait for a response until then.

    Thank you for your patience

    ki

  • Hi Ki
    Thanks for replying.

    Best regards.

  • Is there any way to create a persistent variable in flash as well?

    The ti-cgt-c2000_21.6.0.LTS compiler does allow the PERSISTENT pragma to be used, which causes the data variable to be placed in a ".TI.persistent" section.

    However, the assembler generated by the compiler to modify persistent variables just assumes the variable is in writable memory. E.g. the following test created for a TMS320F280023:

    #pragma PERSISTENT (num_boots)
    int num_boots = 0;
    
    int main(void)
    {
        num_boots++;
    
    	return num_boots;
    }
    

    Resulted in the assembler:

    ||main||:
    	.dwcfi	cfa_offset, -2
    	.dwcfi	save_reg_to_mem, 26, 0
    	.dwpsn	file "../main.c",line 13,column 5,is_stmt,isa 0
            MOVW      DP,#||num_boots||     ; [CPU_ARAU] 
            INC       @||num_boots||        ; [CPU_ALU] |13| 
    	.dwpsn	file "../main.c",line 15,column 2,is_stmt,isa 0
            MOV       AL,@||num_boots||     ; [CPU_ALU] |15| 
    	.dwpsn	file "../main.c",line 16,column 1,is_stmt,isa 0
    $C$DW$3	.dwtag  DW_TAG_TI_branch
    	.dwattr $C$DW$3, DW_AT_low_pc(0x00)
    	.dwattr $C$DW$3, DW_AT_TI_return
    
            LRETR     ; [CPU_ALU] 
            ; return occurs ; [] 
    

    Since flash in C2000 devices needs erase and programming operations, i.e. isn't byte writable like MSP430 FRAM devices, then a variable marked as persistent in flash won't be able to be modified by a running program.

    Also, searching the template linker .cmd files in a CCS 11.1 installation only finds a ".TI.persistent" section in the linker command files for MSP430 FRAM based devices.

    I.e. can't see any C2000 devices which support FRAM, so not sure why the ti-cgt-c2000_21.6.0.LTS compiler allows the PERSISTENT pragma.

  • Hi Chester,

    Thanks for replying.

    Is there any way to create a persistent variable on a c2000 devices?

  • PS

    I am a beginner in embedded development, so my posts may not make sense. Sorry.

    After much research, I found out that there is a limit to the number of writes in FlASH.

    So, I found a document that says that the following is a common way to use FLASH if you want to keep the value even after power off/reset.
    (1) Save the value stored in FLASH to a RAM variable at startup
    (2) Periodically write the value of the RAM variable to FLASH

    Is it possible to do these kinds of processes in ccs?
    If so, it would be very helpful if you could provide a sample of the processing along with it.

    Thank you in advance.

  • Manabe,

    As Chester mentions the C2000 only has Flash as a non-volatile memory, which can only be dynamically changed from a "1"(erased) to a "0"(programmed) at the bit level.  If the same flash word is desired to use to store a dynamic variable you would need to run the erase Flash API call, which erases an entire sector of flash.

    Best,

    Matthew

  • Hi Manabe,

    Yes, you can use the method that you mentioned - Copy from flash at startup and program to flash as needed.

    You can program those values in to flash using the flash API at runtime as needed.  Please take a look at this C2000Ware example for flash API usage:  C2000Ware_x_xx_xx_xx\driverlib\f28002x\examples\flash\flashapi_ex1_programming.c.

    Thanks and regards,
    Vamsi

  • Hi Manabe,

    Hope you reviewed the example.  I am closing this post.  Please open a new post if you have further questions and our team will route you to the appropriate expert.

    Please note: I am out of office up to May 17th and may not be able to reply until then.

    Thanks and regards,

    Vamsi