Question
STM32CubeMx generated _sbrk() in syscalls.c not working with FreeRTOS
Hi !
I'm working on a project using STM32CubeMx and FreeRTOS (version 9.0.0, MEMORY_ALLOCATION = STATIC) and running into trouble as soon as the new operator is used (in my case implicitly be the library function gmtime()).
The problem seems to be the function _sbrk() in the generated file syscalls.c:
The check in line 15 fails if using FreeRTOS due to each FreeRTOS task is using its own different stack pointer.
register char * stack_ptr asm("sp");
...
caddr_t _sbrk(int incr)
{
extern char end asm("end");
static char *heap_end;
char *prev_heap_end;
if (heap_end == 0)
heap_end = &end;
prev_heap_end = heap_end;
if (heap_end + incr > stack_ptr)
{
// write(1, "Heap and stack collision\n", 25);
// abort();
errno = ENOMEM;
return (caddr_t) -1;
}
heap_end += incr;
return (caddr_t) prev_heap_end;
}How can this be fixed ???
- is there a "special" version of _sbrk() available which can handle a non-continuous stack pointer memory space ?
- simply disable the check by modifying the generated file ? But neither the function is weak nor there are user code hooks implemented)
Thanks,
Michael.
