Skip to main content
Associate III
Apr 11, 2024 6:33 AM UTC
Solved

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

How does STM32 dynamically allocate memory ?

This topic has been closed for replies.
Andrew Neil
Andrew NeilBest answer
Super User
Apr 11, 2024 8:50 AM UTC

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.

4 replies

Andrew Neil
Andrew NeilBest answer
Super User
Apr 11, 2024 8:50 AM UTC

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
Apr 13, 2024 3:49 AM UTC

thanks

Tesla DeLorean
Guru
Apr 11, 2024 9:03 AM UTC

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
Apr 11, 2024 9:12 AM UTC

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.