cancel
Showing results for 
Search instead for 
Did you mean: 

What is the meaning of "minimum heap size" and "minimum stack size", in stm32cube ide?

AKuma.2074
Associate III

Dear friends,

Recently I came across the options of "minimum heap size" and "minimum stack size" in stm32cube ide and linker file as well.

I can't understand the actual meaning of the numbers. Does the sum of both has to be equal to the ram size. Can it be less?

How to determine the values? Or i simply just tell compiler to break the ram into the given value?

Or Does it reserve some memory for some other purposes?

Or does it mean entirely something else.

I am working on stm32l010k4, and am running low on ram size, 96% consumed. Unfortunately i can't upgrade the microcontroller.

Any suggestions?

4 REPLIES 4

Generally to tell the *linker* what the allocations are so they can be accounted for in the totals for the build, and determining if it will fit.

They don't have to be equal, but need to be realistic.

If you, and any code you call, don't use malloc()/free() you can dispense with the Heap

The stack utilization depends on the depth of you call trees, the amount of auto/local variable usage, and how your interrupts, and what they call eats into that further.

Typically you analyze/review the actually usage patterns dynamically, so you can establish a reasonable value.

If you don't have a large enough area for the stack it will crash downward into you other RAM usage, corrupting that.

You could try different optimization settings. Try a better compiler, like Keil, ST has a free licence for STM32 Cortex-M0(+) parts

Reduce RAM usage by reusing buffers for multiple purposes.

Avoid static/global allocations where possible, instead using a larger stack frame.

Avoid using RAM for constant data, especially in subroutines

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Javier1
Principal

>I can't understand the actual meaning of the numbers.

its my understanding those values mean number of bytes in hexadecimal.

being a minimum heap of 0x100 --> 256 bytes

minimum heap of 0x1000 --> 4Kilobytes

The rest of your questions are very interesting to me, i have little-no idea about how the compiler manages those min heap and min stack values.

i think this clarifies things https://community.st.com/s/question/0D50X0000BiD97O/stm32-stack-and-heap

we dont need to firmware by ourselves, lets talk

So, if i am getting you right. If i am using 512bytes of variable, taking double memory to be on safe side, i can set the stack size to hex equivalent of 1kb?

These variables are global. Should it affect anything?

And as dynamic allocation is zero, i can set it to near zero or zero value?

Shoud it be okay?

And why should i avoid static/global variables?

I know static/globals are stored in data section, but what problems can it create?

Actually, i need to view some data from debugger, hence globals are mandatory.

Thanks for the reply.

Thank you for the link.

But its still a bit unclear to me