FreeRTOS+TCP will not reply ping after unplug/plug eth cable when sending data

I test the FreeRTOS+TCP, sending data from FreeRTOS to PC, FreeRTOS is the server side, minor change from example “SimpleTCPEchoServer.c”, see attachment. PC side can receive data well. but have problem when I do below experiment: 1) run pc side program to receive data, data can receive smoothly; and run ping FreeRTOS in cycle 2) unplug eth cable 3) wait until timeout(5 sec) 4) plug in the eth cable, FreeRTOS will never reply ping any more. In step3, if not wait timeout, quickly plug in the cable, ping will be replied. Where should I check for this problem? Thanks for any help! test environment: 1) xilinx zynq zybo board 2) 160919FreeRTOSLabs 3) some minor change from 160919FreeRTOSLabs: a) disable DHCP, using static ip b) call “vStartSimple2TCPServerTasks( mainTCPSERVERSTACKSIZE, tskIDLEPRIORITY+2 );” before vTaskStartScheduler in main() c) EchoServer port set to 1000 in SimpleTCPEchoServer.c d) not receive data, just sending data in SimpleTCPEchoServer.c

FreeRTOS+TCP will not reply ping after unplug/plug eth cable when sending data

Hi Guoxing Zhang,
In step3, if not wait timeout, quickly plug in the cable, ping will be replied. Where should I check for this problem?
I can reproduce this, thanks. I’m working on it and I will post a solution today.

FreeRTOS+TCP will not reply ping after unplug/plug eth cable when sending data

Hi Guoxing Zhang, There is one thing to realise while testing: when you run ping constantly while disconnecting your device, your OS may start forwarding the ping ICMP packets through a different ( gateway ) interface. You may see this happing by running WireShark. And also like this: ~~~ Reply from 192.168.2.106: bytes=32 time<1ms TTL=128 Reply from 192.168.2.106: bytes=32 time<1ms TTL=128 Request timed out. Reply from 192.168.2.5: Destination host unreachable. Request timed out. Request timed out. Request timed out. Request timed out. Reply from 192.168.2.1: Destination host unreachable. ~~~ Here above, there is a shift from x.x.x.5 to x.x.x.1. If that happens, you may want to try the following: ● Try a few pings ● Stop pinging and disconnect the device ● Wait 20 seconds and connect the device ● Wait a while and try ping again Sometimes, when packets are forwarded to the wrong interface, it may help to clear the ARP cache. The driver for Zynq/Zybo has changed a bit through time. I will attach the latest ( not-yet well-tested ) version ( see Zynq_Zybo_driver.zip, here below ). Please have a try with it. I tested the demo application as follows: ● Disconnect device ● Start it up ● Wait 15 secs ● Connect it to the LAN ● See it working And also I did your test: ● Start it up while connected ● See it working ● Disconnect it from the LAN ● Wait 15 secs ● Re-connect it ● See it working These tests worked fine here. What is new in this version: when the device notices a rise of the Link Status, a new Auto Negotiation will be started. Regards.

FreeRTOS+TCP will not reply ping after unplug/plug eth cable when sending data

Hi Hein Tibosch, Thanks for your help! For your recommendation(try few pings, wait long time to ping), I have tried, but none can recover. I tried your updated driver, no success too. In your steps, do you have run socket receiving at PC(win7) side? There is 2 important conditions for this phenomenon: 1) unplug the cable when PC(win7) receiving data by socket. If not run receiving program in PC side, just unplug/plug cable, ping is OK. 2) after unplug cable, need to wait some time, several seconds, I guess this time related with FREERTOSSOSNDTIMEO, after timeout, socket task in freeRTOS will be deleted. if quickly unplug/plug cable, ping will come back. I captured the data by wireshark, see attachment. I know little about TCP stack, maybe you can help to check it. Here I also attach the socket receiving program in PC side, I compiled with VC. I do this test, because I want data receiving recover after cable plug in, to emulate the condition cable not stable. Best Regards Guoxing

FreeRTOS+TCP will not reply ping after unplug/plug eth cable when sending data

HI Guoxing, thanks for the PCAP. Are you connecting your embedded device to a switch or router, or directly to your laptop? If possible, use a LAN switch. When that works you can try other connection types. I did not use the TCP connection during my tests, but today I will! Both modules euadRecv.c and SimpleTCPEServer.c compiled well and run without a problem ( although the free() statement is erroneous, pBuf points to a static char buffer ). Your VC application does not notice the disconnection. I changed it to call select() before calling recv(). If select() returns negative, the connection has gone. But you may also notice that select() returns a positive value, while recv() returns zero. This is a sign that OOB ( out-of-band ) data has been received, most possibly an FD_CLOSE event, which means: connection closed. I just tested with the adapted VC application ( attached as tcp_client.cpp ), and saw that the disconnection was noticed quite quickly after disconnecting: ~~~ Received 41 MB Received 41 MB Received 42 MB // still connected select returns -1 BufLen receive error recv failed (10022) // WSAEINVAL uCntRevTemp = (-1) ~~~ Under all circumstances, the ping worked fine as long as the device was connected.

FreeRTOS+TCP will not reply ping after unplug/plug eth cable when sending data

PS. when testing, please use the driver in SimpleTCPEServer.c that I posted here above. It has some minor changes in the PHY handling.

FreeRTOS+TCP will not reply ping after unplug/plug eth cable when sending data

Sorry, I mean the driver in ZynqZybodriver.zip and not SimpleTCPEServer.c

FreeRTOS+TCP will not reply ping after unplug/plug eth cable when sending data

Hi Hein, Really appreciate for your help! After using a switch, no problem seen. The previous tests I have done does not use any switch or router, PC connected to ZYBO directly, not the crossed cable. So may I think this problem related with this directly connection? I think this is not a major problem, I am OK for freeRTOS+TCP with a switch. And thanks for your modified tcp_client.cpp. I have never use the select before, I will learn it. Thanks! BR Guoxing

FreeRTOS+TCP will not reply ping after unplug/plug eth cable when sending data

Hi Hein, In today’s test, I disconnect the connection between pc and switch. I am afraid, the sesult will fail if disconnect freeRTOS and switch. I will test this tommorrow. Thanks!

FreeRTOS+TCP will not reply ping after unplug/plug eth cable when sending data

Hi Hein, Sorry for my pervious statement. I just disconnect the connection between freeRTOS and switch. It has no problem too. Thanks for your help! BR Guoxing

FreeRTOS+TCP will not reply ping after unplug/plug eth cable when sending data

PC connected to ZYBO directly, not the crossed cable
Crossed versus straight: that should not be a problem. Most PHY’s can negotiate about that and find a way to communicate. But what is a problem is that when you unplug the device, the Network Interface on your laptop goes down. When the laptop is connected to a switch or router, the Network Interface is up all the time because it is connected constantly. So for testing, please disconnect and reconnect your device from the switch, and not your laptop. When that all works well ( like it does here ), I don’t mind checking the laptop-to-device connection.

FreeRTOS+TCP will not reply ping after unplug/plug eth cable when sending data

Hi Hein,
So for testing, please disconnect and reconnect your device from the switch, and not your laptop.
Yes, this test( disconnect and reconnect your device from the switch) have done, it’s OK. Thanks!