Skip to main content
CYesi.1
Associate II
July 21, 2020
Question

What limits stack size?

Hello 

I am working on STM32L072 series MCU. I am using Stm32cubeide

My project is using %94 of RAM. I need more stack on my project. I tried to increase stack in linker file, but i get error. I think, there is enough area in my ram. Additionally, I can increase Heap size. But, IDE doesnt allow to increase stack size.

Is there any ram area allocated for heap? Or, why can not I use my free memory for stack?

Thank you

This topic has been closed for replies.

4 replies

Nikita91
Lead II
July 21, 2020

To know exactly how the RAM is used have a look to the Debug/xx.map file (xx is the project name).

CYesi.1
CYesi.1Author
Associate II
July 21, 2020

Thanks for your answer.

I have one more question. I moved a project from uVision to Stm32CubeIde. There is a difference between Ram usages. Same project compiling with STM32CubeIde use more Ram space. Do you know what is the reason?

Pavel A.
July 23, 2020

> Is there any ram area allocated for heap? Or, why can not I use my free memory for stack?

With a normal GNU-style linker script and library (newlib/nano) heap and stack share the same space.

Stack and heap sizes are defined as two separate constants, but actually it is single area with size = sum of two.

If your program does not use heap (malloc or sbrk), the whole space is available for stack.

If you have a custom link script, all bets are off.

> Same project compiling with STM32CubeIde use more Ram space. Do you know what is the reason?

Keil compiler and libraries are more frugal? At 94% of capacity this becomes noticeable.

-- pa

Cartu38 OpenDev
Graduate II
July 24, 2020

Takes care too to your compiler optimization settings. Default build configuration is debug oriented one not promoting best binary memory footprint. Some release configuration is avaible too. Then up to you to perfom proper tuning.​