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.

Get the start, end and the size of a memory section of the linker file with _symval

Other Parts Discussed in Thread: MSP430F5438A

Hello,

 

I am working with a MSP430F5438A and CCS  Version: 5.5.0.00077 and TI compiler version 4.2.4

I declared 2 memory sections in the linkerfile because I want to place some data there. 

MEMORY
{
...

DATA_A : origin = 0x45800,length = 0x200
DATA_B : origin = 0x45A00,length = 0x200

...
}

In the sections file I have placed: 

SECTIONS
{
...

.dataA : START(dataA_start), SIZE(dataA_size)
{} > DATA_A /* storage area for data Page A */
.dataB : START(dataB_start), SIZE(dataB_size)
{} > DATA_B /* storage area for data Page B */

...

}

and in source code: 

...

#define DATA_A_STARTADDRESS (const unsigned int *) _symval(&dataA_start)
#define DATA_A_SIZE _symval(&dataA_size)
#define DATA_B_STARTADDRESS (const unsigned int *) _symval(&dataB_start)
#define DATA_B_SIZE _symval(&dataB_size)

extern char dataA_start, dataA_size; /* the type does not matter! It is a linker file variable, it has no address only a value. */
extern char dataB_start, dataB_size; /* the type does not matter! It is a linker file variable, it has no address only a value. */

...

The defines I use in the source code. The startaddress is working and returning the first address of the reserved memory part. but the size stays 0. 

I have also tried:

- RUN_SIZE()

- LOAD_SIZE()

- END()

but they all return 0. It seems now that only the START() function is working. Is there something I do wrong? I would like to let the RUN() and END() also work. 

Best regards,

Jeroen

  • Jeroen Begeer said:
    The startaddress is working and returning the first address of the reserved memory part. but the size stays 0.

    Is the linker actually allocating any sections to the memory regions for which the SIZE operator is used for?

    From looking at the symbols in the linker map file found that the SIZE operator returns how many bytes have been allocated in the memory region, rather than the size of the memory region itself.

  • Thank you for your reply!

    I think that is the problem. The linker isn't allocating any data to the memory region where I wanted to know the size. 

    What is the correct way to get the size of a memory region in the source code without allocating any data to the memory region in the linker file? 

  • Jeroen Begeer said:
    What is the correct way to get the size of a memory region in the source code without allocating any data to the memory region in the linker file?

    It looks like the linker command file can create symbols which relate to the size of MEMORY regions. E.g. created a linker command file with:

    /****************************************************************************/
    /* SPECIFY THE SYSTEM MEMORY MAP                                            */
    /****************************************************************************/
    
    MEMORY
    {
        /* Other memory regions removed in this example */
        DATA_A : origin = 0x24000,length = 0x200
        DATA_B : origin = 0x24400,length = 0x200
    }
    
    /****************************************************************************/
    /* SPECIFY THE SECTIONS ALLOCATION INTO MEMORY                              */
    /****************************************************************************/
    
    SECTIONS
    {
        /* Other sections removed in this example */
        .dataA : {} > DATA_A /* storage area for data Page A */
        .dataB : {} > DATA_B /* storage area for data Page B */
    }
    
    /* Define symbols for the start and size of MEMORY regions */
    dataA_start=START(DATA_A);
    dataA_size=SIZE(DATA_A);
    
    dataB_start=START(DATA_B);
    dataB_size=SIZE(DATA_B);
    

    The DATA_A region had no sections allocated, and the DATA_B region had part of its space allocated with regions, as shown in the linker map file:

    MEMORY CONFIGURATION
    
             name            origin    length      used     unused   attr    fill
    ----------------------  --------  ---------  --------  --------  ----  --------
      <snip>
      DATA_A                00024000   00000200  00000056  000001aa  RWIX
      DATA_B                00024400   00000200  00000000  00000200  RWIX
    

    However, with the setting of symbols the linker map file showed that symbols dataA_size and dataB_size had now been set to the total size of the memory regions:

    GLOBAL SYMBOLS: SORTED BY Symbol Address 
    
    address    name
    --------   ----
    <snip>
    00000200   dataA_size
    00000200   dataB_size
    <snip>
    00024000   dataA_start
    00024000   data_a_array
    00024400   dataB_start
    

  • Thanks for your solution, it is working!

    First I had placed the defines for the start and size of MEMORY regions in the SECTIONS part, that is not working. Then I saw it need to be placed outside of the SECTIONS. Now is it working and returns the size of the MEMORY region. 

    Thanks for your help. 

**Attention** This is a public forum