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.

Linker C6000: how to automatically set a sections size to the free (non allocated) memory?

Hi,

I want, at link time,  to allocate automatically all the free remaining RAM memory to a special section to be used as a custom memory pool that adapts its size to the size of unused memory. I tried some SPC arithmetic but I'm not able to work it out.

Something like:

#define RAM_SIZE (512*1024*1024)   //512M (EVM)

MEMORY { .... RAM: o=0x80000000, l=RAM_SIZE }

SECTIONS

{

...

GROUP

{

  .data

   ...

  .sysmem

   .my_memory_pool: align(0x100), type=NOINIT

   {

    my_memory_pool_begin = . ;

     . += END(RAM) -  my_memory_pool_begin ;  // error:  my_memory_pool_begin undefined!!

   }

} > RAM

}

I tried also with SIZE(RAM) and literal values but I get always some errors.

  • You don't need to explicitly construct a section to solve your problem.  I'll present my solution as a series of linker command file snippets.

    Before either the MEMORY or SECTIONS directives have ...

    #define RAM_START 0x80000000
    #define RAM_SIZE  0x02000000
    
    _my_heap_size = RAM_START + RAM_SIZE - _my_heap_start;
    

    In the MEMORY directive have ...

    RAM:    o = RAM_START   l = RAM_SIZE
    

    The SECTIONS directive will include something similar to ...

    GROUP
    {
        .stack
        .args
        /* other data memory sections here */
    } > RAM, end(_my_heap_start)
    

    You can use the symbols my_heap_start and my_heap_size in your code to set up your custom heap.

    Thanks and regards,

    -George