WIZnet Developer Forum

Connect() does not return TIMEOUT error

Hello,
it’s been reproduced quite many times that connect() function does not return SOCKERR_TIMEOUT error even though it should do it.
the func is stuck in the section of:

while(getSn_SR(sn) != SOCK_ESTABLISHED) { if (getSn_IR(sn) & Sn_IR_TIMEOUT) { setSn_IR(sn, Sn_IR_TIMEOUT); #if _WIZCHIP_ == 5200 // for W5200 ARP errata setSUBR((uint8_t*)"\x00\x00\x00\x00"); #endif return SOCKERR_TIMEOUT; } }

I see that the w5500 returns socket disconnected.

Of course timeout is configured to w5500 (I read it directly from its register).
The SPI bus works well.

Can you help me to solve this issue?

Thanks,
avivf

Hi~ avivf

This is valid only in TCP mode and operates when Socket n acts as ‘TCP client’.
And the connect-request fails in the following three cases.

Is it timeout error?

Thanks,
EK :slight_smile:

Hello,
thanks for reply.

Well, as I said the problem is that the connect procedure fails, as socket did not get to SOCK_ESTABLISHED state.
I expect the w5500 to return timeout error upon checking the proper register getSn_IR(sn) & Sn_IR_TIMEOUT
For some reason w5500 does not identify that timeout has passed, though the timeout register is set to 15000 (the timeout value is read from the w5500 using ctlnetwork(CN_GET_TIMEOUT,...)
As NO timeout occurred - the loop is endless.

Can you figure out why w5500 does not get into timeout?

Thanks,
Aviv

Hi…

I think you set a lot of timeout value.

Please add the code and test again.
function declaration in main.c

wiz_NetTimeout gWIZNETTIME = {.retry_cnt = 3,         //RCR = 3
                               .time_100us = 2000};     //RTR = 2000

You have to insert this code before TCP client test function execute.

ctlnetwork(CN_SET_TIMEOUT,(void*)&gWIZNETTIME);
ctlnetwork(CN_GET_TIMEOUT, (void*)&gWIZNETTIME);

And do you send your test code ?

thanks,
EK :slight_smile:

Hi EK,
I’ve set the RTR and RCR as you suggested, but it didn’t help.

I will describe the problem once again:

  1. my socket is configured as TCP (uses as a client)
  2. connection with the server succeeded
  3. server sent a disconnection msg
  4. client (w5500 socket) tries to re-connect to server - using connect() func, of course
  5. getSn_IR(sn) returns “0x2” ( = Sn_IR_DISCON) for ever
  6. no time is generated by the w5500
  7. connect() func is stuck in endless loop, as NO timeout is received by getSn_IR(sn):

while(getSn_SR(sn) != SOCK_ESTABLISHED) { if (getSn_IR(sn) & Sn_IR_TIMEOUT) { setSn_IR(sn, Sn_IR_TIMEOUT); #if _WIZCHIP_ == 5200 // for W5200 ARP errata setSUBR((uint8_t*)"\x00\x00\x00\x00"); #endif return SOCKERR_TIMEOUT; } }
Can you pleae help?

Thanks

Hi~ avivf
I tested our driver.I’m having a bit of trouble with our driver and I modified connect() function in socket.c
The conditional statement added a end conditions(if(getSn_SR(sn) == SOCK_CLOSED)).
It have to confirm the Sn_SR value if SOCK_CLOSED or not.

while(getSn_SR(sn) != SOCK_ESTABLISHED)
   {   
      if (getSn_IR(sn) & Sn_IR_TIMEOUT)
      {
         setSn_IR(sn, Sn_IR_TIMEOUT);
         #if _WIZCHIP_ == 5200   // for W5200 ARP errata 
            setSUBR((uint8_t*)"\x00\x00\x00\x00");
         #endif
         return SOCKERR_TIMEOUT;
      }
+ 	if (getSn_SR(sn) == SOCK_CLOSED)
+       {
+	     return SOCKERR_SOCKCLOSED;
+        }
   }

I updated the driver. Please visit the GitHub for more information.
https://github.com/Wiznet/ioLibrary_Driver/commit/0ada86b800b7c24dc36055388297cf29826c6e46

Thanks.

the fix is correct, though it still misses the case where the socket is disconnected (and not closed).
This is actually the case I was encountered.

I fixed the bug by the following code (which I think needs to be merged with your fix):

while(getSn_SR(sn) != SOCK_ESTABLISHED) { /** * Upon server sending a disconnection msg - getSn_IR(sn) returns "0x2" ( = Sn_IR_DISCON) for ever, * and no time is generated by the w5500. * This leads connect() func to be stuck in endless loop, as NO timeout is received by getSn_IR(sn). * * The fix is adding a Sn_IR_DISCON condition, in order to exit loop. */ if (getSn_IR(sn) & Sn_IR_TIMEOUT) { setSn_IR(sn, Sn_IR_TIMEOUT); #if _WIZCHIP_ == 5200 // for W5200 ARP errata setSUBR((uint8_t*)"\x00\x00\x00\x00"); #endif return SOCKERR_TIMEOUT; } else if (getSn_IR(sn) & Sn_IR_DISCON) { setSn_IR(sn, Sn_IR_DISCON); return (SOCKERR_SOCKSTATUS); } }

Hey,

I had the same issue with the TCP-Client. I tried the solution from avivf and it worked like a charm.

thank you for the help.

Copyright © 2017 WIZnet Co., Ltd. All Rights Reserved.