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.

How to store an array in FLASH

Other Parts Discussed in Thread: MSP430G2553

Hi, 

I have been programming 8051's for a few years and have just purchased the MSP LaunchPad with a M430G2553 uC and am learning how to program it using CCS.

I have used the segment name "code" to store an array in FLASH in other compilers, e.g.:

code unsigned char testArray[3][8]= {"10 X 6", "6 X 5", "8 X 8"};

I have read that it is different for CCS. I would like the compiler to store the array in the FLASH memory of the M430G2553 . It doesn't matter where the compiler puts it in FLASH - the array is just too big for RAM.

I read that the CCS equivalent of "code" is ".text". I have also read that I need to make changes in the linker command file and use #pragma DATA_SECTION in my code. 

I'm quite lost about what to do. Where can I find the linker command file in the IDE? What changes do I need to make to it, if any? How do I use #pragma DATA_SECTION in my code?

Please help!

Dan 




  • Daniel Milutinovic said:
    Where can I find the linker command file in the IDE?

    When you create a new project in CCS, among the items you enter in the first screen is the name of the device.  Based on that, CCS chooses many project configuration settings for you.  Among them is the linker command file.  Your linker command file will have a name similar to lnk_msp430g2553.cmd.  It will be among the source files in your project.  To understand the contents of that file, see this wiki article.

    Daniel Milutinovic said:
    What changes do I need to make to it, if any? How do I use #pragma DATA_SECTION in my code?

    Please see this wiki article.

    Thanks and regards,

    -George

  • Daniel Milutinovic said:
    It doesn't matter where the compiler puts it in FLASH - the array is just too big for RAM.

    On the assumption that you don't want to change the content of the array at at run time, the simplest approach to make the compiler store the array in flash is to const qualify the array. i.e.:

    const unsigned char testArray[3][8]= {"10 X 6", "6 X 5", "8 X 8"};

  • Thank you George. I see that the first wiki file you referred me to is in the index under the "Compiler Wiki" link under your signature. However I could not find the second wiki article there ("Placing variables in specific memory locations - MSP430"). Can you please tell me where I can find this article, so that I can research there first before posting. Also if there are any other links with info on the MSP430, please let me know.

    I am sorry, but I just can't find a file similar to lnk_msp430g2553.cmd in my project. When I expand the name of my project I see "Binaries", "Includes", "Debug", "targetConfigs", "main.c" and "msp430g2553.Id" but I can't find a file with a .cmd extension in any of these.

    Regards,

    Dan
  • Thank you very much Chester, the "const" qualifier works perfectly! One thing that confuses me is the message in the console window when I hit "Run", then "Debug" to download the code . In my case it says "4158 (code) and 20 (data) bytes written to FLASH/FRAM. Expected RAM usage is 1616 (uninitialized data and stack) bytes." The expected RAM usage is clearly more than the maximum allowed (512 bytes for the M430G2553). How can one determine exactly how large their program is?
  • Daniel Milutinovic said:
    I see that the first wiki file you referred me to is in the index under the "Compiler Wiki" link under your signature. However I could not find the second wiki article there ("Placing variables in specific memory locations - MSP430"). Can you please tell me where I can find this article, so that I can research there first before posting.

    I added that article to the collection of compiler articles at http://processors.wiki.ti.com/index.php?title=Category:Compiler .

    Daniel Milutinovic said:
    Also if there are any other links with info on the MSP430, please let me know.

    The collection of articles on MSP430 is at http://processors.wiki.ti.com/index.php/Category:MSP430 .

    Daniel Milutinovic said:
    I am sorry, but I just can't find a file similar to lnk_msp430g2553.cmd in my project. When I expand the name of my project I see "Binaries", "Includes", "Debug", "targetConfigs", "main.c" and "msp430g2553.Id" but I can't find a file with a .cmd extension in any of these.

    I presumed you use the TI MSP430 compiler.  But from that linker command file name I can see you use the GCC MSP430 compiler.  The directories and files you list are all normal for a CCS project which builds with the GCC MSP430 compiler.

    Thanks and regards,

    -George

  • Daniel Milutinovic said:
    In my case it says "4158 (code) and 20 (data) bytes written to FLASH/FRAM. Expected RAM usage is 1616 (uninitialized data and stack) bytes." The expected RAM usage is clearly more than the maximum allowed (512 bytes for the M430G2553).

    A bug has been reported for that, see CCS Shows way to much expected ram usage in console window after build

    Daniel Milutinovic said:
    How can one determine exactly how large their program is?

    The GCC linker doesn't report the total usage of the memory regions. However, the .map file generated by the linker does report the total size of each section and the allocated section address. You can then sum-up the sections which have been allocated in flash and RAM to see how large the program is.

  • I found that there are also many examples in "Resource Explorer(Examples)" under "View" for those new to CCS.

    Thank you George and Chester for taking the time to answer my questions.