Question
STM32H563 - LWIP memory corruption - Linker configuration with Cube IDE for RAM utilization
Hi,
I'm using STM32H563 to develop an application that utilizes the MQTT and TCP connection with LwIP stack.
When running mqtt ping-pong application for testing, I got memory corruption in lwip stack (mem.c).
Further debug I found that, with the default code generated by CubeIDE
in lwipopts.h
#define LWIP_RAM_HEAP_POINTER 0x20044000
the lwip heap start at 0x20044000
In the linker that is used by default: STM32H563RGTX_FLASH.ld, the lwIP sections was declared as:
.lwip_sec (NOLOAD) : {
. = ABSOLUTE(0x20040000);
*(.RxDecripSection)
. = ABSOLUTE(0x20040060);
*(.TxDecripSection)
. = ABSOLUTE(0x20040200);
*(.RxArraySection)
} >RAM2
. = ABSOLUTE(0x20040000);
*(.RxDecripSection)
. = ABSOLUTE(0x20040060);
*(.TxDecripSection)
. = ABSOLUTE(0x20040200);
*(.RxArraySection)
} >RAM2
But when building the project, in the map file I found that.
*(.RxArraySection)
.RxArraySection
0x20040200 0x4983 ./LWIP/Target/ethernetif.o
0x20040200 memp_memory_RX_POOL_base
.RxArraySection
0x20040200 0x4983 ./LWIP/Target/ethernetif.o
0x20040200 memp_memory_RX_POOL_base
so that the memp_memory_RX_POOL_base ranges from 0x20040200 to 0x20044B83 which overlaps with the LwIP heap and caused the corruption.
Increase the LWIP_RAM_HEAP_POINTER to 0x20050000 then the application works fine.
I think you should fix this issue when the IDE generated the code.
Besides, In default linker, the RAM was defined as:
RAM2 (xrw) : ORIGIN = 0x20040000, LENGTH = 64K
RAM (xrw) : ORIGIN = 0x20050000, LENGTH = 320K
RAM (xrw) : ORIGIN = 0x20050000, LENGTH = 320K
which means 256K of RAM1 on the MCU (form 0x20000000 to 2003FFFF) was not used for the application.
Can you help to advise if there is a special reason that RAM1 is not used. I think it's a big waste since 256K RAM for embedded application is considered big.
