What are the stack and heap set in the GCC linker script used for?

Hi

In the linker script for GCC the following are set:

ENTRY(Reset_Handler)

/* Highest address of the user mode stack */
_estack = ORIGIN(DTC_STACK) + LENGTH(DTC_STACK); /* end of "RAM" Ram type memory */

_Min_Heap_Size  = 4K; /* required amount of heap */
_Min_Stack_Size = 4K; /* required amount of stack */

/* Memories definition */
MEMORY
{
  DTC_STACK    	(xrw)    : ORIGIN = 0x10000000,   LENGTH = _Min_Heap_Size + _Min_Stack_Size
  DTCM_MISC    	(xrw)    : ORIGIN = 0x10000000 + _Min_Heap_Size + _Min_Stack_Size,  LENGTH = 10K - _Min_Heap_Size + _Min_Stack_Size
  RAM     		(xrw)    : ORIGIN = 0x20000000,   LENGTH = 32K - 1k
  RAM_NVS		(xrw)    : ORIGIN = 0x20008000,   LENGTH = 1K
  FLASH    		 (rx)    : ORIGIN = 0x8000000,    LENGTH = 128K
}

I am guessing the stack is used for interrupt processing, saving registers etc, but what is the heap used for. What’s the best way of working out the size necessary for each of these?

Thanks
Rob

The heap size defined in the linker file will generally be for the standard C library malloc function, which is likely not thread-safe unless you have taken the steps to make it so. (or the environment has been specially created for FreeRTOS and has taken the steps by default to make it safe).

As to figuring out how much space you need, you really need to know your application and its needs, or start big and see what is left after testing.