Thread working areas not going to CCM ram.
Posted: Wed Nov 05, 2014 4:06 pm
Hey,
I found out that the thread stacks are not using CCM, hence a lof of valuable ram is wasted, not even counting on the performance.
I made a little change that should work on all platforms:
chthreads.h:
Linker script:
Tested and works fine on STM32F3
Saved me 6kb of "normal" ram.
Idealy this should be an option as some might want to use DMA with data from their threads.
Another option is this macro:
However it won't put system threads in CCM. (idle, possibly USB and LWIP)
I found out that the thread stacks are not using CCM, hence a lof of valuable ram is wasted, not even counting on the performance.
I made a little change that should work on all platforms:
chthreads.h:
Code: Select all
#define THD_WORKING_AREA(s, n) \
stkalign_t s[THD_WORKING_AREA_SIZE(n) / sizeof(stkalign_t)] __attribute__ ((section (".stacks")))
Linker script:
Code: Select all
.stacks :
{
. = ALIGN(8);
__main_stack_base__ = .;
. += __main_stack_size__;
. = ALIGN(8);
__main_stack_end__ = .;
__process_stack_base__ = .;
__main_thread_stack_base__ = .;
. += __process_stack_size__;
. = ALIGN(8);
__process_stack_end__ = .;
__main_thread_stack_end__ = .;
} > ccmram AT > ram
.ccm (NOLOAD) :
{
PROVIDE(_cmm_start = .);
. = ALIGN(4);
*(.stacks)
. = ALIGN(8);
*(.stacks.*)
. = ALIGN(8);
*(.ccm)
. = ALIGN(4);
*(.ccm.*)
. = 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 AT > ram
Code: Select all
$ arm-none-eabi-size.exe -A motolink.elf
motolink.elf :
section size addr
startup 416 134238208
.text 36004 134238624
.textalign 4 134274628
.stacks 1536 268435456
.ccm 5952 268436992
.data 1356 536870912
.bss 17656 536872272
.ARM.attributes 53 0
.comment 112 0
.debug_info 128859 0
.debug_abbrev 13106 0
.debug_loc 34585 0
.debug_aranges 1752 0
.debug_ranges 6240 0
.debug_line 25669 0
.debug_str 18703 0
.debug_frame 4880 0
Total 296883
Tested and works fine on STM32F3
Saved me 6kb of "normal" ram.
Idealy this should be an option as some might want to use DMA with data from their threads.
Another option is this macro:
Code: Select all
#define THD_CCM_WORKING_AREA(s, n) THD_WORKING_AREA(s, n) __attribute__ ((section (".ccm")))
However it won't put system threads in CCM. (idle, possibly USB and LWIP)