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/MSP430F5659: How to compile big arrays?!

Part Number: MSP430F5659

Tool/software: Code Composer Studio

Good morning TI experts,

today I'm here because I have an issue related to arrays' compiling.

I need to load in my project this very big data array:

char example[]= { 164,74,196,74,229,82,5,83,39,91,71,91,72,91,104,99,136,99,169,99,169,107,169... };       /* total size= 124160*/

And, as expected, I have this error: #96 array is too large.

In my project properties I have selected large code memory model and restricted data memory model; so, I know that the maximum data size in this case is 64kB for each individual object, isn't it?!

But if I have to work with bigger data array (such as "example") which is the best way to avoid this problem?

Your advice and help would be really apreciated,

Thanks & Kind regards,

Maria Angela

  • Maria Angela Cianci said:
    But if I have to work with bigger data array (such as "example") which is the best way to avoid this problem?

    Change the data memory model from restricted to large.  Read more about the memory models in the MSP430 compiler manual section titled Data Memory Models.

    Thanks and regards,

    -George

  • Thanks for your fast reply George.

    After changed the data memory model from restricted to large I'm able to compile the array "example" only if I define it as 

    const char example[176660]= {....};

    (But it doesn't work with my project at the moment).

    If then I try with 

    char example[176660]= {... };

    unfortunately Code Composer shows me this error: "program will not fit into available memory. placement with alignment fails for section ".cinit" size 0x24fed".

    What's wrong in the memory placement of this array?

    Thanks & Kind Regards,

    MariaAngela

  • Maria Angela Cianci said:
    (But it doesn't work with my project at the moment).

    Object files built with different data models are not compatible. All files in an application must be built with the same data model. Additionally, a run-time-support library matching that data model must be used.

    Check --near_data flag value.

    When --near_data=globals is specified, this option tells the compiler that all global read/write data must be located in the first 64K of memory. This is the default behavior. Global read/write data is placed by default in the .bss and .data sections. If --near_data=none is specified, this option tells the compiler that it cannot rely on this assumption to generate more efficient code.

  • Because of the keyword const, this array ...

    Maria Angela Cianci said:
    const char example[176660]= {....};

    requires less space than this array ...

    Maria Angela Cianci said:
    char example[176660]= {... };

    I'll call the first one the const array, and the second one the regular array.

    The const array is created and initialized all at once.  It takes up, in this case, 176,660 bytes.

    The regular array is created and initialized in separate steps.  The compiler places all the values in an initialized section named .data.  The linker collects all the .data sections together, and based on that, creates a compressed initialized section named .cinit. The .data section is then changed from initialized to uninitialized.  Startup code decompresses the .cinit section and copies the values into .data.  How much memory is used?  The uninitialized .data section uses 176,660 bytes.  The initialized .cinit section, because of compression, uses less.  But it is still somewhere around 100,000 bytes.  

    Thus, the regular array uses much more memory than the const array.  In your case, it causes your program to not fit on your system.

    Thanks and regards,

    -George

  • Dear Tomasz,

    Dear George

    thank you very much for your clear and accurate answers.

    Now, finally, I understand in a very good way what are .cinit and .data section!

    If I compile the program using

    const char example[]={...};

    I use Flash/FRAM: 181130 bytes. RAM: 222 bytes.

    Otherwise I'm not able to load the program for the debug session because of the errors I mentioned in the previous post related to the memory allocation.

    So, if I want to use a regular array it must be smaller, right? There isn't another way to compile and use such big data array, is there?

    Any hint and advice would be really appreciated.

    My best regards,

    Maria Angela

  • For each constant and variable, you can assign a separate data section and place that section even at a specified data address.
  • Maria Angela Cianci said:
    So, if I want to use a regular array it must be smaller, right?

    Yes

    Maria Angela Cianci said:
    There isn't another way to compile and use such big data array, is there?

    No

    Thanks and regards,

    -George