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.

Initializing flash segment from CCS compiler/linker ?

Other Parts Discussed in Thread: MSP430G2553, ENERGIA

I have figured out how to use flash memory to persist values in the MCU, like to survive across a power failure. So that is cool.

One last thing is how does one get the CCS C++ compiler/linker to initialize a flash segment? Does anyone have a technique for initializing a segment?

For example, I am mapping the persistent values into SEGMENT_C. The C++ compiler/linker does not, at least as mine is setup, initialize the flash segment. It always has the same values from the last time the program wrote values in there, even when the program is rebuilt and reloaded into the MCU.

I have been experimenting with #pragma location= and #pragma LOCATION(x,address) in an attempt to initialize a static variable into SEGMENT_C. But the C++ compiler is saying those are unknown pragmas.

Does anyone know the technique to get the CCS C++ compiler/linker to initialize a flash memory segment like SEGMENT_C to something like all 0x00 or all 0xFF?

Thank you,

  • Hi Robert,

    I would like to help with your question, but I need a few clarifications to make sure that we are on the same page about what you are trying to do and the best solution. 
    1. Can you provide some information about which specific MSP430 device you are using, and also information on what method specifically you have used so far to implement storing data in flash that you want to keep through power loss? (Code snippets might help, or show us an example if you modified your linker file, etc)
    2. Are you writing to the flash in-application, but are asking about how to have it already initialized to a particular value when you first load the program?
    3. Are you wanting to simply store an array of constants in flash at device first programming, or are these values that you will update at some point in your application in the field?

    Regards,
    Katie

  • This is with CCS 6.1.3.xxxx with MSP430G2553.

    The program is able to read from and write to flash successfully. It stores various values in the flash that it needs when/if the system reboots from a power interruption.

    At first I defined the flash storage like this

    static const unsigned char flashData[2*SEGMNT_SIZE]

    and reference it with the SEGPTR(flashData) macro. My program lays a struct over the space to give it a clearer definition, but that’s incidental to this topic.

    The CSS compiler/linker will initialize that space to all 0x00 when it flashes the program into the MCU. So it always starts clean on a new program load.

    The allocation of 2*SEGMENT_SIZE is more flash space than is needed, but it is the minimum that can be allocated using that technique. So I decided to use one of the available, predefined flash segments, SEGMENT_C (which is smaller and also not used to store program instructions). That frees up valuable space needed by the program.

    The challenge is that the CSS compiler/linker does not automatically initialize contents of SEGMENT_C whenever it flashes the program into the MCU. SEGMENT_C is left to whatever might have been written in there from any earlier program that wrote into SEGMENT_C. I would like to find a way to get the contents of the predefined SEGMET_C initialize by the CSS compiler/linker to all 0x00 or 0xFF when a new program is flashed into the MCU.

    Is it possible to get the CSS compiler/linker to initialize the contents of SEGMENT_C?

    Thank you,
  • Hi Robert,

    Thanks for the detailed explanation - it really helped me to understand what is going on. I can think of a few ways to get the behavior that you are wanting here (INFO C memory segment to be set 0xFF on a program load).

    Option 1:

    In CCS, go to Project > Properties > Debug. Select MSP430 Properties, then scroll down to Erase Options and select Erase main and Information Memory (it defaults to just erase main memory only). That will tell CCS that you want to erase the Information segments B/C/D when you do a program load (Note: Do not select Erase main, information, and protected information memory because that will erase INFO A where all of your calibration data for the ADC etc is stored).

    Option 2:

    Instead of changing the CCS project settings, you could try setting a FILL value in the linker cmd file for your project (basically making a customized version of the linker file. The difference in this method is that you could have the segment initialized to something besides 0xFF at program load if you wanted for some reason. In Project Explorer, find lnk_msp430g2553.cmd and open it. Then under "MEMORY" where it says

        INFOC                   : origin = 0x1040, length = 0x0040

    Change it to add the fill option:

        INFOC                   : origin = 0x1040, length = 0x0040, fill = 0xFFFF

    This will fill the segment with 0xFFFF on a load. You could alternately use a different value like 0, or 0xABCD, or whatever you'd like.

    Regards,

    Katie

  • Hi Katie,

    Option 2 seems like exactly what is needed here. Looking at the CSS project I cannot locate any files in the project ending with .cmd. There is a .map file which mentions infoc. But it is not in the same format shown in your reply.

    The project's properties shows the linker command file field as blank.

    This is a CSS project created from Project->New Energia Sketch. Apparently that does not create a .cmd file for the project like when creating a regular CCS project.

    Can you help me locate/create the project’s .cmd file referred to in your suggestion?

     

    Thank you,

  • Hi Robert,

    I didn't realize you were using Energia - sorry for the confusion. The linker cmd file and method I referred to is if you use TI's C/C++ compiler. But Energia uses the GNU GCC compiler which uses a different kind of linker file, and so is going to have different commands/features. I'm not as familiar with these so I'm not sure if there's a similar command to the "fill" one that I mentioned. But Option 1 should work even with Energia.

    In GCC complier, the linker file is ending in .ld. In project properties, if you select msp430g2553.ld under Linker Command File option, you can see it appear in your project. However, I'm not sure if there is an option similar to the fill option for the TI compiler. You may need to check in the (DO NOT USE) TI C/C++ Compiler - Forum where they may have more info about GCC. However, as I mentioned Option 1 should still work for Energia.

    Regards,
    Katie

  • Hi Katie,

    Option 1 is working nicely "Erase main and information memory." It is erases to 0xFF rather than 0x00, which is fine. Thank you for the guidance. It really helped !!!

    Robert

  • Great! I'm so glad that I could help.

**Attention** This is a public forum