Skip to main content
Alexander Vasiljev
Associate II
August 6, 2020
Question

Is _sbrk generated by stm32cubeide incompatible with FreeRtos?

  • August 6, 2020
  • 4 replies
  • 2197 views

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

This topic has been closed for replies.

4 replies

TDK
August 6, 2020

> 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.
August 6, 2020

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
August 7, 2020

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
August 7, 2020

TDK,

Thank you for reference!