cancel
Showing results for 
Search instead for 
Did you mean: 

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

wsrrasel
Associate

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

1 REPLY 1
STea
ST Employee

 

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

 

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.