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 declare an array that fills an entire section?



Hi

I am familiar with how to define an array that is to placed in a specific area of memory.  For example:

const unsigned MY_TABLE_SIZE=1024;

#pragma DATA_ALIGN(4);

#pragma DATA_SECTION(".ddr_table")

unsigned myTable[MY_TABLE_SIZE];

 

Is it possible to automatically size the array to fit an entire section?

I am thinking of something like:

const unsigned MY_TABLE_SIZE = DATA_SECTION_SIZE(".ddr_table");

#pragma DATA_SECTION(".ddr_table")

unsigned myTable[MY_TABLE_SIZE];

Best regards

David

  • David Aldrich92784 said:
    Is it possible to automatically size the array to fit an entire section?

    You can do something similar by using the #include feature of linker command files.

    This header file gets included by both your C code and your link command file.  Note "MR" stands for memory range.

    // mr_lengths.h -------------------------------
    #define MR_LENGTH 0x1000

    Your C code is similar to this.

    #include "mr_lengths.h"
    
    #pragma DATA_SECTION(table, "special_section");
    unsigned table[MR_LENGTH/sizeof(unsigned)];

    And your link command file has lines similar to this.

    #include "mr_lengths.h"
    
    MEMORY
    {
       MR_SPECIAL : org = 0x80000000, len = MR_LENGTH
    }
    
    SECTIONS
    {
       special_section > MR_SPECIAL
    }
    

    Notice how MR_LENGTH is defined once and used in both the C source and the link command file.

    Thanks and regards,

    -George

  • Hi George

    Thanks for your answer.

    Best regards

    David