Hi
I was reading up on the use of the stack and heap of the startup files on the FreeRTOS website and it was implied that these two memory areas were only used by the main.c program. Anything done in a task used the task stack and FreeRTOS heap.
I am using Simple Dynamic Strings (SDS).
So I set my heap to 0 in the startup file and bang! Hard fault. The thing crashed in the sds string function sdslen because the function tried to address 0x00000000 - 1. Bad idea.
I made my startup heap 4k and it worked.
Am I going about this the correct way or should I be calling a different malloc from within sds.
sds has an allocator for memory management:
/* SDS allocator selection.
*
* This file is used in order to change the SDS allocator at compile time.
* Just define the following defines to what you want to use. Also add
* the include of your alternate allocator if needed (not needed in order
* to use the default libc allocator). */
#define s_malloc malloc
#define s_realloc realloc
#define s_free free
Should I be fiddling with this or should I just use the startup heap? I only use sds in one task, but I may wish to use it in another.
I’m happy with the way it works, but there might be some nasty side effects I’m unaware of.
I also don’t quite get the difference between the startup heap and the heap set in FreeRTOS config.
I have read the stuff on the web site, but the penny hasn’t dropped. If I create a variable using malloc in a task, which heap is it using, the startup heap, the one defined in FreeRTOSConfig or the task heap itself? Can I create a variable by calling pvPortMalloc(). Which heap would this use?
Also I would think that all interrupts use the startup stack as the startup code sets the stack pointer to the address assigned in startup viz:
Reset_Handler:
ldr sp, =_estack
_estack if defined in the GCC linker script:
/* Highest address of the user mode stack */
_estack = ORIGIN(DTC_STACK) + LENGTH(DTC_STACK); /* end of "RAM" Ram type memory */
_Min_Heap_Size = 0x1000 ; /* required amount of heap */
_Min_Stack_Size = 0x1000 ; /* required amount of stack */
/* Memories definition */
MEMORY
{
FIR_FILT_DW (xrw) : ORIGIN = 0x20000000, LENGTH = 4K
DTCM_MISC (xrw) : ORIGIN = 0x20001000, LENGTH = 116K
DTC_STACK (xrw) : ORIGIN = 0x20010000, LENGTH = 8K
It’s all a bit mysterious.
Best regards
Rob