Skip to main content
Associate III
April 11, 2024
Solved

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

  • April 11, 2024
  • 4 replies
  • 3312 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

 

4 replies

Andrew Neil
Andrew NeilBest answer
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

 

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
ShiinaAuthor
Associate III
April 13, 2024

thanks

Tesla DeLorean
Guru
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. 

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
mƎALLEm
ST 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.

To give better visibility on the answered topics, please click "Best answer" on the reply which solved your issue or answered your question.