K66 lwip disconnection bug

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

K66 lwip disconnection bug

2,267 Views
mpazzi
Contributor III

Hello,

I'm using MCUXpresso IDE 10.2 and SDK 2.4.1 with MK66FX1M0.

The problem is with ethernet cable, if I disconnect it and then reconnect it the comunication is not resumed any way until I reset the microntroller.

Is there any solutions to fix this bug ? ...possibly without change SDK 2.4.1 to SDK 2.6 and conseguently the IDE ...

Thank a lot for any suggestion and help.

Marco

Labels (1)
14 Replies

1,785 Views
FelipeGarcia
NXP Employee
NXP Employee

Hi Marco,

 

You could try to do something as follows to detect when the ethernet cable has been disconnected:

 

PHY_GetLinkStatus(ethernetif->base, BOARD_ENET0_PHY_ADDRESS, &link);
 
if(false == link)
{
    PRINTF("LINK DOWN\r\n");
    netif_set_down(netif);
}
else
{
    PRINTF("LINK UP\r\n");
    netif_set_up(netif);
}‍‍‍‍‍‍‍‍‍‍‍‍

 

Hope it helps!

 
Have a great day,
Felipe

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 Kudos

1,785 Views
mpazzi
Contributor III

Hello Felipe,

thanks for your replay.

But where do I insert the code you gives to me ?

down the main code for handle communication:

pastedImage_2.png

If the connection is established fine the cycle remain in the

pastedImage_4.png

 and if some data is coming goes through

pastedImage_5.png

if I close connection excute 

pastedImage_6.png

But if I disconnect the cable the code excuted

pastedImage_7.png

because no data will come.

If the cable is connected or if I disconnect it the running remain in this part:

pastedImage_8.png

called from this:

pastedImage_10.png

Thanks for your help.

Regards

0 Kudos

1,785 Views
FelipeGarcia
NXP Employee
NXP Employee

Hi Marco,

 

I am sorry for the late reply.

 

I used the tcp_echo_bm example from the SDK and added those lines in ethernetif.c file. Right before to read the frame.

pastedImage_4.png

I hope this is helpful.


Best regards,
Felipe

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

1,785 Views
mpazzi
Contributor III

Hi Felipe,

I've just tryed your solution, I'm using freeRTOS.

When the cable is connected I see "LINK UP", if I disconnect the cable no "LINK UP" or "LINK DOWN" appears, but when I re-connect the cable I see LINK DOWN and after LINK UP but the comunication is not working any more until the reset.

Any idea?

Thanks a lot for your support.

Marco

0 Kudos

1,785 Views
FelipeGarcia
NXP Employee
NXP Employee

Hi Marco,

 

Did you try the above with the example provided in the SDK? I recommend you to try it first in the example so you can then change to your application.

 

Best regards,

Felipe

0 Kudos

1,785 Views
mpazzi
Contributor III

Hi Felipe,

I have tryed with TWRK65 demo board and I see that with one PC (maybe windows XP) the disconnecting and reconnecting of cable work fine, if I try with one PC (windows 10) the disconnecting and reconnecting of cable do not work.

Not working I mean the cable is connected and I use echotool command and I disconnect and reconnect the cable while the server is responding, the process in PC goes in timeout and after I can't have communication anymore.

Looking in code " tcpecho_thread(void *arg) " -> netconn_recv_data(struct netconn *conn, void **new_buf) -> u32_t sys_arch_mbox_fetch( sys_mbox_t *pxMailBox, void **ppvBuffer, u32_t ulTimeOut ) the last function is called (by sys_timeouts_mbox_fetch(sys_mbox_t *mbox, void **msg) ) with ulTimeOut with zero value that means wait forever and never return for close connection.

pastedImage_1.png

I hope to be clear enough.

Best Regards

Marco

0 Kudos

1,785 Views
FelipeGarcia
NXP Employee
NXP Employee

Hi Marco,

 

I tried the tcpecho_bm example with TWR-K65F board on my side and did the following.

 

- Changed configIP_ADDR in the example code to my PC IP address.

- I sent the following command in echotool:

 

echotool IPADDRESS /p tcp /r 7 /d hello

 

And received:

Hostname IPADDRESS resolved as IPADDRESS

 

Reply from IPADDRESS:7, time 0 ms OK

Reply from IPADDRESS:7, time 0 ms OK

Reply from IPADDRESS:7, time 0 ms OK

Reply from IPADDRESS:7, time 0 ms OK

Reply from IPADDRESS:7, time 0 ms OK

 

Statistics: Received=5, Corrupted=0

Then I disconnected the cable and sent the command again and I received the following.

 

Host unreachable

 

Statistics: Received=0, Corrupted=0

Finally I reconnected the cable and sent the same command and received the same response as the beginning.

 

Hostname IPADDRESS resolved as IPADDRESS

 

Reply from IPADDRESS:7, time 0 ms OK

Reply from IPADDRESS:7, time 0 ms OK

Reply from IPADDRESS:7, time 0 ms OK

Reply from IPADDRESS:7, time 0 ms OK

Reply from IPADDRESS:7, time 0 ms OK

 

Statistics: Received=5, Corrupted=0

Could you please confirm you experience this behaviour on your side?

 

Best regards,

Felipe

0 Kudos

1,785 Views
mpazzi
Contributor III

Hi Felipe,

thanks for your reply.

On my board I use RTOS, so I used TWRK65 with RTOS example and I have problem if I disconnect the cable, specially with PC as windows 10. The ping command work correctly in any situation.

For resolve the issue I have modify as down:

pastedImage_1.png

pastedImage_2.png

So I have introduced a timeout of 5sec on static err_t
netconn_recv_data(struct netconn *conn, void **new_buf), if I do not have communication for more then 5 sec the netconn is closed.

What do think about this solution ?

Thanks

Marco

0 Kudos

1,785 Views
FelipeGarcia
NXP Employee
NXP Employee

Hi Marco,

 

That looks correct from my side.

 

Regards,

Felipe

1,785 Views
mpazzi
Contributor III

Hi Felipe,

thanks for precious help. I have one more question.

I have used the tcp-echo example to implement MODBUS over TCP protocol, and with the modified above I can connect to one PC or to another PC by disconecting cable or using an Hub.

But now I should handle 2 connection at the same time , so two PC should connected through a hub to my board.

How can I do this functionality ?

Thank for your support

Regards

Marco

0 Kudos

1,785 Views
FelipeGarcia
NXP Employee
NXP Employee

Hi Marco,

 

The LWIP stack supports multiple TCP connection but it will depend on the memory you have available.

 

In lwipopts.h file the macro MEMP_NUM_TCP_PCB defines the number of simultaneously active TCP.

 

To create a new connection you should use netconn_new as in tcpecho_thread.

 

Best regards,

Felipe

1,785 Views
mpazzi
Contributor III

Hi Felipe,

thanks a lot for your support.

The macro MEMP_NUM_TCP_PCB is defined at 10 connection, so is enough.

I'm not very experienced with TCP and to get a result in less time, do you have an example I can rely on?

Best Regards

Marco

0 Kudos

1,785 Views
FelipeGarcia
NXP Employee
NXP Employee

Hi Marco,

 

Unfortunately, we do not have such an example for that specific application.

 

Sorry for the inconvenience this may cause you.

 

Best regards,

Felipe

0 Kudos

1,785 Views
mpazzi
Contributor III

Hi Felipe,

thanks anyway.

Best regards

Marco

0 Kudos