Skip to main content
Moamen Ayman
Associate III
December 4, 2019
Question

STM32 stack and heap

  • December 4, 2019
  • 2 replies
  • 10356 views

Hello I want to understand allocating stack and heap size, I am using stm32f767zi with 512Kbyte RAM memory (0x80000 bytes) so what I understand is this memory should be split between only the stack and heap (if there is something else please tell me) so I gave the stack 0x60000 and the heap 0x20000 as in the attached photo. I am using IAR v8.

This topic has been closed for replies.

2 replies

waclawek.jan
Super User
December 4, 2019

No.

You need RAM also for global and static variables.

Stack is where the return addresses and register content and some other "helper" data are stored when calling subroutines, together with variables declared locally in functions (without static specifier).

Heap is where dynamically allocated (usually through calling malloc()) variables are stored.

JW

Ozone
Principal
December 4, 2019

> Heap is where dynamically allocated (usually through calling malloc()) variables are stored.

Actually, most toolchains set a default value of zero for the heap size. Many embedded projects do not use dynamic memory allocation at all.

Moamen Ayman
Associate III
December 4, 2019

So the RAM for only (global/static) (stack) (heap) is there something else?

Ozone
Principal
December 4, 2019

You can read up about C language memory/section management (variable placement) in general C tutorials.

And virtually all toolchains can create a map file during the linker run, an exhausting list of object (variable, code) sizes and placement.