Hi,
I am trying to figure out how can I define the start and end of the Heap.
My processor is MK66 with 256K Ram & Atolic True Studio.
The Ram Starts at 0x1FFF 0000 and ends at 0x2002 FFFF.
According to Data sheet the memory is not divided into two regions.
SRAM_L From 0x1FFF 0000 to 0x1FFF FFFF (in total 64K bytes).
SRAM_U From 0x2000 0000 to 0x2002 FFFF (in total 192K bytes).
I want to place Data, Fast Code & Stack in SRAM_L Region. And the Heap in SRAM_U region.
The first part is easy but I don't know how to tell the Linker to place Heap at the start of SRAM_U.
By default the linker script provided by Atolic considers the whole Ram as one continuous Region and places the the start of Heap at some where after end of .bss section.
(I know from my previous experience with TI's TMS320 DSP where there were symbols called ".sysmem" & "heap size" which could be linked at desired address and with desired size. )
Solved! Go to Solution.
Hi,
I think I found the answer to my question but if someone have a better one please feel free to correct me.
Well after a bit research I came across this article of stackoverflow.com: (which shed some light on the matter)
gcc - setting up heap in memory for ARM embedded system - Stack Overflow
Atolic True Studio Provides following "_sbrk" function in syscalls.c file. which is called in this sequence
( new[] -> malloc() -> _sbrk_r() -> _sbrk() ).
caddr_t _sbrk(int32_t incr)
{
extern uint8_t end asm("end");
static uint8_t *heap_end;
uint8_t *prev_heap_end;
if (heap_end == 0)
heap_end = &end;
prev_heap_end = heap_end;
if (heap_end + incr > stack_ptr)
{
errno = ENOMEM;
return (caddr_t) -1;
}
heap_end += incr;
return (caddr_t) prev_heap_end;
}
and also see the following listing from linker file.
/* User_heap_stack section, used to check that there is enough RAM left */
._user_heap_stack :
{
. = ALIGN(4);
PROVIDE ( end = . );
PROVIDE ( _end = . );
. = . + _Min_Heap_Size;
. = . + _Min_Stack_Size;
. = ALIGN(4);
} >RAM
in both the listings the symbol "end" is the key.
This symbol defines the start point of Heap and you can control the Heap size by re-writing the function "_sbrk", for that see also the link gcc - setting up heap in memory for ARM embedded system - Stack Overflow
Regards
Lal
Hi,
I think I found the answer to my question but if someone have a better one please feel free to correct me.
Well after a bit research I came across this article of stackoverflow.com: (which shed some light on the matter)
gcc - setting up heap in memory for ARM embedded system - Stack Overflow
Atolic True Studio Provides following "_sbrk" function in syscalls.c file. which is called in this sequence
( new[] -> malloc() -> _sbrk_r() -> _sbrk() ).
caddr_t _sbrk(int32_t incr)
{
extern uint8_t end asm("end");
static uint8_t *heap_end;
uint8_t *prev_heap_end;
if (heap_end == 0)
heap_end = &end;
prev_heap_end = heap_end;
if (heap_end + incr > stack_ptr)
{
errno = ENOMEM;
return (caddr_t) -1;
}
heap_end += incr;
return (caddr_t) prev_heap_end;
}
and also see the following listing from linker file.
/* User_heap_stack section, used to check that there is enough RAM left */
._user_heap_stack :
{
. = ALIGN(4);
PROVIDE ( end = . );
PROVIDE ( _end = . );
. = . + _Min_Heap_Size;
. = . + _Min_Stack_Size;
. = ALIGN(4);
} >RAM
in both the listings the symbol "end" is the key.
This symbol defines the start point of Heap and you can control the Heap size by re-writing the function "_sbrk", for that see also the link gcc - setting up heap in memory for ARM embedded system - Stack Overflow
Regards
Lal
Hi again,
there is a typo in sentence number 4 so here is my question re posted.
I am trying to figure out how can I define the start and end of the Heap.
My processor is MK66 with 256K Ram & Atolic True Studio.
The Ram Starts at 0x1FFF 0000 and ends at 0x2002 FFFF.
According to Data sheet the memory is divided into two regions.
SRAM_L From 0x1FFF 0000 to 0x1FFF FFFF (in total 64K bytes).
SRAM_U From 0x2000 0000 to 0x2002 FFFF (in total 192K bytes).
I want to place Data, Fast Code & Stack in SRAM_L Region. And the Heap in SRAM_U region.
The first part is easy but I don't know how to tell the Linker to place Heap at the start of SRAM_U.
By default the linker script provided by Atolic considers the whole Ram as one continuous Region and places the the start of Heap at some where after end of .bss section.
(I know from my previous experience with TI's TMS320 DSP where there were symbols called ".sysmem" & "heap size" which could be linked at desired address and with desired size. )
Regards
Lal.