cancel
Showing results for 
Search instead for 
Did you mean: 

lwIP on STM32H7: tcp_write() causes exception / HardFault_Handler() when it is low of memory

HMüll.4
Senior

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!

 

4 REPLIES 4
Andrew Neil
Super User

On debugging Hard faults:

https://community.st.com/t5/community-guidelines/how-to-write-your-question-to-maximize-your-chances-to-find-a/tac-p/708193/highlight/true#M51

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.
LCE
Principal II

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

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?

LCE
Principal II

Never trust Cube defaults... :D