cancel
Showing results for 
Search instead for 
Did you mean: 

Is _sbrk generated by stm32cubeide incompatible with FreeRtos?

Alexander Vasiljev
Associate II

Hello!

Stm32CubeIde generated _sbrk(int incr) function for me. Also I need to use FreeRtos.

_sbrk checks heap not to overcome stack pointer.

if (heap_end + incr > stack_ptr)

   {

      errno = ENOMEM;

      return (caddr_t) -1;

   }

But FreeRtos allocates stacks for every task from the heap. So eventually some stack pointer of a task that is going to allocate memory, will be smaller than the heap_end.

I know how to deal with it. But as this file is auto-generated, I ask you to repair this in the next releases of Stm32CubeIDe.

I use stm32F22RET6 MCU.

Stm32CubeIde 1.4.0

4 REPLIES 4
TDK
Guru

> Is _sbrk generated by stm32cubeide incompatible with FreeRtos?

Yes, unless something has changed with a recent version:

https://community.st.com/s/question/0D50X0000AAIEWbSQP/stm32cubemx-generated-sbrk-in-syscallsc-not-working-with-freertos

If you feel a post has answered your question, please click "Accept as Solution".
Pavel A.
Evangelist III

You see, neither sbrk nor mallloc and its friends are part of FreeRTOS API.

FreeRTOS has its own allocation functions.

So you actually request ST to provide integration of FreeRTOS with the C library (newlib) malloc.

-- pa

Alexander Vasiljev
Associate II

Pavel,

The realization of sbrk in Stm32CubeIde is a copy from newlib doumentation. https://sourceware.org/newlib/libc.html#index-sbrk

So it can be considered to be integrated with newlib per the documentation. :)

But it doesn't help when you deal with FreeRtos.

Alexander Vasiljev
Associate II

TDK,

Thank you for reference!