Skip to main content
Explorer
January 2, 2025
Question

System gets stuck in hardfault handler after sending few chunks with LWIP using FreeRTOS

  • January 2, 2025
  • 2 replies
  • 1381 views

HELLO, 
I’m facing a hard fault when transmitting large data (60,018 bytes) via LwIP TCP/IP on STM32H723 with FreeRTOS. After increasing buffers and adjusting lwipopts.h, only 4000-5000 bytes transmit successfully. Remaining data causes crashes, likely due to memory exhaustion, stack overflow, or incorrect buffer handling. Need help resolving this.

HARD FAULT STACK-
"cam_bsnet Debug [STM32 C/C++ Application]
cam_bsnet.elf [cores: 0]
Thread #1 [main] 1 [core: 0] (Suspended : Signal : SIGTRAP:Trace/breakpoint trap)
HardFault_Handler() at stm32h7xx_it.c:113 0x8002070
<signal handler called>() at 0xfffffffd
ethernet_input() at ethernet.c:113 0x8023328
tcpip_thread_handle_msg() at tcpip.c:174 0x801714e
tcpip_thread() at tcpip.c:148 0x8017102
pxPortInitialiseStack() at port.c:214 0x8012ab0
arm-none-eabi-gdb (13.2.90.20230627)
ST-LINK (ST-LINK GDB server)"

THANKS IN ADVANCE

    This topic has been closed for replies.

    2 replies

    Super User
    January 2, 2025

    Probably overflowing the stack, or heap and stack are colliding. Look at the line that triggers failure (ethernet.c:113) and see where the buffer is being stored and verify it's not overwriting anything.

    ArushAuthor
    Explorer
    January 3, 2025

    thanks, I did the changes suggested by you, now i am able to transmit the complete data but sometimes system gets stuck in Hard Fault Handler during start, i think there is some issue in "pxPortInitialiseStack() at port.c:214 0x8011334"-
    Hard Fault Stack-

    cam_bsnet Debug [STM32 C/C++ Application]
    cam_bsnet.elf [cores: 0]
    Thread #1 [main] 1 [core: 0] (Suspended : Signal : SIGTRAP:Trace/breakpoint trap)
    HardFault_Handler() at stm32h7xx_it.c:112 0x8001e2c
    <signal handler called>() at 0xfffffffd
    ethernet_input() at ethernet.c:113 0x8021bb4
    tcpip_thread_handle_msg() at tcpip.c:174 0x80159d6
    tcpip_thread() at tcpip.c:148 0x801598a
    pxPortInitialiseStack() at port.c:214 0x8011334
    arm-none-eabi-gdb (13.2.90.20230627)
    ST-LINK (ST-LINK GDB server)
    Need help resolving this.
    ST Employee
    February 17, 2025

    Hello @Arush ,

    it seems that you are lacking proper buffer management, so you are running out of stack.

    this is worth mentioning about LwIP memory management:

    • LwIP provides a flexible way to manage memory pool sizes and organization.
    • It reserves a fixed-size static memory area in the data segment. It is subdivided into the various pools that lwIP uses for the various data structures. As an example, there is a pool for struct tcp_pcb, and another pool for struct udp_pcb. Each pool can be configured to hold a fixed number of data structures. This number can be changed in the lwipopts.h file. For example, MEMP_NUM_TCP_PCB and MEMP_NUM_UDP_PCB define the maximum number of tcp_pcb and udb_pcb structures that can be active in the system at a given time.
    • The user options can be changed in lwipopts.h

    Regards