Page 1 of 2

Memory sections in linker script

Posted: Wed Apr 03, 2013 12:01 pm
by Laurent
Hi

I'm using a STM32F405 micro-controller, with its 192 KB of RAM. I need to get as much as possible from these 192 KB for dynamic allocations inside my program.

When I look at my linker script, I notice that two sections take a significant amount of RAM: ethram and ccmram.

Code: Select all

MEMORY
{
    flash : org = 0x08020000, len = 256k
    ram : org = 0x20000000, len = 112k
    ethram : org = 0x2001C000, len = 16k
    ccmram : org = 0x10000000, len = 64k
}


My questions are:
- what are these two sections (I can't find any documentation about ethram, very little about ccmram)?
- can I safely remove them and merge the saved space into the "ram" section, getting true 192 KB of RAM available?

In case ethram is related to some ethernet stuff, I can say that I have no ethernet controller on my board.

Re: Memory sections in linker script

Posted: Wed Apr 03, 2013 3:21 pm
by Giovanni
Hi,

You can merge ethram but not ccmram because it is not contiguous. Note that the CCMRAM is not reachable from the DMAs, it is documented on the Reference Manual.

Giovanni

Re: Memory sections in linker script

Posted: Wed Apr 03, 2013 3:28 pm
by Tectu
By the way, has anyone ever done some CCM benchmark? I'd be really interested to know if it works faster as well.


~ Tectu

Re: Memory sections in linker script

Posted: Wed Apr 03, 2013 3:31 pm
by Laurent
Thanks :)

Any idea what the ethram and ccmram sections are normally used for? Can I use the ccmram myself, or is it used for some internal stuff? Is it faster than normal RAM?

Re: Memory sections in linker script

Posted: Wed Apr 03, 2013 3:33 pm
by Giovanni
The CCMRAM is not faster than normal RAM but it is not affected by DMA operations and that would translate in better performance on DMA intensive systems. You could allocate stacks there for example (there is an example .ld file for that for the F4).

Giovanni

Re: Memory sections in linker script

Posted: Thu Apr 04, 2013 1:57 pm
by efuentes
What would be the best way to have space for variables allocated in the CCM instead of the SRAM?

Whenever I have done debugging, they have always been allocated in addresses greater than 0x20000000.

Re: Memory sections in linker script

Posted: Thu Apr 04, 2013 2:18 pm
by Giovanni
Hi,

In ChibiOS there is an example .ld file that shows how to allocate arbitrary variables into the CCM memory: ./os/ports/GCC/ARMCMx/STM32F4xx/ld/STM32F407xG_CCM.ld

See this:

Code: Select all

    .ccm :
    {
        PROVIDE(_cmm_start = .);
        . = ALIGN(4);
        *(.bss.mainthread.*)
        . = ALIGN(4);
        *(.bss._idle_thread_wa)
        . = ALIGN(4);
        *(.bss.rlist)
        . = ALIGN(4);
        *(.bss.vtlist)
        . = ALIGN(4);
        *(.bss.endmem)
        . = ALIGN(4);
        *(.bss.nextmem)
        . = ALIGN(4);
        *(.bss.default_heap)
        . = ALIGN(4);
        PROVIDE(_cmm_end = .);
    } > ccmram


Giovanni

Re: Memory sections in linker script

Posted: Thu Apr 11, 2013 11:56 am
by Laurent
I added this to my linker script:

Code: Select all

    .ccm :
    {
        PROVIDE(_cmm_start = .);
        . = ALIGN(4);
        *(.bss.my_var)
        . = ALIGN(4);
        PROVIDE(_cmm_end = .);
    } > ccmram


With

Code: Select all

MEMORY
{
    flash : org = 0x08020000, len = 256k
    ram : org = 0x20000000, len = 128k
    ccmram : org = 0x10000000, len = 64k
}


And, in one of my source files:

Code: Select all

char my_var[10];


But my_var is not put in CCM RAM (its address is still 0x2000...). The only difference with the provided example is that it also puts .stacks in CCM RAM; however it crashes my app if I do so (some obscur error with SPI interrupts).

What am I missing?

By the way, if my_var is a buffer which is then written to a file on a SD card, it's not going to work anyway since it involves DMA, right?

Re: Memory sections in linker script

Posted: Thu Apr 11, 2013 12:13 pm
by Giovanni
Right, no DMA there.

Check in the .map file the section containing you variable and use that name in the .ld file for relocation.

Giovanni

Re: Memory sections in linker script

Posted: Thu Apr 11, 2013 12:19 pm
by Laurent
Thanks.

One more question: if I only use the CCM RAM for one thing (like a single big buffer), can I access it directly by its address, without declaring anything in the linker script?
Like:

Code: Select all

char* ccmram_ptr = (char*)0x10000000;
memcpy(ccmram_ptr , ...);