2025-08-29 4:04 AM
Hi,
I have a lwIP implementation running on an STM32H723 using a CubeMX HAL implementation, so no OS-like stuff involved. In case of heavy outgoing traffic, it seems it is running low on memory at some point. This is not dramatic as tcp_write() knows an error-code ERR_MEM which would give the possibility to deal with that situation.
Unfortunately it seems this error code is not used here. Instead of that, the system dies and ends up in HardFault_Handler() via following stacktrace:
HardFault_Handler() at stm32h7xx_it.c:85 0x8002f04
<signal handler called>() at 0xffffffe9
mem_malloc() at mem.c:934 0x800d7fe
pbuf_alloc() at pbuf.c:284 0x800e348
tcp_pbuf_prealloc() at tcp_out.c:263 0x801299a
tcp_write() at tcp_out.c:610 0x8012e48
So...how can I change that? What do I have to do to let tcp_write() return with a proper error code instead of letting the whole system crash?
Thanks!
2025-08-29 4:08 AM
On debugging Hard faults:
2025-08-29 4:19 AM
There are several #define settings for the TCP queue / window, which should be smaller than the memory which is used.
Have you already checked these?
I had to modify tcp_write to edit a new pbuf variable, it's tedious the way it is programmed, but possible...
2025-08-29 4:57 AM
I'm currently running with the lwIP-defaults that are given in CubeMX (except for what is described in https://community.st.com/t5/stm32-mcus/how-to-create-a-project-for-stm32h7-with-ethernet-and-lwip-stack/ta-p/49308#memory-layout ). Aren't these defaults usable?
2025-08-29 6:18 AM
Never trust Cube defaults... :D