8000 rp2: Add Wiznet W5100S-EVB-Pico board. by andrewleech · Pull Request #8540 · micropython/micropython · GitHub
[go: up one dir, main page]

Skip to content

rp2: Add Wiznet W5100S-EVB-Pico board. #8540

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 13 commits into from

Conversation

andrewleech
Copy link
Contributor
@andrewleech andrewleech commented Apr 13, 2022

This PR builds on and extends the prior work done in #8021 to provide the Wiznet Ethernet driver on Raspberry Pi Pico port, cleaning this up and pre-configuring it on the board for W5100S_EVB_PICO.

This board config should also work on the regular Pico with the Wiznet RP2040-HAT-C module attached, I believe the same pinouts are used.

Build

cd ports/rp2
make submodules
make clean BOARD=W5100S_EVB_PICO
make BOARD=W5100S_EVB_PICO

Flash the normal way for rpi pico as per https://github.com/micropython/micropython/blob/master/ports/rp2/README.md

Usage

The HW configuration for W5100S_EVB_PICO has been pre-configured, so to enable the network access you can simply do something like:

>>> import network
>>> nic = network.WIZNET5K()
>>> nic.active(True)
>>> nic.ifconfig("dhcp")
>>> print(nic.ifconfig())
('192.168.0.18', '255.255.255.0', '192.168.0.1', '8.8.8.8')

This was done with the board network interface connected to a local router supplying DHCP.

The pinouts can alternatively be configured at runtime:

import network
from machine import Pin, SPI
spi = SPI(0, 2_000_000, mosi=Pin(19), miso=Pin(16), sck=Pin(18))
nic = network.WIZNET5K(spi, Pin(17), Pin(20))
nic.active(True)
nic.ifconfig("dhcp")

The older Wiznet drivers in micropython/drivers have been left untouched for now. Changes added to them in the micropython repo since they were first brough in have been rebased/refactored into a new MR on the (now available) official driver repository: Wiznet/ioLibrary_Driver#120

The exported function name fix commit in this in particular is essential to allow usage of the upstream driver here in micropython.
The branch in the wiznet driver repo PR has been brought in here as a submodule in the micropython/lib folder for use with this PR.

In #8021, @irinakim12 ported stm32/modnwwiznet5k.c into rp2/modnwwiznet5k.c, updating it to use machine.pin and machine.spi interfaces rather than the original stm32 HAL interfaces. I've now taken this further, migrating modnwwiznet5k.c to extmod with appropriate updates to use global definitions where possible.

Further updates to rp2/modnwwiznet5k.c made in https://github.com/Wiznet/RP2040-HAT-MicroPython have also been selectively merged in, particularly the dhcp support. I've renamed network.WIZNET5K().active() function to network.WIZNET5K().dhcp() however to better reflect its functionality.

I've also ported the network_wiznet5k.c driver from stm to extmod/rp2 and brought LwIP support into rp2. This driver is now the default one as it has broader compatibility with other network features, and includes things such as a user api for mac address. For more details see https://docs.micropython.org/en/latest/library/network.html

The updates made here to use the extmod machine interfaces to SPI & allow defining the default wizmac pintouts in the board config have also been ported into network_wiznet5k.c.

This extmod version includes a default MAC address generated in the "random" address space, but statically defined by the individual chip unique ID.

These updated extmod interfaces should work on the stm32 port with little effort. I'd like to migrate the stm32 usage of wiznet drivers over to this new lib & extmod interface in a follow up PR, at which point the legacy drivers/wiznet folder will be ready for removal.

@andrewleech
Copy link
Contributor Author

The stm32 CI build failures prompted me to update all the wiznet drivers to a current consistent state.
Added missing drivers for 5100, 5100s and 5300
Merge official 5200 driver in, maintaining WIZCHIP_USE_MAX_BUFFER support.
Replace the existing 5500 driver with current version, with minor cleanups.
Updates merged in manually from https://github.com/Wiznet/ioLibrary_Driver@ce4a7b6

The formatting of these C files is very inconsistent. @dpgeorge do you have a preference with regard to either:
a. keeping the source formatting largely in line with the wiznet source repo?
b. cleaning up the formatting to match micropython standard?

@dpgeorge
Copy link
Member

Does it make sense to have wiznet ioLibrary_Driver as a git submodule?

@DeeJay
Copy link
DeeJay commented Apr 14, 2022

Thank you for your efforts to give these w5100s boards some attention.

@DeeJay
Copy link
DeeJay commented Apr 18, 2022

{Disclaimer: I may not know what I am talking about.
My experience of MicroPython, C and GitHub may not qualify me to participate in discussion of this PR.}

I have a 'standalone' Pico and a separate WIZnet Ethernet 'Hardware Attached Underneath'
W5100S module. I was keen to beta-test this potential MicroPython solution.

It doesn't work for me as released. Attempting to build from the linked commit results in a
compilation error -

pi@rpitest64:~/aleechmp2 $ git clone https://github.com/andrewleech/micropython.git
Cloning into 'micropython'...
remote: Enumerating objects: 99755, done.
remote: Total 99755 (delta 0), reused 0 (delta 0), pack-reused 99755
Receiving objects: 100% (99755/99755), 331.85 MiB | 1.60 MiB/s, done.
Resolving deltas: 100% (72576/72576), done.
pi@rpitest64:~/aleechmp2 $ cd micropython/
pi@rpitest64:~/aleechmp2/micropython $ git status
On branch master
Your branch is up to date with 'origin/master'.

nothing to commit, working tree clean
pi@rpitest64:~/aleechmp2/micropython $ git checkout rpi-wiznet-5100s
Branch 'rpi-wiznet-5100s' set up to track remote branch 'rpi-wiznet-5100s' from 'origin'.
Switched to a new branch 'rpi-wiznet-5100s'
pi@rpitest64:~/aleechmp2/micropython $ git status
On branch rpi-wiznet-5100s
Your branch is up to date with 'origin/rpi-wiznet-5100s'.

nothing to commit, working tree clean
pi@rpitest64:~/aleechmp2/micropython $ cd ports/rp2

