cancel
Showing results for 
Search instead for 
Did you mean: 

Different linking behavior (same project) between Clion and STM32CubeIDE

azer asd
Associate II

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 :

  • heap_end : 0x200119fc
  • sp : 0x20003370

In CLion I did the same test :

  • heap_end : 0x20012000
  • sp : 0x20005d58

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.

1 REPLY 1
Markus GIRDLAND
ST Employee

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!