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/MSP430F123: Initializing data in the data section during programing the part

Part Number: MSP430F123
Other Parts Discussed in Thread: MSP430FR2422

Tool/software: Code Composer Studio

I am using CCS  Version: 8.0.0.00016. In my code I have:

#pragma DATA_SECTION( EngSet, ".infoB" )
int    EngSet = 250;               // engine temperature set point

This places the variable in FLASH in the infoB section as can be seen in the Code.map file:

00001000  EngSet                        

The Code.txt file starts at @e000 and does not have any data located at @1000. I would like to have the EngSet variable initialized to 250 when I program the part. I will be changing the value of EngSet in the program (can't be declared const) but I need it initialized. I have tried several modification to lnk_msp430f123.cmd but they have not worked.

  • maybe something like...   

    linker .cmd :

    MEMORY

    {

    # hello Geoffrey, Not sure if you want 0x1000 or 0xe000 as the origin for this tiny data section, please consider/adjust as you see fit 

    ENGINESETPOINT (RWX) : org = 0x1000, len = 0x2 

    }

    SECTIONS

    {

    .enginesetpoint: load > ENGINESETPOINT, fill = 0xFA ; 

    }

    C code:

    int EngSet;   /* EngSet is initialized to 254 via the linker  .cmd file.   This may be a bit obfuscated but ought to work.  */ 

  • Hi Steve,

    I was looking at processors.wiki.ti.com/.../Placing_Variables_in_Specific_Memory_Location_-_MSP430 and it states:

    "Modifying The Linker Configuration File
    As shown above, the defined memory segments of IAR's linker configuration file and memory section of CCS's linker command file can be used with constseg pragma and DATA_SECTION pragma respectively to put a variable inside a specific memory location. Therefore it is possible to modify the linker configuration/command file to define a new memory segment/section and put the necessary variable inside the defined memory segment/location.
    For more information regarding modifying the linker configuration/command file, please refer to the CCS and IAR documentation."

    I have several variables and I wish to place them in the infoB section @ 0x1000 with their values specified in the C source code. Their example shows this being done but not how to modify the linker configuration file.

    Your help is appreciated.
  • Please understand that I have only a vague understanding the memory available on MSP devices.  My point here could be wrong.

    Geoffrey Probert said:
    I will be changing the value of EngSet in the program (can't be declared const)

    This means EngSet cannot be in non-volatile memory like FLASH.  And infoB is FLASH.  It has to be in volatile memory like RAM.

    Thanks and regards,

    -George

  • infoB is a section of the FLASH that can be written to by a program to change its value. It involves special handling to set it up for erase and writing and I have these working. These values need to persist during a power off and be available the next time the device is powered on. When first programming the device us CCS and the FET, I want the initial values I specify to be written into the infoB section of the memory.

  • Geoffrey Probert said:
    These values need to persist during a power off and be available the next time the device is powered on.

    Use #pragma PERSISTENT for that. Please read about it in the MSP430 compiler manual.  

    I continue to suspect your device does not support this feature.  When #pragma PERSISTENT is used, it creates an entry in the section .TI.persistent.  The linker command file lnk_msp430f123.cmd has no entry for this section.  But there are entries for .TI.persistent in the linker command files for other MSP devices.  Explaining this difference requires expertise on these devices which I lack.  Thus I am turning this thread over to the experts in the MSP device forum.

    Thanks and regards,

    -George

  • All,

    The #pragma PERSISTENT is only used used for FRAM devices. One way to place an initialized variable in INFOB would be to do the following:

    #pragma RETAIN(Var)
    #pragma location = 0x0fde  // replace with location of where you want to store Var
    unsigned int Var = 0xAA55; // Initialize Var
    

    Hope this helps! I haven't tried this with the  F1xx devices, but I have used it for some of our newer devices. 

  • My code using your example is:

    #pragma RETAIN( EngSet )
    #pragma location = 0x1000
    int    EngSet = 250;               // engine temperature set point

    My previous code is:

    #pragma DATA_SECTION( EngSet, ".infoB" )
    int    EngSet = 250;               // engine temperature set point

    Both place the variable EngSet in the FLASH memory in the infoB section but neither generates data in the code.map to initialize the variable during programming. The code.txt file actually shows:

    .TI.bound:EngSet
    *          0    00001000    00000002     UNINITIALIZED
                      00001000    00000002     Eg400.obj (.TI.bound:EngSet)

  • Geoffrey,

    Try the following:

    #pragma RETAIN( EngSet )
    #pragma location = 0x1900
    int    EngSet ;               // engine temperature set point
    
    EngSet = 250;

    I saw this initialize on a part i have on my bench. I see my mistake from earlier is that I usually use it as a const which doesn't help you. I was thinking on how you are using this variable, you'll have to copy it to a temp var in ram, do what operations you want to, then periodically do a Flash write to its InfoB location to update in Flash. 

    If you have the ability to switch devices, I would recommend one of our FRAM devices as this becomes easier to do. You would just have to use the PERSISTANT Pragma mentioned earlier and everything is taken care of for you. this is due tot he ease of writing to FRAM so you can use it like a RAM variable and it will keep updated (aka persist) between power cycles. Basically you can constantly overwrite it as the memory endurance for FRAM is more similar to RAM than Flash in terms of scale. This would help reduce code size as well as you wouldn't have to write a Flash Write routine. The MSP430FR2422 might be a code fit for you as it has similar specs to the MSP430F123 and its 1k unit pricing is about half the cost of the MSP430F123. 

**Attention** This is a public forum