pi@rpitest64:~/aleechmp2/micropython/ports/rp2 $ make submodules
make -f ../../py/mkrules.mk GIT_SUBMODULES="lib/mbedtls lib/pico-sdk lib/tinyusb" submodules
make[1]: Entering directory '/home/pi/aleechmp2/micropython/ports/rp2'
Use make V=1 or set BUILD_VERBOSE in your environment to increase build verbosity.
Updating submodules: lib/mbedtls lib/pico-sdk lib/tinyusb
Submodule 'lib/mbedtls' (https://github.com/ARMmbed/mbedtls.git) registered for path '../../lib/mbedtls'
Submodule 'lib/pico-sdk' (https://github.com/raspberrypi/pico-sdk.git) registered for path '../../lib/pico-sdk'
Submodule 'lib/tinyusb' (https://github.com/hathach/tinyusb) registered for path '../../lib/tinyusb'
Cloning into '/home/pi/aleechmp2/micropython/lib/mbedtls'...
Cloning into '/home/pi/aleechmp2/micropython/lib/pico-sdk'...
Cloning into '/home/pi/aleechmp2/micropython/lib/tinyusb'...
Submodule path '../../lib/mbedtls': checked out '1bc2c9cb8b8fe4659bd94b8ebba5a4c02029b7fa'
Submodule path '../../lib/pico-sdk': checked out '2062372d203b372849d573f252cf7c6dc2800c0a'
Submodule path '../../lib/tinyusb': checked out '4bfab30c02279a0530e1a56f4a7c539f2d35a293'
make[1]: Leaving directory '/home/pi/aleechmp2/micropython/ports/rp2'

pi@rpitest64:~/aleechmp2/micropython/ports/rp2 $ make clean BOARD=W5100S_EVB_PICO
rm -f -rf build-W5100S_EVB_PICO

pi@rpitest64:~/aleechmp2/micropython/ports/rp2 $ make  BOARD=W5100S_EVB_PICO    [ -d build-W5100S_EVB_PICO ] || cmake -S . -B build-W5100S_EVB_PICO -DPICO_BUILD_DOCS=0 -DMICROPY_BOARD=W5100S_EVB_PICO
PICO_SDK_PATH is /home/pi/aleechmp2/micropython/lib/pico-sdk
Defaulting PICO_PLATFORM to rp2040 since not specified.
Defaulting PICO platform compiler to pico_arm_gcc since not specified.
PICO compiler is pico_arm_gcc
-- The C compiler identification is GNU 8.3.1
-- The CXX compiler identification is GNU 8.3.1
-- The ASM compiler identification is GNU
-- Found assembler: /usr/bin/arm-none-eabi-gcc
PICO target board is pico.
Using board configuration from /home/pi/aleechmp2/micropython/lib/pico-sdk/src/boards/include/boards/pico.h
-- Found Python3: /usr/bin/python3.9 (found version "3.9.2") found components: Interpreter
TinyUSB available at /home/pi/aleechmp2/micropython/lib/tinyusb/src/portable/raspberrypi/rp2040; enabling build support for USB.
Found User C Module(s):
-- Configuring done
-- Generating done
-- Build files have been written to: /home/pi/aleechmp2/micropython/ports/rp2/build-W5100S_EVB_PICO

[ ... ] Part of transcript suppressed

[ 55%] Building C object CMakeFiles/firmware.dir/modnwwiznet5k.c.obj
In file included from /home/pi/aleechmp2/micropython/drivers/wiznet5k/ethernet/wizchip_conf.h:113,
                 from /home/pi/aleechmp2/micropython/ports/rp2/modnwwiznet5k.c:44:
/home/pi/aleechmp2/micropython/ports/rp2/modnwwiznet5k.c: In function 'wiznet5k_regs':
/home/pi/aleechmp2/micropython/drivers/wiznet5k/ethernet/w5100s/w5100s.h:63:41: error: '_W5200_IO_BASE_' undeclared (first use in this function)
 #define WIZCHIP_SREG_ADDR(sn, addr)    (_W5200_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (addr))
                                         ^~~~~~~~~~~~~~~
/home/pi/aleechmp2/micropython/ports/rp2/modnwwiznet5k.c:457:28: note: in expansion of macro 'WIZCHIP_SREG_ADDR'
             uint32_t reg = WIZCHIP_SREG_ADDR(sn, i);
                            ^~~~~~~~~~~~~~~~~
/home/pi/aleechmp2/micropython/drivers/wiznet5k/ethernet/w5100s/w5100s.h:63:41: note: each undeclared identifier is reported only once for each function it appears in
 #define WIZCHIP_SREG_ADDR(sn, addr)    (_W5200_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (addr))
                                         ^~~~~~~~~~~~~~~
/home/pi/aleechmp2/micropython/ports/rp2/modnwwiznet5k.c:457:28: note: in expansion of macro 'WIZCHIP_SREG_ADDR'
             uint32_t reg = WIZCHIP_SREG_ADDR(sn, i);
                            ^~~~~~~~~~~~~~~~~
make[3]: *** [CMakeFiles/firmware.dir/build.make:2890: CMakeFiles/firmware.dir/modnwwiznet5k.c.obj] Error 1
make[2]: *** [CMakeFiles/Makefile2:1578: CMakeFiles/firmware.dir/all] Error 2
make[1]: *** [Makefile:103: all] Error 2
make: *** [Makefile:23: all] Error 2

I tried resolving this by 'Brute Force' as a change to the declaration in the .h file -

pi@rpitest64:~/aleechmp2/micropython/drivers/wiznet5k/ethernet/w5100s $ diff w5100s.h w5100s.h.orig
63c63
< #define WIZCHIP_SREG_ADDR(sn, addr)    (_W5100S_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (addr))
---
> #define WIZCHIP_SREG_ADDR(sn, addr)    (_W5200_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (addr))

With that change the firmware build runs to completion and creates a .uf2 with these properties -

pi@rpitest64:~/aleechmp2/micropython/ports/rp2/build-W5100S_EVB_PICO $ picotool info -a firmware.uf2
File firmware.uf2:

Program Information
 name:            MicroPython
 version:         v1.9.4-4262-g60c1c509e-dirty
 features:        USB REPL
                  thread support
 frozen modules:  _boot, _boot_fat, rp2, onewire, ds18x20, dht, uasyncio,
                  uasyncio/core, uasyncio/event, uasyncio/funcs, uasyncio/lock,
                  uasyncio/stream, neopixel
 binary start:    0x10000000
 binary end:      0x1004cd94
 embedded drive:  0x100a0000-0x10200000 (1408K): MicroPython

Fixed Pin Information
 none

Build Information
 sdk version:       1.3.0
 pico_board:        pico
 boot2_name:        boot2_w25q080
 build date:        Apr 18 2022
 build attributes:  MinSizeRel

Q: Should I expect MicroPython v1.9.4?

The MicroPython firmware can be flashed to ny Pico and is correctly detected and reported by the Thonny REPL:

MicroPython v1.9.4-4262-g60c1c509e-dirty on 2022-04-18; W5100S-EVB-Pico with RP2040
Type "help()" for more information.
>>> help('modules')
__main__          gc                uasyncio/lock     uos
_boot             math              uasyncio/stream   urandom
_boot_fat         micropython       ubinascii         ure
_onewire          neopixel          ucollections      uselect
_rp2              network           ucryptolib        usocket
_thread           onewire           uctypes           ustruct
_uasyncio         rp2               uerrno            usys
builtins          uarray            uhashlib          utime
cmath             uasyncio/__init__ uheapq            uzlib
dht               uasyncio/core     uio
ds18x20           uasyncio/event    ujson
framebuf          uasyncio/funcs    umachine
Plus any modules on the filesystem
>>> import network
>>> help(network.WIZNET5K)
object <class 'WIZNET5K'> is of type type
 regs -- <function>
 ifconfig -- <function>
 isconnected -- <function>
>>> 

But when connected to the Wiznet hardware it does not perform as expected -

MicroPython v1.9.4-4262-g60c1c509e-dirty on 2022-04-18; W5100S-EVB-Pico with RP2040
Type "help()" for more information.
>>> import network
>>> nic=network.WIZNET5K()
>>> print(nic.regs())
None
>>> nic.ifconfig()
('0.0.0.0', '0.0.0.0', '0.0.0.0', '8.8.8.8')
>>> print(nic.regs())
None
>>> 

Retrying with explicit creation arguments -

MicroPython v1.9.4-4262-g60c1c509e-dirty on 2022-04-18; W5100S-EVB-Pico with RP2040
Type "help()" for more information.
>>> import network
from machine import Pin, SPI
spi = SPI(0, 2_000_000, mosi=Pin(19), miso=Pin(16), sck=Pin(18))
nic = network.WIZNET5K(spi, Pin(17), Pin(20))
>>> print(nic.regs())
None
>>> nic.ifconfig()
('192.168.0.18', '255.255.255.0', '192.168.0.1', '8.8.8.8')
>>> print(nic.regs())
None
>>> 

(Note that the LAN to which the module is connected operates its DHCP server in subnet 192.168.1.n,
so the dhcp configuration being claimed is spurious. Edit: subsequently realised that WIZNET5K.ifconfig() only reports
current config, it does NOT invoke a dhcp client - the 'wrong' values are hard-coded defaults
.)

But the Good News, of sorts, is that if I create the network.WIZNET5K() and SPI instances with
explicit creation arguments AND I provide a valid configuration in network.WIZNET5K.ifconfig() then the
device DOES appear on the LAN and can be PINGed even though its own reports suggest it should not be
working!

MicroPython v1.9.4-4262-g60c1c509e-dirty on 2022-04-18; W5100S-EVB-Pico with RP2040
Type "help()" for more information.
>>> import network
from machine import Pin, SPI
spi = SPI(0, 2_000_000, mosi=Pin(19), miso=Pin(16), sck=Pin(18))
nic = network.WIZNET5K(spi, Pin(17), Pin(20))
>>> nic.regs()
>>> nic.isconnected()
False
>>> nic.ifconfig(['192.168.1.84', '255.255.255.0', '192.168.1.1', '8.8.8.8'])
>>> nic.ifconfig()
('192.168.1.84', '255.255.255.0', '192.168.1.1', '8.8.8.8')
>>> nic.regs()
>>> nic.isconnected()
False
>>> 

pi@rpitest64:~/aleechmp2/micropython/ports/rp2/build-W5100S_EVB_PICO $ ping 192.168.1.84
PING 192.168.1.84 (192.168.1.84) 56(84) bytes of data.
64 bytes from 192.168.1.84: icmp_seq=1 ttl=128 time=5.98 ms
64 bytes from 192.168.1.84: icmp_seq=2 ttl=128 time=7.01 ms
64 bytes from 192.168.1.84: icmp_seq=3 ttl=128 time=6.61 ms
64 bytes from 192.168.1.84: icmp_seq=4 ttl=128 time=6.77 ms
64 bytes from 192.168.1.84: icmp_seq=5 ttl=128 time=8.88 ms
^C
--- 192.168.1.84 ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4006ms
rtt min/avg/max/mdev = 5.978/7.049/8.883/0.978 ms
pi@rpitest64:~/aleechmp2/micropython/ports/rp2/build-W5100S_EVB_PICO $ arp -a
? (192.168.1.84) at 00:08:dc:ab:cd:ef [ether] on wlan0
? (192.168.1.1) at 98:de:d0:be:4b:c8 [ether] on wlan0
? (192.168.1.163) at 70:f1:a1:80:16:2d [ether] on wlan0
? (192.168.1.138) at b8:27:eb:fd:34:bd [ether] on wlan0

A lot of words there, hope it is of some use. Content to get polite feedback if I have
made any silly error.

tl;dr: It works after manual patching, although it looks as though it shouldn't. And only
icmp ping has been tested, not any higher level IP protocol.

@andrewleech
Copy link
Contributor Author

Thanks for the testing reports @DeeJay !

I tried resolving this by 'Brute Force' as a change to the declaration in the .h file -

pi@rpitest64:~/aleechmp2/micropython/drivers/wiznet5k/ethernet/w5100s $ diff w5100s.h w5100s.h.orig
63c63
< #define WIZCHIP_SREG_ADDR(sn, addr)    (_W5100S_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (addr))
---
> #define WIZCHIP_SREG_ADDR(sn, addr)    (_W5200_IO_BASE_ + WIZCHIP_SREG_BLOCK(sn) + (addr))

Good catch.... I broke this in my latest commits to bring the wiznet driver closer to the upstram published version. They don't have the WIZCHIP_SREG_ADDR in most of their drivers, but we are using it in the bindings, so I added it (incorrectly as you found) to the other chips. I've fixed this now thanks.

Program Information
name: MicroPython
version: v1.9.4-4262-g60c1c509e-dirty

Q: Should I expect MicroPython v1.9.4?

Not sure why you're getting this, perhaps the git tags aren't all fetched on your repo?
The version works correctly on mine

>>> 
MPY: soft reboot
MicroPython v1.18-337-g74dcbc4a3-dirty on 2022-04-19; W5100S-EVB-Pico with RP2040
Type "help()" for more information.

But when connected to the Wiznet hardware it does not perform as expected -

MicroPython v1.9.4-4262-g60c1c509e-dirty on 2022-04-18; W5100S-EVB-Pico with RP2040
Type "help()" for more information.
>>> import network
>>> nic=network.WIZNET5K()
>>> print(nic.regs())
None
>>> nic.ifconfig()
('0.0.0.0', '0.0.0.0', '0.0.0.0', '8.8.8.8')
>>> print(nic.regs())
None
>>> 

Retrying with explicit creation arguments -

MicroPython v1.9.4-4262-g60c1c509e-dirty on 2022-04-18; W5100S-EVB-Pico with RP2040
Type "help()" for more information.
>>> import network
from machine import Pin, SPI
spi = SPI(0, 2_000_000, mosi=Pin(19), miso=Pin(16), sck=Pin(18))
nic = network.WIZNET5K(spi, Pin(17), Pin(20))
>>> print(nic.regs())
None
>>> nic.ifconfig()
('192.168.0.18', '255.255.255.0', '192.168.0.1', '8.8.8.8')
>>> print(nic.regs())
None
>>> 

This is really interesting, I hadn't seen it earler. There's something a bit strange going on here, not sure what yet.
I can confirm a reproduction of this, but not reliably. Sometimes it works, sometimes not... might be related to soft-reboot vs hard power cycle.
I just added a new function to WIZNET5K.spi() which returns the spi object in use - when it works I see

>>> import network
>>> nic=network.WIZNET5K()
>>> nic.ifconfig()
('192.168.0.18', '255.255.255.0', '192.168.0.1', '8.8.8.8')
>>> nic.spi()
SPI(0, baudrate=1953125, polarity=0, phase=0, bits=8, sck=18, mosi=19, miso=16)

but when it fails;

>>> import network
>>> nic = network.WIZNET5K()
>>> nic.ifconfig()
('0.0.0.0', '0.0.0.0', '0.0.0.0', '8.8.8.8')
>>> nic.spi()
SPI(0, baudrate=1953125, polarity=0, phase=0, bits=8, sck=6, mosi=7, miso=4)

So sometimes the auto configuration is grabbing the wrong pins, somehow. Haven't got to the root cause yet.

(Note that the LAN to which the module is connected operates its DHCP server in subnet 192.168.1.n, so the dhcp configuration being claimed is spurious. Edit: subsequently realised that WIZNET5K.ifconfig() only reports current config, it does NOT invoke a dhcp client - the 'wrong' values are hard-coded defaults.)

But the Good News, of sorts, is that if I create the network.WIZNET5K() and SPI instances with explicit creation arguments AND I provide a valid configuration in network.WIZNET5K.ifconfig() then the device DOES appear on the LAN and can be PINGed even though its own reports suggest it should not be working!

Good catch - I actually hadn't realised the 192.168.0.18 was a hardcoded default myself - turns out this is shared with the original stm32 driver too. This should also probably be abstracted out to defines, or perhaps the default should be a 169.254.x.y auto-ip style address to be obvious.

I also didn't know about / hadn't tried the regs() function - something is wrong with this.
I can confirm isconnected() also isn't behaving right for me either :-(

A lot of words there, hope it is of some use. Content to get polite feedback if I have made any silly error.

tl;dr: It works after manual patching, although it looks as though it shouldn't. And only icmp ping has been tested, not any higher level IP protocol.

Quite helpful thanks!

I also hadn't done more than ping tests yet - certainly will be important to check socket does indeed work correctly!

@andrewleech andrewleech force-pushed the rpi-wiznet-5100s branch 2 times, most recently from d2edbbd to b1d3e04 Compare April 19, 2022 01:38
@andrewleech
Copy link
Contributor Author

Well that was daft - I was never actually configuring the sck/miso/mosi pins on the auto-created spi object. Fixed now.

@DeeJay
Copy link
DeeJay commented Apr 19, 2022

Thanks for the acknowledgement and prompt fixes. I'll retest later today (UK time.)

Re: "Version 1.9.4" - I was testing against your GH repo which I got by -
$ git clone https://github.com/andrewleech/micropython.git
$ cd micropython
$ git checkout rpi-wiznet-5100s

Is that the right starting point?
(I think I also tried git clone --branch rpi-wiznet-5100s [github url] with similar results.)

@Lobo-T
Copy link
Lobo-T commented Apr 19, 2022

I'm very happy that someone is trying to make this work, so I tought I could try to help by testing at least.

As i understand it this should also work with the W5500.
I have a custom made PCB with a RP2040 and a Wiznet module with W5500. I have run Circuitpython and the Circuitpython Wiznet driver on it sucessfully.

I cloned with:
git clone -b rpi-wiznet-5100s https://github.com/andrewleech/micropython.git mpwz5k
Compiled mpy-cross, and did at make submodules in ports/rp2.
Then made a copy of the boards/W5100S_EVB_PICO directory.
Edited mpconfigboard.cmake to refer to w5500 instead of w5100s. And edited the SPI pins in mpconfigboard.h.

The make then failed with:
In file included from /home/pi/src/mpwz5k/drivers/wiznet5k/ethernet/w5500/../wizchip_conf.h:149,
from /home/pi/src/mpwz5k/drivers/wiznet5k/ethernet/w5500/w5500.h:52,
from /home/pi/src/mpwz5k/drivers/wiznet5k/ethernet/w5500/w5500.c:55:
/home/pi/src/mpwz5k/drivers/wiznet5k/ethernet/w5500/../w5500/w5500.h:1552:1: error: "/*" within comment [-Werror=comment]
/**

I added the */ that seemed to be missing, and it then compiled sucessfully.

But trying to start the interface gives just the defaults, same as @DeeJay :

import network
nic = network.WIZNET5K()
nic.ifconfig()
('192.168.0.18', '255.255.255.0', '192.168.0.1', '8.8.8.8')

So DHCP is definitely not working.

Just to be sure i also downloaded the firmware to a bare Pico, not connected to anything and tried to intitialise the non existing interface. It gives no errors, but everything is 255.

nic.ifconfig()
('255.255.255.255', '255.255.255.255', '255.255.255.255', '8.8.8.8')

So atleast there is some communication between the RP2040 and W5500.

I also get the 1.9.4 version:
MicroPython v1.9.4-4262-gb1d3e04a9-dirty
But as DeeJay, I'm not sure I really understand git either.

@Lobo-T
Copy link
Lobo-T commented Apr 19, 2022

Another issue is that there doesn't appear to be any way to set the MAC address.
As far as I know the Wiznet chips do not come with a unique MAC address.
The MAC address apears to be set in line 429 of ports/rp2/modnwwiznet5k.c.

The comment says "// set some sensible default values; they are configurable using ifconfig method". But there does not seem to be any way to set the MAC with ifconfig. And I would argue that a "default MAC" is in no way "sensible"
If you get two ethernet interfaces with the same MAC on the network you get some very strange problems that are not easy to debug.

MAC address should probably be a mandatory parameter when instancing the NIC. (Ideally you would read a unique MAC from something like a Microchip 24AA025E48 first.)

But this seems to be the same in the STM port. I can't understand that anyone can ever have used this successfully if they have more than one unit running the same firmware on the same network.

@DeeJay
Copy link
DeeJay commented Apr 19, 2022

Feedback on commit b1d3e04

MicroPython v1.9.4-4262-gb1d3e04a9-dirty on 2022-04-19; W5100S-EVB-Pico with RP2040
Type "help()" for more information.

from network import WIZNET5K
nic=WIZNET5K()
nic.ifconfig()
('192.168.1.84', '255.255.255.0', '192.168.1.1', '8.8.8.8')
nic.spi()
SPI(0, baudrate=1953125, polarity=0, phase=0, bits=8, sck=18, mosi=19, miso=16)

$ ping 192.168.1.84
PING 192.168.1.84 (192.168.1.84) 56(84) bytes of data.
64 bytes from 192.168.1.84: icmp_seq=1 ttl=128 time=33.4 ms
64 bytes from 192.168.1.84: icmp_seq=2 ttl=128 time=45.7 ms
64 bytes from 192.168.1.84: icmp_seq=3 ttl=128 time=15.6 ms

Default constructors appear to work as expected.

Ping works.

An attempt to create an mqtt client publish script failed - hung at mqtt.connect(). Further investigation needed. Higher-level (socket) protocols are unproven at the time of writing.

Still builds as v1.9.4

@DeeJay
Copy link
DeeJay commented Apr 19, 2022

Still puzzled by the failure of network.WIZNET5K,regs() to return any result.

It is an apparently valid function reported by HELP -

>>> help(WIZNET5K)
object <class 'WIZNET5K'> is of type type
  regs -- <function>
  spi -- <function>
  ifconfig -- <function>
  isconnected -- <function>
>>> 

It seems the only place it can be implemented is in ports/rp2/modnwwiznet5k.c

(This where your new spi function is implemented, so is clearly part of the build process.)

The relevant declaration begins -

STATIC mp_obj_t wiznet5k_regs(mp_obj_t self_in) {
    // wiznet5k_obj_t *self = self_in;
    printf("Wiz CREG:");

I am not a C programmer, but I don't see how this can fail to emit that "Wiz CREG:" message.

8000
@DeeJay
Copy link
DeeJay commented Apr 19, 2022

Andrew. You have probably done your own background research, but just to pass on what I have picked up...

Wiznet carried on working on an independent vendor-provided version of uPy firmware after their PR 8021 'stalled'

Their most recent release, v1.0.4 was in mid-March 2022 and is available here - https://github.com/Wiznet/RP2040-HAT-MicroPython (this is not the same GH account or Repo as the one that promoted the PR.)

If I run that firmware on my Pico + W5100S combo the MQTT Publish (modules +script) Test is successful, so there might be lessons to be learned from that version of their codebase? In that version there is an additional function WIZNET5K.active() which invokes a DHCP client attempt to get and apply the 4 config items needed by the WIZNET5K.ifconfig([]) Setter function.

@andrewleech
Copy link
Contributor Author

Re: "Version 1.9.4" - I was testing against your GH repo which I got by - $ git clone https://github.com/andrewleech/micropython.git $ cd micropython $ git checkout rpi-wiznet-5100s

Ah, yes I wouldn't normally clone direct from my fork, I guess the "correct" method is to cover this main repo, then there's a button near top of this PR to check out the PR. Compiling from my fork will get a comparable / working build but I don't have the release tags so that explains the version issue. As far as testing the wiznet feature though you can safely continue with what you're doing and ignore the version.

@andrewleech
Copy link
Contributor Author

/home/pi/src/mpwz5k/drivers/wiznet5k/ethernet/w5500/../w5500/w5500.h:1552:1: error: "/*" within comment [-Werror=comment] /**

I added the */ that seemed to be missing, and it then compiled sucessfully.

That must be about error I just added while trying to clean up some inconsistent / ugly commenting in those files, I'll fix it.

But trying to start the interface gives just the defaults, same as @DeeJay :

import network
nic = network.WIZNET5K()
nic.ifconfig()
('192.168.0.18', '255.255.255.0', '192.168.0.1', '8.8.8.8')

So DHCP is definitely not working.

Yep I don't think DHCP is designed to be built in at all, there's presumably a separate DHCP client application / driver that could be run to handle this - I haven't looked into that yet though.

@andrewleech
8000 Copy link
Contributor Author

Another issue is that there doesn't appear to be any way to set the MAC address. As far as I know the Wiznet chips do not come with a unique MAC address.

The comment says "// set some sensible default values; they are configurable using ifconfig method". But there does not seem to be any way to set the MAC with ifconfig. And I would argue that a "default MAC" is in no way "sensible" If you get two ethernet interfaces with the same MAC on the network you get some very strange problems that are not easy to debug.

MAC address should probably be a mandatory parameter when instancing the NIC. (Ideally you would read a unique MAC from something like a Microchip 24AA025E48 first.)

This does appear to be quite an oversight in the existing / current driver. I will need to look into options for this - certainly bring able to set it at least will be important, regardless of whether or not a "default" is provided.

@andrewleech
Copy link
Contributor Author

Still puzzled by the failure of network.WIZNET5K,regs() to return any result.

Yeah this one has me puzzled currently too. C printf certainly works in other ports, but this is the first time I've worked with RPI Pico, perhaps the printf function here isn't working for some reason.

@andrewleech
Copy link
Contributor Author

Wiznet carried on working on ... uPy firmware ... available here - https://github.com/Wiznet/RP2040-HAT-MicroPython (this is not the same GH account or Repo as the one that promoted the PR.)

Thanks for the suggestion! While I'd seen this previously I didn't reference it during development so far - I'd initially assumed the existing driver here was stable / complete enough.
In light of some of the glitches we're running into it's great to hear higher level usage is working with that one, that'll make it a good idea to look at to learn from!

In that version there is an additional function WIZNET5K.active() which invokes a DHCP client attempt to get and apply the 4 config items needed by the WIZNET5K.ifconfig([]) Setter function.

I actually think wiznet supply a C DHCP driver which could be built in, I'm guessing that's what they're doing in their fork here. Certainly sounds like it's worth using, would be simpler to have it built in.

@DeeJay
Copy link
DeeJay commented Apr 20, 2022

I guess the "correct" method is to cover this main repo, then there's a button near top of this PR to check out the PR.

So I've definitely learnt something about git/GitHub here..

That code button at the head of this PR page required me to install the gh CLI tool, and get a GH access token to authenticate it,

Once I had done that I could do -

 $ git clone https://github.com/micropython/micropython.git
 $ cd micropython/
 $ gh pr checkout 8540 

That concludes with -

From https://github.com/micropython/micropython
 * [new ref]             refs/pull/8540/head -> rpi-wiznet-5100s
Switched to branch 'rpi-wiznet-5100s'

When I now build from the resulting checkout I get a firmware that reports the 'right' MP version -

 $ picotool info -a build-W5100S_EVB_PICO/firmware.uf2
File build-W5100S_EVB_PICO/firmware.uf2:

Program Information
 name:            MicroPython
 version:         v1.18-336-gb1d3e04a9-dirty
 features:        USB REPL
                  thread support
 frozen modules:  _boot, _boot_fat, rp2, onewire, ds18x20, dht, uasyncio,
                  uasyncio/core, uasyncio/event, uasyncio/funcs, uasyncio/lock,
                  uasyncio/stream, neopixel
 binary start:    0x10000000
 binary end:      0x1004cde4
 embedded drive:  0x100a0000-0x10200000 (1408K): MicroPython

Fixed Pin Information
 none

Build Information
 sdk version:       1.3.0
 pico_board:        pico
 boot2_name:        boot2_w25q080
 build date:        Apr 20 2022
 build attributes:  MinSizeRel


This doesn't affect any of the functional issues, but it means I can be more confident that I am accurately testing
your intended patches and not introducing 'artefacts' from a faulty build process. Thanks for the hint.

@DeeJay
Copy link
DeeJay commented Apr 21, 2022

I have a proposed trivial patch to enable network.WIZNET5K.regs() to produce output -

 $ diff modnwwiznet5k.c modnwwiznet5k.c.orig.al
44d43
< #define printf(...) mp_printf(MP_PYTHON_PRINTER, __VA_ARGS__)
430,431c429,430
<         .mac = {0x00, 0x08, 0xdc, 0xbf, 0xac, 0xed},
<         .ip = {192, 168, 1, 84},
---
>         .mac = {0x00, 0x08, 0xdc, 0xab, 0xcd, 0xef},
>         .ip = {192, 168, 0, 18},
433c432
<         .gw = {192, 168, 1, 1},
---
>         .gw = {192, 168, 0, 1},

(Only the first #define is significant - the other changes just hard-code the IP config for my LAN.)

Having done so, a call to nic.regs() produces output. But the output is wrong. Every byte is reported
as 0x20. So if the chip register content is wrong that might explain why the rest of the stack isn't cooperating?

For comparison, this is the output from the WizNet v1.0.4 firmware -

>>> nic.regs()
Wiz CREG:
  0000: 03 c0 a8 01 01 ff ff ff 00 00 08 dc ab cd ef c0
  0010: a8 01 54 00 00 00 00 07 d0 07 55 55 00 00 00 00
  0020: 00 00 00 00 00 00 00 00 28 00 00 00 00 00 00 00
  0030: 40 00 00 00 00 00 00 00 00 00 ff ff 01 85 0a 00
  0040: 00 00 00 00 00 01 00 40 00 00 00 00 00 07 d0 00
Wiz SREG[0]:
  0000: 00 00 00 00 00 00 ff ff ff ff ff ff 00 00 00 00
  0010: 00 00 00 00 00 00 80 00 00 00 00 00 00 00 02 02
  0020: 08 00 00 00 00 00 00 00 00 00 00 00 ff 40 00 00
Wiz SREG[1]:
  0000: 00 00 00 00 00 00 ff ff ff ff ff ff 00 00 00 00
  0010: 00 00 00 00 00 00 80 00 00 00 00 00 00 00 02 02
  0020: 08 00 00 00 00 00 00 00 00 00 00 00 ff 40 00 00
Wiz SREG[2]:
  0000: 00 00 00 00 00 00 ff ff ff ff ff ff 00 00 00 00
  0010: 00 00 00 00 00 00 80 00 00 00 00 00 00 00 02 02
  0020: 08 00 00 00 00 00 00 00 00 00 00 00 ff 40 00 00
Wiz SREG[3]:
  0000: 00 00 00 00 00 00 ff ff ff ff ff ff 00 00 00 00
  0010: 00 00 00 00 00 00 80 00 00 00 00 00 00 00 02 02
  0020: 08 00 00 00 00 00 00 00 00 00 00 00 ff 40 00 00

I don't know how to interpret this, other than the fact that the MAC address is present in the first line.

And CREG Byte 0x3C appears to be an indication of whether the Ethernet Link is Up/Down.
Connected = 0x01, not Connected = 0x86

@andrewleech
Copy link
Contributor Author
andrewleech commented Apr 21, 2022

@DeeJay I actually found exactly the same today, worked on this a bit this afternoon. I manually merged in pretty much everything from the other wiznet repo and saw that same define which enables printf, fixing regs.
The incorrect output of regs is also related to why actual network traffic doesn't work correctly.
I've narrowed the issue down to the spi transport functions, switching out the current spiburst ones for the ones in the other wiznet repo fixes the issue. The current spiburst ones are closest to the upstream master version of the drivers itself so I'm planning on fixing them, having this other wiznet version should make that pretty straightforward.

Once that's working, I'll probably try to separate out any changes in the wiznet driver into a new PR on their repo, if/when it's merged we can simply include it here as a submodule rather than a patched copy.

@irinakim12
Copy link

#8021
I don't know why they don't merge. I want to know the contents of that part. So you have created a repository to use W5100S-EVB-PICO using PATCH operation.
https://github.com/Wiznet/RP2040-HAT-MicroPython

@andrewleech
Copy link
Contributor Author

#8021 I don't know why they don't merge. I want to know the contents of that part. So you have created a repository to use W5100S-EVB-PICO using PATCH operation. https://github.com/Wiznet/RP2040-HAT-MicroPython

This original PR is not yet in a state ready to merge:

  • the changes affect all rp2 boards (it builds this wiznet support into all rp2 boards) rather than adding a new board definition.
  • some of the refactoring in machine.pin and machine.spi moved too much stuff to header files
  • header files also needed #ifndef guards and similar cleanups
  • there are multiple merge conflicts
  • the PR branch is not a clean set of commits (has extra merge commits in the middle instead of rebased to current master)
  • cmakelist changes have if/else duplications, making future maintenance difficult.
  • the commit messages need to follow the micropython commit message standard

Don't get me wrong, it was a fantastic piece of work which was a great starting point for me here - indeed I've kept most of your changes in commits authored by you (with cleanups I've made along the way). I hope you're happy with me keeping your name on these modified commits @irinakim12 ?

I've also been referencing your other patch fork/repo to bring in your more recent changes such as dhcp support, which is certainly a worthy addition (not pushed here yet).

Once I've fixed the incompatibility issues between the official wiznet driver and th copy of them here I think this PR will be in a quite good state.

Signed-off-by: Andrew Leech <andrew@alelec.net>
This works if your network is pre-configured in
boot.py as an object called: nic

Without this multitests expects to access the
WLAN class which isn't always correct.

Signed-off-by: Andrew Leech <andrew@alelec.net>
This exercises the inclusion of a number of libraries in the rpi2
port including mbed and lwip.

Signed-off-by: Andrew Leech <andrew@alelec.net>
@dpgeorge
Copy link
Member
dpgeorge commented Jun 3, 2022

I rebased this and merged it in 9bd6169 through b92e51e, with some minor changes to formatting and removal of unnecessary header includes.

@andrewleech would be great if you could re-test it on hardware with master.

@dpgeorge dpgeorge closed this Jun 3, 2022
@DeeJay
Copy link
DeeJay commented Jun 5, 2022

{to avoid confusion - I am NOT @andrewleech the PR author. But I have been following this PR with interest}

Please find below a test report based on my experience;

Test conducted using a classic 'standalone' RPi PICO with a separate
'Hardware Attached Underneath' WizNet W5100S combo. Workstation
at 192.168.1.202 is an RPi4B2G running RasPiOS Bullseye [64],
used as iperf and MQTT server. LAN infrastructure has all
devices connected to a TP-Link Fast Ethernet Switch.

Using this Build from Master -

MPY: soft reboot
MicroPython v1.18-567-g2111ca0b8-dirty on 2022-06-04; W5100S-EVB-Pico with RP2040
Type "help()" for more information.
>>> 
('Dirty' status is due to a customised manifest.py)


Network initialisation -

>>> import network
>>> nic = network.WIZNET5K()
>>> nic.active(True)
>>> nic.ifconfig()
('192.168.1.205', '255.255.255.0', '192.168.1.1', '192.168.1.1')
>>> 

Standard Ping -

pi@rpitest64:~ $ ping -c 32 -q 192.168.1.205
PING 192.168.1.205 (192.168.1.205) 56(84) bytes of data.

--- 192.168.1.205 ping statistics ---
32 packets transmitted, 32 received, 0% packet loss, time 31745ms
rtt min/avg/max/mdev = 0.656/0.687/0.725/0.018 ms
pi@rpitest64:~ $

Flood Ping -

pi@rpitest64:~ $ sudo ping -f -c 4096 -q 192.168.1.205
PING 192.168.1.205 (192.168.1.205) 56(84) bytes of data.

--- 192.168.1.205 ping statistics ---
4096 packets transmitted, 4096 received, 0% packet loss, time 2733ms
rtt min/avg/max/mdev = 0.567/0.613/0.786/0.016 ms, ipg/ewma 0.667/0.609 ms
pi@rpitest64:~ $

IPERF -

>>> import iperf3
>>> iperf3.client("192.168.1.202")
CLIENT MODE: TCP sending
Connecting to ('192.168.1.202', 5201)
Interval           Transfer     Bitrate
  0.00-1.00   sec   436 KBytes  3.56 Mbits/sec
  1.00-2.01   sec   462 KBytes  3.75 Mbits/sec
  2.01-3.01   sec   487 KBytes  3.99 Mbits/sec
  3.01-4.01   sec   489 KBytes  4.00 Mbits/sec
  4.01-5.02   sec   489 KBytes  3.97 Mbits/sec
  5.02-6.02   sec   487 KBytes  3.99 Mbits/sec
  6.02-7.02   sec   490 KBytes  4.01 Mbits/sec
  7.02-8.02   sec   486 KBytes  3.98 Mbits/sec
  8.02-9.02   sec   487 KBytes  3.98 Mbits/sec
  9.02-10.01  sec   478 KBytes  3.97 Mbits/sec
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
  0.00-10.02  sec  4.68 MBytes  3.92 Mbits/sec  sender
  0.00-10.50  sec  4.68 MBytes  3.74 Mbits/sec  receiver
>>> 

uRequests -

>>> import urequests
>>> r = urequests.get("https://micropython.org/ks/test.html")
>>> print(r.content[0:256])
b'<!DOCTYPE html>\n<html lang="en">\n    <head>\n        <title>Test</title>\n    </head>\n    <body>\n        <h1>Test</h1>\n        It\'s working if you can read this!\n    </body>\n</html>\n'
>>> 

MQTT Publish + Subscribe Client -

>>> %Run -c $EDITOR_CONTENT
Pico + Wiznet + MQTT Data Logger
Checking Temperature - 
45.7702
44.83391
Setting up Wiznet network interface - 
DHCP config:  ('192.168.1.205', '255.255.255.0', '192.168.1.1', '192.168.1.1')
Network setup done
Connecting to MQTT Broker 
Connected to 192.168.1.202 MQTT Broker
Published temp:  44.36577
Subscriber reports:  ('pico_temp', '44.36577')
Published temp:  44.83391
Subscriber reports:  ('pico_temp', '44.83391')
Published temp:  44.83391
Subscriber reports:  ('pico_temp', '44.83391')
Published temp:  44.83391
Subscriber reports:  ('pico_temp', '44.83391')
Published temp:  44.36577
Subscriber reports:  ('pico_temp', '44.36577')

In summary - I have found nothing of concern to report about this implementation.

Thanks to Andrew and Damien for their efforts.

@beyonlo
Copy link
beyonlo commented Jun 5, 2022

@DeeJay Three points about the tests that I would like to know:

  1. I see that you tested MQTT in unsecure mode. Do you know if MQTT works with SSL/TLS mode?
  2. Do you know if everything over SSL/TLS will works on this driver, like as to create a secure HTTP Server (HTTPS) on RP2?
  3. I see that you tested using the W5100S Chip. Did you tested using the chip W5500, or do you know if everything works on it too?

Thank you!

@andrewleech
Copy link
Contributor Author
andrewleech commented Jun 6, 2022

I started some tests running on friday which were looking good, but then computer restarted before I could copy the results here. Basically urequests checks and iperf all looked equivalent to before, similar to @DeeJay's testing above (thanks for that!)

Also:

anl@STEP:~/micropython-wiznet/tests$ sudo python run-tests.py --target pyboard -r results_wiz net_inet/*.py
pass  net_inet/getaddrinfo.py
pass  net_inet/ssl_errors.py
FAIL  net_inet/test_tls_nonblock.py
pass  net_inet/test_tls_sites.py
pass  net_inet/tls_num_errors.py
pass  net_inet/tls_text_errors.py
pass  net_inet/uasyncio_cancel_stream.py
pass  net_inet/uasyncio_open_connection.py
pass  net_inet/uasyncio_tcp_read_headers.py
9 tests performed (68 individual testcases)
8 tests passed
1 tests failed: test_tls_nonblock
  • same as before

and

>>> anl@STEP:~/micropython-wiznet/tests$ sudo python run-tests.py --target pyboard -r results_wiz net_hosted/*.py
pass  net_hosted/accept_nonblock.py
pass  net_hosted/accept_timeout.py
pass  net_hosted/connect_nonblock.py
FAIL  net_hosted/connect_nonblock_xfer.py
pass  net_hosted/connect_poll.py
pass  net_hosted/ssl_getpeercert.py
pass  net_hosted/uasyncio_start_server.py
7 tests performed (56 individual testcases)
6 tests passed
1 tests failed: connect_nonblock_xfer
  • same as before!

@andrewleech
Copy link
Contributor Author

@DeeJay Three points about the tests that I would like to know:

  1. I see that you tested MQTT in unsecure mode. Do you know if MQTT works with SSL/TLS mode?
  2. Do you know if everything over SSL/TLS will works on this driver, like as to create a secure HTTP Server (HTTPS) on RP2?
  3. I see that you tested using the W5100S Chip. Did you tested using the chip W5500, or do you know if everything works on it too?

Thank you!

SSL mode in both mqtt and https should work in a standard way, mbedtls for ssl support is integrated with the standard micropython ssl interfaces.

Most testing here has only been done on the W5100S-EVB-Pico board. The W5500 chip should work and has had a little testing in the past (#8540 (comment)), but I don't know of any testing on other wiznet chips on the final merged version of the PR.

@beyonlo
Copy link
beyonlo commented Jun 6, 2022

@andrewleech Thank you for the reply and for the amazing work on the Wiznet5k driver for the rp2.

Just curious about some points:

1. Is this ethernet driver for the Wiznet5k supporting rp2 MCU right? Why did you used pyboard as target test for this driver? sudo python run-tests.py --target pyboard.
1.1. I see that FAIL on the test_tls_nonblock.py and connect_nonblock_xfer.py in your tests.That FAIL was being expected? Is there plans do fixed/support it in the future?
2. I see in comments above that this driver use LwIP, like as the Wiznet5k ethernet driver for the STM32 (Pyboard). So, will this driver works on the stm32/pyboard as well? If yes, maybe this explain why do you used pyboard as target in question 1.
2.1. This driver will be just a commom Wiznet5k ethernet driver for both, rp2 and pyboard?
3. As this driver use Wiznet5k chip in mac raw mode (using LwIP), that maximum sockets allowed by chip model is still is valid? Here the list of Wiznet5k chips and how many sockets (HW Socket) every chip model support https://www.wiznet.io/product/tcpip-chip/. Or as the driver are using mac raw mode, are there not number of HW Socket limits anymore?

Thank you in advance!

@andrewleech
Copy link
Contributor Author
andrewleech commented Jun 6, 2022

1. Is this ethernet driver for the Wiznet5k supporting rp2 MCU right? Why did you used pyboard as target test for this driver? sudo python run-tests.py --target pyboard.

With the unit test suite, the pyboard target just means it uses pyboard.py tool to directly run the tests on hardware, as opposed to eg. using the unix build of micropython as the target. It then runs on whatever micropython board is connected to the PC (in my case it was the W5100S-EVB-Pico board)

1.1. I see that FAIL on the test_tls_nonblock.py and connect_nonblock_xfer.py in your tests.That FAIL was being expected? Is there plans do fixed/support it in the future?

If you look through the earlier messages on this thread where these unit tests were run previously, the fails were seen there and discussed briefly. I think they fail on multiple platforms currently so possibly relate to common code, not just this board.

2. I see in comments above that this driver use LwIP, like as the Wiznet5k ethernet driver for the STM32 (Pyboard). So, will this driver works on the stm32/pyboard as well? If yes, maybe this explain why do you used pyboard as target in question 1.

This PR incldued a new consolidated wiznet driver in the extmod directory. The stm32 port already supposed the same two modes of wiznet interface through a pair of drivers in the stm32 port folder, however the new one has more features. The stm32 port can be updated to use this new driver, however I don't have any immediate plans to do this myself as I don't have any stm32 boards with wiznet (and too many other projects on the go).

2.1. This driver will be just a commom Wiznet5k ethernet driver for both, rp2 and pyboard?

As above, yes this is a new common driver that could be used for any port, if anyone else wants to add support.

3. As this driver use Wiznet5k chip in mac raw mode (using LwIP), that maximum sockets allowed by chip model is still is valid? Here the list of Wiznet5k chips and how many sockets (HW Socket) every chip model support https://www.wiznet.io/product/tcpip-chip/. Or as the driver are using mac raw mode, are there not number of HW Socket limits anymore?

In mac raw mode the hardware sockets limit won't apply at all, you'll only be limited by available ram on the micro I believe. If instead you build in the external stack mode, then it's stlightly faster in most cases, uses less ram, but has less features and yes the limit will apply.

@mariusmotea
Copy link

I also want to test this on a custom RP2040 board with W5100S controller. Do i simply need to pick the last nightly build or it require manual compilation?

Thanks,
Marius.

@andrewleech
Copy link
Contributor Author

I also want to test this on a custom RP2040 board with W5100S controller. Do i simply need to pick the last nightly build or it require manual compilation?

You should be able to use the nightly builds for the W5100S-EVB-Pico board.

If you connect the wiznet chip on the same pins as the official board it should just work, else you can specify all the pins used during initialisation in python.

To use a different wiznet controller chip though recompilation would be needed.

@mariusmotea
Copy link

My board is similar with W5100S-EVB-Pico, only with PoE ethernet made it specially for my home. Was very disappointed when i test it with Wiznet oficial firmware and HomeAssistant. In Home Assistant i declared a switch for every GPIO pin, but because of the sockets limit just the first declared switch was added, all others where considered offline (probing http requests are send simultaneous by homeassistant and this cannot be changed). With the firmware you made i set 7 switches and all where added. I did not test with a bigger number since i don't think i will need more than this. Overall i think you did a great job.

Thank you very much!

@liudr
Copy link
liudr commented Jun 9, 2022

Is there any chance to use this driver on ESP32 ports? That would be a great thing to add to other ports.

@andrewleech
Copy link
Contributor Author

Is there any chance to use this driver on ESP32 ports? That would be a great thing to add to other ports.

The commits in this PR that handle bringing in the wiznet driver should be straightforward for someone to port to esp32 - it's already got tls & lwip I believe so those other commits shouldn't be needed. Considering both this PR and esp32 use cmake it should transfer pretty easily. I don't have hardware (or time) to handle this myself but would be happy to assist anyone else trying to do it via slack etc.

@liudr
Copy link
liudr commented Jun 12, 2022

Yes I am very interested! I'm not very good with git so I could use some help. I have cloned micropython and micropython-libs to my computer and pulled the latest master. I've built micropython firmware before and I've used IDF for some time. but when it comes to what it takes to get this driver, I could use some help. slack would be great!

@Lobo-T
Copy link
Lobo-T commented Jun 21, 2022

Most testing here has only been done on the W5100S-EVB-Pico board. The W5500 chip should work and has had a little testing in the past (#8540 (comment)), but I don't know of any testing on other wiznet chips on the final merged version of the PR.

If anyone is interested W5500 seems to still work in Micropython 1.19.1.
I haven't done any extensive testing, but I have a project I will be using it for so if I notice anything in the future I'll make a bug report.

@rajtan
Copy link
rajtan commented Jul 13, 2022

Most testing here has only been done on the W5100S-EVB-Pico board. The W5500 chip should work and has had a little testing in the past (#8540 (comment)), but I don't know of any testing on other wiznet chips on the final merged version of the PR.

If anyone is interested W5500 seems to still work in Micropython 1.19.1. I haven't done any extensive testing, but I have a project I will be using it for so if I notice anything in the future I'll make a bug report.

@Lobo-T Which build have you tested separate W5500 board to be working with RP2 ?

Further, did it require any change in option or compile time flag ? I have made a build but it stalls at active(True)

@Lobo-T
Copy link
Lobo-T commented Jul 14, 2022

I think I pretty much copied the mpconfigboard.cmake and mpconfigboard.h files for the W5100S_EVB_PICO and just changed set(MICROPY_PY_NETWORK_WIZNET5K W5100S) in mpconfigboard.cmake to set(MICROPY_PY_NETWORK_WIZNET5K W5500)
And set the default pins in mpconfigboard.h to match my board.

I seem to remember that I had some problems with it hanging and not timing out if there were no network cable attached. But this does not seem to be a problem with the latest build (v1.19.1-129).

@rajtan
Copy link
rajtan commented Jul 14, 2022

Ok, Thanks @Lobo-T
I am using vanilla Pico and standalone W5500 board. Though I am using a different pin combination, but that perhaps is being taken care while creating 1241 SPI object. Anyways, I shall change the pin definitions as you suggest and build using the v1.19.1-129 (recent) build.

Interestingly, this setup had worked with default binary build of 18th March 2022 as provided by the manufacturer.

I shall update the outcome.

@rajtan
Copy link
rajtan commented Jul 14, 2022

@Lobo-T

I shall update the outcome.

Yes, it's working for preliminary tests. Any further issues, I shall communicate back

@beyonlo
Copy link
beyonlo commented Jul 26, 2022

Yes I am very interested! I'm not very good with git so I could use some help. I have cloned micropython and micropython-libs to my computer and pulled the latest master. I've built micropython firmware before and I've used IDF for some time. but when it comes to what it takes to get this driver, I could use some help. slack would be great!

Hello @liudr

Did you have progress to port this driver to run on the ESP32? I'm very interested as well to use the W5100S on the ESP32-S3.

Thank you in advance!

@liudr
Copy link
liudr commented Jul 27, 2022

Hello @liudr

Did you have progress to port this driver to run on the ESP32? I'm very interested as well to use the W5100S on the ESP32-S3.

Thank you in advance!

I never got any help from anyone. If someone is willing to help me get this started, that'd be great. I need some help to do this.

@beyonlo
Copy link
beyonlo commented Jul 27, 2022

Hi @liudr

I never got any help from anyone. If someone is willing to help me get this started, that'd be great. I need some help to do this.

Did you tried to call the @andrewleech on the Slack? I see in the above post that he was available to help you on there. Unfortunately I'm far away to have acknowledge to help you in this task, but I'm sure that he is the right person to help you to this port.

I see that you (at least with nick @liudr) are not in the MicroPython Slack https://micropython.slack.com. If you really still do not have a user there, just create and call him on the channel #esp32 inside MicroPython Slack.

I hope that you can get appropriate help, because to have this driver ported to ESP-IDF will be great, so all ESP32 devices from Espressif that use ESP-IDF will works with this ethernet chip W5100S.

Please, let me know if you got the help :)

Thank you.

@beyonlo
Copy link
beyonlo commented Sep 28, 2022

Hello @liudr Any news about to use this PR driver Wiznet W5100S/W5500 to port/implement on the ESP32 family?

Just to notice you: the MicroPython community has migrate from Slack to Discord, and the @andrewleech is there in the Discord, and I believe he can help to you to start with that, if you still has interest :)

I would like as well so much to use the Wiznet W5100S/W5500 on the ESP32 family, but unfortunately I'm far away for the knowledge to help you.

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

0