Skip to main content
Visitor II
November 28, 2024
Question

LwIP Assertion Failed: "mem_free: illegal memory: non-linked: double free"

  • November 28, 2024
  • 1 reply
  • 1388 views

Hi ST Community,

I am working on a project using the STM32H723 MCU and the KSZ8863 Ethernet switch. I initially encountered issues while using a modified TCP echo server example, but after reverting to the unmodified example, the same issue persists. Communication is functional, but the system eventually crashes with the following assertion:

Assertion "mem_free: illegal memory: non-linked: double free" failed at line 661 in ../Middlewares/Third_Party/LwIP/src/core/mem.c

System Details:

  1. MCU: STM32H723
  2. Switch: KSZ8863 (connected via RMII for Ethernet data and SPI for control)
  3. Middleware: LwIP (as provided in STM32Cube firmware package)
  4. Example Used: Modified tcpecho server example from LwIP.
  5. Peripheral Interface:
    • RMII for Ethernet data.
    • SPI for KSZ8863 switch configuration.
    • SMI is not used.

Observed Behavior:

  • The application works correctly for some time, and the TCP echo functionality responds as expected.
  • Under moderate network load or over time, the system crashes with the above assertion in LwIP’s mem_free function.

Here are the configurations:

Cortex M7:

cortexM7.png

 

Ethernet:

eth.png

 

LwIP:

lwip_1.png

 

lwip_2.png

 

lwip_3.png

 

Thanks in advance for any guidance!

Best regards,

Russel Mahmud

    This topic has been closed for replies.

    1 reply

    ST Employee
    January 15, 2025

     

    Hello @wsrrasel ,

    Your memory configuration is lacking and don't cover parts where LwIP heap and descriptors will be placed.

    You need to take care when allocating memory make sure you have the permission in MPU configuration for that address range and calculate the amount of allocated Heap according to the available memory on your case the SRAM.

    Also, you will need to handle the freeing of allocated memory when not used to make sure you don't run out of usable memory.
    you can have some references and documentations on LwIP which might help you:

    -How to create a project for STM32H7 with Ethernet ... - STMicroelectronics Community

    -https://github.com/stm32-hotspot/STM32H7-LwIP-Examples

    -Developing applications on STM32Cube with LwIP TCP/IP stack
    -STM32CubeH7/Projects/NUCLEO-H723ZG/Applications/LwIP at master · STMicroelectronics/STM32CubeH7 · GitHub


    Regards