cancel
Showing results for 
Search instead for 
Did you mean: 

Does new project use all the available RAM?

JBond.1
Senior

I have created new project with STM32CubeMX for my STM32F091RC. I have noticed that when allocating memory it ends very fast. Do I need to change any settings to use all of the available 32Kb of memory?

In "startup_stm32f091xc.s" I find these values:

Stack_Size      EQU    0x400

Heap_Size     EQU    0x200

Should they be much bigger? Why default project does not use max available memory? What maximum values I can use?

13 REPLIES 13

The defaults tend in ensure that the linker can get closure and build the project. The appropriateness of everything is your domain.

Your responsibility as a programmer is to understand the usage/expectation of your code/algorithms, and things like interrupt loading.

Embedded is a more constrained environment, you can't allocate more virtual memory and spill it to a paging file. You also have to be aware of long term usage patterns, as the devices may be expected to run for months or years, so you can't have dynamic memory leaks or fragmentation issues.

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

Always make the stack size big as when you hit its limit, finding the root cause is time consuming. Note: If your leftover RAM is full, the linker will error. The reverse won't be,

Some linkers can crawl recursively to give you the max stack depth from all the vectors, so you could guess the max stack size with all possible interrupts running.

Unfortunately, once people use function pointers, this recurse analysis (some MAP file will show it) is less reliable.

I would make it for bare metal few kbytes if you declare arrays or big structures in functions (which reduces the need for heap and malloc() )

When using RTOS, that is a totally different story.

Piranha
Chief II

> 32Kb = 0x7FFF, stack and heap gets only 0x400, 0x200 so ALL the rest 0x79FF is for global and static variables?

The 0x7FFF and 0x79FF are adresses of the last bytes, but sizes are 0x8000 and 0x7A00 respectively.

S.Ma
Principal

Actually, even though there is no convenient way to do it, theoretically, for bare metal applications, all globals could be created as local variables in the stack in main(), which would be a different way to answer your question.