2021-05-25 01:42 AM
Hello.
I am currently working on CLion and I am trying to switch to STM32CubeIDE but my code is asserting in a malloc function called in rand() function called in udp_init() of LwIP.
In _sbrk() function I can see :
In CLion I did the same test :
In this case malloc is working.
I am using code generated by STM32CubeMX, I am using FreeRTOS and LwIP.
Do you know how to change this behavior to allocate memory without issue ?
Do you know if I can stop using malloc but use pvPortMalloc instead ? I don't have access to standard C library with STM32CubeIDE so I don't know how to do it.
Thank you for you help.
2021-05-25 05:08 AM
What version of CubeIDE are you using?
The bsrk() function in CubeIDE version prior to 1.6.x makes a check:
if (heap_end + incr > stack_ptr)
This check is to see that heap + new memory allocation will not grow into the stack. But it is under the assumption that the stack is located above the heap.
In some memory configurations for FreeRTOS the FreeRTOS task stacks are located inside the bss. And the bss region is below the memory space available for the heap. --> Problem!
Generating a new project in CubeIDE 1.6.x and copying the sysmem.c to your project could fix this issue.
Next step will be to consider thread-safety in your application. newlib malloc is not thread-safe by default!