cancel
Showing results for 
Search instead for 
Did you mean: 

STM32H743 Stack and Heap

Manu Abraham
Senior

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

4 REPLIES 4
TDK
Guru

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".

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

  1. Read your map file
  2. Stop in debugger in your main() and look at the registers. Especially at MSP ;)

Reading the map file...

Execution Region RW_IRAM2 (Exec base: 0x24000000, Load base: 0x08047920, Size: 0x00026358, Max: 0x00080000, ABSOLUTE, COMPRESSED[0x000000b4])

  Execution Region RW_DMARxDscrTab (Exec base: 0x30040000, Load base: 0x080479d4, Size: 0x00000060, Max: 0x00000060, ABSOLUTE)

   Exec Addr   Load Addr   Size        Type  Attr     Idx   E Section Name       Object

   0x30040000  0x080479d4  0x00000060  Data  RW         833   .RxDecripSection   ethernetif.o

   Execution Region RW_DMATxDscrTab (Exec base: 0x30040060, Load base: 0x08047a34, Size: 0x00000060, Max: 0x00000140, ABSOLUTE)

   Exec Addr   Load Addr   Size        Type  Attr     Idx   E Section Name       Object

   0x30040060  0x08047a34  0x00000060  Data  RW         834   .TxDecripSection   ethernetif.o

   Execution Region RW_Rx_Buffb (Exec base: 0x30040200, Load base: 0x08047a94, Size: 0x00001800, Max: 0x00001800, ABSOLUTE, COMPRESSED[0x00000034])

   Exec Addr   Load Addr   Size        Type  Attr     Idx   E Section Name       Object

   0x30040200  COMPRESSED  0x00001800  Data  RW         832   .RxArraySection    ethernetif.o

It does match the given scatter file.

So:

Current Size: 152kb

but:

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

Heap + Stack = 512kB

512k should be quite enough ..

Somehow, FreeRTOs + LWIP + altcp + mbedTLS cribs about out of memory like a stack overflow, very weird.

crash is around tcp_connect() return, which looked quite weird. FreeRTOS hooks show a happy stack though.

Argh!