Memory sections in linker script

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderator: RoccoMarco

Laurent
Posts: 35
Joined: Mon Mar 25, 2013 9:01 am

Memory sections in linker script

Post 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.
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Memory sections in linker script

Post 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
User avatar
Tectu
Posts: 1225
Joined: Thu May 10, 2012 9:50 am

Re: Memory sections in linker script

Post 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
Laurent
Posts: 35
Joined: Mon Mar 25, 2013 9:01 am

Re: Memory sections in linker script

Post 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?
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Memory sections in linker script

Post 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
efuentes
Posts: 35
Joined: Wed Jul 25, 2012 6:16 am

Re: Memory sections in linker script

Post 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.
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Memory sections in linker script

Post 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
Laurent
Posts: 35
Joined: Mon Mar 25, 2013 9:01 am

Re: Memory sections in linker script

Post 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?
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Memory sections in linker script

Post 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
Laurent
Posts: 35
Joined: Mon Mar 25, 2013 9:01 am

Re: Memory sections in linker script

Post 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 , ...);
Post Reply