Wiznet / ioLibrary_Driver

ioLibrary_Driver can be used for the application design of WIZnet TCP/IP chips as W5500, W5300, W5200, W5100 W5100S.
MIT License
603 stars 331 forks source link

socket.c infinite loop #94

Open Tomsiik opened 4 years ago

Tomsiik commented 4 years ago

In functions socket() and close() is an infinite loop for checking Sn_CR register when W5100 not responds or it not connected to MCU.

_while( getSnCR(sn) );

I solved it by adding a check of repeat attempts.

_uint8_t repeat = 0; do { if (repeat > 10) { return SOCKERR_TIMEOUT; } repeat++; } while (getSnCR(sn));

zhigangbox commented 4 years ago

这里确实是个问题,RT-THread的wiz软件包基于V1.0.3版本,新建的socke(前端无路由器,直接接在交换机上)居然不是closed状态而是0x22,造成直接-1返回造成一直无法通讯。大家有这个问题可以讨论QQ2730122869

hp-beko commented 4 years ago

Hi everybody,

@Tomsiik is right. infinite loop is a no go in bare metal programming. @zhigangbox Could you please write in englisch?

Best regards Hannes

ApmTIMEmqA commented 3 years ago

I actually stuck in infinite loop in W5300 with 28335, and solved it by modifying the following:

https://github.com/Wiznet/ioLibrary_Driver/blob/master/Ethernet/W5300/w5300.h#L1925

#define getSn_CR(sn) \
   ((uint8_t)WIZCHIP_READ(Sn_CR(sn)) & 0xFF)

I think it occurred because 28335 does not have a 1byte data type. (getSn_CR() returned 0x0100 before modification.)

If it's the same cause, try fixing it like this

https://github.com/Wiznet/ioLibrary_Driver/blob/master/Ethernet/W5100/w5100.h#L1431

#define getSn_SR(sn) \
        WIZCHIP_READ(Sn_SR(sn) & 0xFF)