2025-09-01 3:29 AM
I'm running the CubeMX-generated lwIP implementation on an STM32H723. Memory addresses and configuration has been modified according to what is described at https://community.st.com/t5/stm32-mcus/how-to-create-a-project-for-stm32h7-with-ethernet-and-lwip-stack/ta-p/49308
Now when running this implementation, I stumble upon different illegal memory accesses where data is located in memory areas outside of the addresses of range 0x30000200 .. 0x30000200+32232.
This happens more or less randomly. When I add some own address-checks at one position in code to ensure a pointer is in that area, lwIP crashes at an other position. So this looks like some memory leak or some other fundamental problem.
Next I enabled MEMP_SANITY_CHECK in lwIP settings to track down these problems. With that, immediately on connection of an external client to my server, I end up in a failed MEMP-sanity check:
HardFault_Handler() at stm32h7xx_it.c:85 0x8002f10
<signal handler called>() at 0xffffffe9
memp_sanity() at memp.c:108 0x800d920
do_memp_free_pool() at memp.c:389 0x800dafa
memp_free_pool() at memp.c:410 0x800db5a
pbuf_free_custom() at ethernetif.c:446 0x800cb18
pbuf_free() at pbuf.c:768 0x800e8cc
tcp_input() at tcp_in.c:382 0x80106a8
ip4_input() at ip4.c:709 0x8017756
ethernet_input() at ethernet.c:186 0x8018a66
ethernetif_input() at ethernetif.c:351 0x800ca8c
MX_LWIP_Process() at lwip.c:144 0x800c786
So for me this looks like some problem with the lwIP-implementation provided by ST or with the configuration.
Any ideas how I fix or at least track down this issue?
Thanks!
Solved! Go to Solution.
2025-09-05 8:07 AM
After reviewing the project with @HMüll.4, it was confirmed that the memory corruption was caused by using 12 Rx buffers while MEM_SIZE in lwipopts.h was set for only 10 buffers (15,360 bytes). This mismatch exceeded the allocated 16 KB memory and led to the issue.