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/MSP430FR2422: Checksum of program code

Part Number: MSP430FR2422


Tool/software: Code Composer Studio

Hi,

My customer plans to implement a checksum function to alert bit error of program code.
Does CCS has such function to write the checksum data to data area of FRAM?
Best Regards, Taki

  • Hi Isao,

    Let me make sure I understand what customer wants to do.

    They want CCS to calculate checksum during code build and store it somewhere is FRAM?

    I'm not sure.  Let me check on that.

    Attached is some information and example code that might be useful though.

    0435.Write to FRAM example.pdf

    #include <msp430.h> 
    #include <stdint.h>
    
    /*
     * Notes: By default both data and program FRAM memory is enabled and must be
     * disabled in order to write to these sections.
     * For more information on this topic see section 5.12.22
     * https://www.ti.com/lit/ug/slau132v/slau132v.pdf
     *
     * Noinit and persistent variables behave identically with the exception of
     * whether or not they are initialized at load time.
     * The NOINIT pragma may be used only with uninitialized variables. It
     * prevents such variables from being set to 0 during a reset.
     * It may be used in conjunction with the LOCATION pragma to map variables
     * to special memory locations, like memory-mapped registers, without
     * generating unwanted writes.
     * The PERSISTENT pragma may be used only with statically-initialized variables.
     * It prevents such variables from being initialized during a reset.
     * Persistent variables disable startup initialization; they are given an
     * initial value when the code is loaded, but are never again initialized.
     * By default, noinit or persistent variables are placed in sections
     * named .TI.noinit and .TI.persistent, respectively. The location of these
     * sections is controlled by the linker command file. Typically .TI.persistent
     * sections are placed in FRAM for devices that support FRAM and .TI.noinit sections
     * are placed in RAM.
     */
    /*
     * Some easy to use #defines
     */
    #define DISABLE_PF_WRITE_PROTECT        SYSCFG0 = FRWPPW | DFWP
    #define DISABLE_DF_WRITE_PROTECT        SYSCFG0 = FRWPPW | PFWP
    #define DISABLE_PF_DF_WRITE_PROTECT     SYSCFG0 = FRWPPW
    #define DISABLE_ALL_WRITE_PROTECT       SYSCFG0 = FRWPPW
    
    #define ENABLE_PF_WRITE_PROTECT         SYSCFG0 = FRWPPW | PFWP
    #define ENABLE_DF_WRITE_PROTECT         SYSCFG0 = FRWPPW | DFWP
    #define ENABLE_PF_DF_WRITE_PROTECT      SYSCFG0 = FRWPPW | PFWP | DFWP
    #define ENABLE_ALL_WRITE_PROTECT        SYSCFG0 = FRWPPW | PFWP | DFWP
    
    /*
     * Example
     * Declare variable 'peanut' persistent in Info memory at location 0x1800.
     * (initialize only once at load time = 0)
     *
     */
    #pragma PERSISTENT(peanut)
    #pragma LOCATION(peanut, 0x1800)
    uint16_t peanut = 0;
    
    /*
     * Example
     * Declare variable 'peach' persistent in Program memory at location 0xE000.
     * (initialize only once at load time = 0x1234)
     *
     */
    #pragma PERSISTENT(peach)
    #pragma LOCATION(peach, 0xE002)
    uint16_t peach = 0x1234;
    
    
    /*
     * Example
     * Declare variable 'apple, compiler will place automatically
     * (initialize only once at load time = 0x55AA)
     */
    #pragma PERSISTENT(apple)
    uint16_t apple = 0x55AA;
    
    /*
     * Example
     * Declare variable 'walnut' noinit in Info memory at location 0x1802.
     * (is not initialized at reset)
     *
     */
    #pragma NOINIT(walnut)
    #pragma LOCATION(walnut, 0x1802)
    uint16_t walnut;
    
    uint16_t SYSCFG0_copy;
    
    int main(void)
    {
    	WDTCTL = WDTPW | WDTHOLD;	// stop watchdog timer
    
    	SYSCFG0_copy = SYSCFG0 & (PFWP | DFWP);     // let's first confirm FRAM protection is on by default
    
    	peanut = 1;                                 // won't work because DFWP is enabled by default
    
    	DISABLE_DF_WRITE_PROTECT;
    
    	peanut = 1;                                 // this time it worked
    
    	walnut = 2;                                 // verify we can change walnut
    
    	apple = 0x55AA;                             // won't work because PFWP is enabled by default
    
    	DISABLE_PF_WRITE_PROTECT;
    
    	apple = 0xAA55;                            // this time it worked
    	
    	peach = 0;                                 // verify we can change peach
    
    	DISABLE_ALL_WRITE_PROTECT;                 // Don't forget to protect when done.
    
    	while(1);
    
    }
    

  • Hi Isao,

    See section 8.9 in  SLAU131.

**Attention** This is a public forum