Skip to content

W5500 problem #1500

@notro

Description

@notro

I'm using an Ethernet Shield for Arduino - W5500 Chipset with an Adafruit Grand Central M4 Express

However I'm getting an error. Yesterday it always failed when sending, today it fails when receiving:

Adafruit CircuitPython patchbase-dirty on 2019-01-27; Adafruit Grand Central M4 Express with samd51p20
>>>
>>>
>>> import board
>>> import busio
>>> import wiznet
>>> import socket
>>> import time
>>>
>>> spi = busio.SPI(clock=board.SCK, MOSI=board.MOSI, MISO=board.MISO)
>>> eth = wiznet.WIZNET5K(spi, board.D10, board.D11)
>>> eth.connected
True
>>> time.sleep(10)
>>> eth.ifconfig()
('192.168.10.135', '255.255.255.0', '192.168.10.1', '0.0.0.0')
>>>
>>> host = 'example.com'
>>>
>>> fam, typ, pro, nam, sockaddr = socket.getaddrinfo(host, 80)[0]
>>> ss = socket.socket(fam, typ, pro)
>>> sockaddr
('93.184.216.34', 80)
>>>
>>> ss.connect(sockaddr)
>>> ss.send(b"GET / HTTP/1.0\r\n\r\n")
18
>>> print(ss.recv(1024))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OSError: [Errno 5] Input/output error
>>>

It errors out in the CHECK_SOCKMODE macro:

int32_t WIZCHIP_EXPORT(recv)(uint8_t sn, uint8_t * buf, uint16_t len)
{
   uint8_t  tmp = 0;
   uint16_t recvsize = 0;
   CHECK_SOCKNUM();
   CHECK_SOCKMODE(Sn_MR_TCP);
   CHECK_SOCKDATA();

This is what I did to make it build:

diff --git a/ports/atmel-samd/Makefile b/ports/atmel-samd/Makefile
index 797369bd6..55de847c0 100644
--- a/ports/atmel-samd/Makefile
+++ b/ports/atmel-samd/Makefile
@@ -281,6 +281,8 @@ SRC_C = \
        freetouch/adafruit_ptc.c \
        supervisor/shared/memory.c

+MICROPY_PY_NETWORK=1
+MICROPY_PY_WIZNET5K=5500
 ifeq ($(MICROPY_PY_NETWORK),1)
 CFLAGS += -DMICROPY_PY_NETWORK=1

diff --git a/ports/atmel-samd/mpconfigport.h b/ports/atmel-samd/mpconfigport.h
index da3383f8e..79e48312c 100644
--- a/ports/atmel-samd/mpconfigport.h
+++ b/ports/atmel-samd/mpconfigport.h
@@ -64,11 +64,11 @@
 #define MICROPY_STREAMS_NON_BLOCK   (1)

 #ifndef MICROPY_PY_NETWORK
-#define MICROPY_PY_NETWORK          (0)
+#define MICROPY_PY_NETWORK          (1)
 #endif

 #ifndef MICROPY_PY_WIZNET5K
-#define MICROPY_PY_WIZNET5K         (0)
+#define MICROPY_PY_WIZNET5K         (5500)
 #endif

 #ifndef MICROPY_PY_CC3K
diff --git a/shared-bindings/network/__init__.c b/shared-bindings/network/__init__.c
index 69f8bea60..4839e0cf5 100644
--- a/shared-bindings/network/__init__.c
+++ b/shared-bindings/network/__init__.c
@@ -28,6 +28,7 @@
 #include <stdint.h>
 #include <string.h>

+#include "py/obj.h"
 #include "py/objlist.h"
 #include "py/runtime.h"
 #include "py/mphal.h"
diff --git a/shared-bindings/socket/__init__.c b/shared-bindings/socket/__init__.c
index 29d47de56..5ecfa8d4d 100644
--- a/shared-bindings/socket/__init__.c
+++ b/shared-bindings/socket/__init__.c
@@ -28,6 +28,7 @@
 #include <stdio.h>
 #include <string.h>

+#include "py/obj.h"
 #include "py/objtuple.h"
 #include "py/objlist.h"
 #include "py/runtime.h"
diff --git a/shared-bindings/wiznet/__init__.c b/shared-bindings/wiznet/__init__.c
index e230deecc..fb8470462 100644
--- a/shared-bindings/wiznet/__init__.c
+++ b/shared-bindings/wiznet/__init__.c
@@ -28,6 +28,7 @@
 #include <stdint.h>
 #include <string.h>

+#include "py/obj.h"
 #include "py/objlist.h"
 #include "py/objproperty.h"
 #include "py/runtime.h"
diff --git a/shared-bindings/wiznet/wiznet5k.c b/shared-bindings/wiznet/wiznet5k.c
index 6d43e8992..288a19691 100644
--- a/shared-bindings/wiznet/wiznet5k.c
+++ b/shared-bindings/wiznet/wiznet5k.c
@@ -28,6 +28,7 @@
 #include <stdint.h>
 #include <string.h>

+#include "py/obj.h"
 #include "py/objlist.h"
 #include "py/objproperty.h"
 #include "py/runtime.h"

cc: @nickzoic

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions