Skip to main content
Graduate II
April 11, 2024
Solved

What does malloc() do in an STM32 MCU run without an OS ?

  • April 11, 2024
  • 3 replies
  • 3266 views

How does STM32 dynamically allocate memory ?

    This topic has been closed for replies.
    Best answer by Andrew Neil

    https://stackoverflow.com/questions/77829982/how-does-arm-none-eabi-gcc-9-2-implement-malloc-free

     

    EDIT

    You didn't state what compiler you're asking about.

    The above relates to the GCC/ARM compiler, as used in the STM32CubeIDE, using the newlib library.

    Other compilers & libraries are available; eg,

    https://developer.arm.com/documentation/dui0067/d/the-c-and-c---libraries/tailoring-storage-management/support-for-malloc

     

    3 replies

    Super User
    April 11, 2024

    https://stackoverflow.com/questions/77829982/how-does-arm-none-eabi-gcc-9-2-implement-malloc-free

     

    EDIT

    You didn't state what compiler you're asking about.

    The above relates to the GCC/ARM compiler, as used in the STM32CubeIDE, using the newlib library.

    Other compilers & libraries are available; eg,

    https://developer.arm.com/documentation/dui0067/d/the-c-and-c---libraries/tailoring-storage-management/support-for-malloc

     

    ShiinaAuthor
    Graduate II
    April 13, 2024

    thanks

    Graduate II
    April 11, 2024

    It allocates memory from the heap. In the GNU/GCC sense this is from the top of the statics to the bottom of the stack via sbrk().

    On Keil/IAR it would be a section of heap memory of defined size that the linker places after the statics. 

    Technical Moderator
    April 11, 2024

    From the title I understand: in which situation the dynamic allocation is used if no rtos is used, but in the text I understand something else. Need to be concise.