Hi
I try to understand HEAP_SIZE and STACK_SIZE in .ld file
In this file KDS find the RAM size : 0x8000 for my KL17Z256VLH4 ; why should we specify KDS the size of stack and head ?
>> Why compiler and linker can not work with just the RAM size ? (to optimize its use)
/*for my KL17Z256*/
HEAP_SIZE = DEFINED(__heap_size__) ? __heap_size__ : 0x8000; /* defaut 0x0400*/
STACK_SIZE = DEFINED(__stack_size__) ? __stack_size__ : 0x8000; /* defaut 0x0400*/
/* 0x8000 = RAM size */
I use Freertos (with en other heap specification : configTOTAL_HEAP_SIZE)
Thank you in advance for your explanations
Hi,
it's necessary to allocate max heap and stack size in a project beforehand.
because:
stack is needed to allocate function parameters, local variables,etc
heap is needed if using mallo() to apply a memory.
global variables and static variables are allocate in RAM (not stack space, neither heap).
normally a project (including called system files) need to use stack and heap anyway, so it's necessary to allocate them in linker file.
Have a great day,
Jennie Zhang
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Hi, thank for your answer
I understand a little better since Friday and you end make me understand (I hope !)
I'm right ? :
Heap :
1>>When using FreeRTOS (I don't use malloc apart from freertos) the heap necessary is that required by FreeRTOS only. (I can use xPortGetFreeHeapSize() to optimise this)
As freertos use malloc to allocate task stack, heap need to be large for a freertos application
2>> If not using malloc or FreeRTOS ; heap can be set to zero (no dynamic allocation)
Stack :
3>>With freertos i need just allocate stack for some variables that are outside FreeRTOS. The not stack or heap space must be allocate for some global or static variables that are outside FreeRTOS.
4>>Without FreeRTOs. I need to allocate the largest Stack, with just enough RAM (not stack space, neither heap) for global or static variables.
5>> In any case I need to leave space in RAM for startup vector table copy.
I'm right ?
thanks
Hi,
regarding to your comments,
for Heap:
no matter using or not using rtos, I suggest you NOT set heap size, even you think your code doesn't use malloc, it potentially called some low level system library functions that could use heap.
for stack:
when use freeRTOS, the freeRTOS related codes are also part of project. the global variables and static variables in freeRTOS are allocated in RAM; the local variables in freeRTOS are allocated in stack.
5>>
yes.
Have a great day,
Jennie Zhang
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------