Skip to main content
yuri CH
Senior
December 7, 2022
Question

LWIP server recovery after cable unplug/replug

  • December 7, 2022
  • 3 replies
  • 3542 views

Hello!

i am working with the STM32H747, i have a cubeMX generated project which uses LWIP for ETH connection and managment.

I've encountered an issue - i have a LWIP tcp server, which connect clients and runs properly. when i disconnect the ethernet cable with out disconnecting rom client first i am not able to recover connection after the cable is reconnected. the only thing that works is restating and this is not an option.

Please advise on possible ways to resolve this issue :)

thanks

This topic has been closed for replies.

3 replies

LCE
Principal II
December 7, 2022

There should be a function called something like "Ethernet_Link_Periodic_Handle", where the PHY link status is checked on a regular basis.

There you can re-initialize the netif and lwip stuff if link is down.

I think the Cube version doesn't work, that is something I yet have to take care of, so I can't help you anymore.

But there should be a thread somewhere, maybe start here:

https://community.st.com/s/question/0D50X0000BOtfhnSQB/how-to-make-ethernet-and-lwip-working-on-stm32

Pavel A.
Super User
December 8, 2022

Rather than relying on Cube generated stuff, check more recent ETH examples here: https://github.com/stm32-hotspot/STM32H7-LwIP-Examples

JongOk Baek
Associate III
December 8, 2022

Please check the version of HAL Library.

If you use v1.10.0, it included bug in link callback function.

​(it is possible to improve using updated HAL Library as v1.11.0)

You should ​enable for Link Callback in LwIP Key Options.

0693W00000WKUz2QAH.pngCheck the code of the ethernet_link_thread() function in the ethernetif.c file

  if(linkchanged)

  {

   /* Get MAC Config MAC */

   HAL_ETH_GetMACConfig(&heth, &MACConf);

   MACConf.DuplexMode = duplex;

   MACConf.Speed = speed;

   HAL_ETH_SetMACConfig(&heth, &MACConf);

   HAL_ETH_Start_IT(&heth);

   netif_set_up(netif);

   netif_set_link_up(netif);

  }

You need to change the initialization function to _IT() as shown below.

HAL_ETH_Start(&heth); -> HAL_ETH_Start_IT(&heth);

Best regards.