Skip to main content
Manu Abraham
Senior
August 23, 2020
Question

STM32H743 Stack and Heap

  • August 23, 2020
  • 4 replies
  • 2187 views

Hi,

I have my scatter file defined thus:

// Scatter file

LR_IROM1 0x08000000 0x00200000 {   ; load region size_region

 ER_IROM1 0x08000000 0x00200000 { ; load address = execution address

  *.o (RESET, +First)

  *(InRoot$$Sections)

  .ANY (+RO)

 }

 RW_IRAM2 0x24000000 0x00080000 { ; RW data

  .ANY (+RW +ZI)

 }

 RW_DMARxDscrTab 0x30040000 0x60 {

 *(.RxDecripSection)

 }

 RW_DMATxDscrTab 0x30040060 0x140 {

 *(.TxDecripSection)

 }

 RW_Rx_Buffb 0x30040200 0x1800 {

 *(.RxArraySection)

 }

}

The startup file defines the following:

// startup_xx.asm

Stack_Size      EQU    0x8000 (32,768 -> 32k)

Heap_Size     EQU    0x0F800 (63,488 -> 62k)

As per the RM;

RAM

------------------------------------------

0x20000000 - 0x2001FFFF      DTCM-RAM         <-- Stack & Heap is here (Size: 0x1ffff = 131071, 128kB)

0x20020000 - 0x23FFFFFF      Reserved

0x24000000 - 0x2407FFFF      AXI SRAM         <-- Current IRAM2: (Size: 0x7ffff, 524287, 511kB)

0x24080000 - 0x2FFFFFFF      Reserved

0x30000000 - 0x3001FFFF      SRAM1            <-- (Size: 0x1ffff, 131,071, 128kB)

0x30020000 - 0x3003FFFF      SRAM2            <-- (Size: 0x1ffff, 131,071, 128kB)

0x30040000 - 0x30047FFF      SRAM3            <-- Current Rx/Tx Descriptors, Rx buffers (Size: 32767, 128kB)

0x30048000 - 0x37FFFFFF      Reserved

0x38000000 - 0x3800FFFF      SRAM4            <-- (Size: 0xffff, 65535, 64kB)

0x38010000 - 0x387FFFFF      Reserved

0x38800000 - 0x38800FFF      Backup SRAM      <-- NVRAM (Size: 0xfff, 4095, 4kB)

0x38801000 - 0x3FFFFFFF      Reserved

As per the RM, the stack and heap are located @0x20000000 (IRAM1), Size=128k

According to my scatter file:

IRAM2 (0x24000000) is used

So, does that really mean that the Stack and heap are now in IRAM2, Size=511k ?

Can someone clarify ?

Thanks,

Manu

This topic has been closed for replies.

4 replies

TDK
August 23, 2020

Look in your startup script to find out what gets loaded into the SP register. That's where the end of your stack is.

"If you feel a post has answered your question, please click ""Accept as Solution""."
Manu Abraham
Senior
August 23, 2020

The startup script is defined thus:

Stack_Size		EQU 0x8000
 
 AREA STACK, NOINIT, READWRITE, ALIGN=3
Stack_Mem SPACE Stack_Size
__initial_sp
 
 
; <h> Heap Configuration
; <o> Heap Size (in Bytes) <0x0-0xFFFFFFFF:8>
; </h>
 
Heap_Size EQU 0x0F800
 
 AREA HEAP, NOINIT, READWRITE, ALIGN=3
__heap_base
Heap_Mem SPACE Heap_Size
__heap_limit
 
 PRESERVE8
 THUMB
 
 
; Vector Table Mapped to Address 0 at Reset
..
..
..
; end of vector tables
 
 B .
 
 ENDP
 
 ALIGN
 
;*******************************************************************************
; User Stack and Heap initialization
;*******************************************************************************
 IF :DEF:__MICROLIB
 
 EXPORT __initial_sp
 EXPORT __heap_base
 EXPORT __heap_limit
 
 ELSE
 
 IMPORT __use_two_region_memory
 EXPORT __user_initial_stackheap
 
__user_initial_stackheap
 
 LDR R0, = Heap_Mem
 LDR R1, =(Stack_Mem + Stack_Size)
 LDR R2, = (Heap_Mem + Heap_Size)
 LDR R3, = Stack_Mem
 BX LR
 
 ALIGN
 
 ENDIF
 
 END
 
 
 
 
 
 

You meant:

                EXPORT __initial_sp

                EXPORT __heap_base

                EXPORT __heap_limit

Those ?

From there, how do I know, whether it is located at 0x20000000 or at 0x24000000 ?

Thanks,

Manu

Pavel A.
August 23, 2020
  1. Read your map file
  2. Stop in debugger in your main() and look at the registers. Especially at MSP ;)