I just hit this issue and not sure the best way to deal with it….
I selected heap_3 (using system malloc), I’m using FreeRTOS 7.5.0 via Erich Steyger’s PE component.
Set up the system stack & heap with plenty of room for this,
What happens is I get a vApplicationMallocFailedHook when trying to create the first task.
It looks like what’s happening is the Kinetis EWL malloc (alloc.c) routine is set up to grow the heap into the stack,
so when it wants to grow it, it checks the stack pointer (SP register) to see if it’s collided and returns fail if so.
Since FreeRTOS uses the heap as the stack, it has just set SP to be basically at the top of the current heap, so of course
this test in malloc (well, actually in sbrk()) will fail.
Looking at alloc.c’s source, there’s a #define HEAP_GROWS 1 in there that could probably be set to zero so the heap is
fully allocated, but that means having the rebuild the system libraries, making that solution very non-portable…
I’m wondering what other ARM chip ports might have this same issue?
So what to do….? Perhaps, in the heap_3 wrapper, save and restore SP, and set it to something useful to detect actual collisions (in this case, SP_MAIN would probably be good) during the malloc call?