2024-03-28 07:53 AM
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
2024-04-08 02:53 AM
Hi ChauNguyen
Is it possible for you to share the code. I am having difficulty in implementing MQTT on the H563.
2024-05-04 09:46 PM
Hi @SDu T
I check with my colleague and found that the memory allocation was due to his modification.
For lwIP to work in H563, you will need to have a ethernetif.c file that provide ethernet low_level_init, low_level_input ... etc. ST already provide the implementation.
You may need to have the new PHY driver depends on which ethernet PHY that you are using.
From the memory point of view:
The lwIP will need a free memory space in RAM that is not accessible from other module.
The address of the memory space is defined in lwipopts.h with macro LWIP_RAM_HEAP_POINTER. The size of this memory defined by MEM_SIZE in the same file.
So you should configured your linker to spare a memory space in RAM from LWIP_RAM_HEAP_POINTER to (LWIP_RAM_HEAP_POINTER + MEM_SIZE)>
Besides, there is 3 memory regions used by ethernetif.c
and
.lwip_sec (NOLOAD) : {
. = ABSOLUTE(0x20000000);
*(.RxDecripSection)
. = ABSOLUTE(0x20000060);
*(.TxDecripSection)
. = ABSOLUTE(0x20000200);
*(.RxArraySection)
} >RAM2 // this is the section for ethernetif memory.
Then from the output map file, I can see the RxArraySection size is 0x4983.
So that the free memory for lwIP stack should be from 0x20004B84 to end of RAM2 (in this case: 0x20010000)