-
Notifications
You must be signed in to change notification settings - Fork 440
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
Support wired network interfaces (W5500, W5100, ENC28J60) #1703
Conversation
WIP - Builds and can get a DHCP address using W5500. Lots of infrastructure work still required: [ ] Separate CYW43 stuff and LWIP stuff (mutex, etc.) [ ] Add async worker for pumping frames [ ] Real LWIP-only mutex [ ] Should WiFiClient be available as TCPClient? etc. Fixes #775
0a3b969
to
e1274dc
Compare
7620dee
to
29c60ce
Compare
1aca44c
to
49a791e
Compare
@khoih-prog if you could give the 5100 and/or the ENC adapters a test I would appreciate it. Simply replace the header of the example in the lwip_w5500 example with below (and any SPI pinout adjustment):
I'll add in some |
acc3a19
to
8d98a9d
Compare
Removes WiFiClass code from pure LWIPEthernet sketches.
Make sure to remove any handlers we used to have from our ethernet processing loops.
Hello ! Thanks you for doing this feature ! I'm trying to implements the Lwip stack with this library, https://github.com/hideakitai/ArtNet, by using the WifiUDP implementation, but I have a strange error compilation. /Users/nico/.platformio/packages/toolchain-rp2040-earlephilhower/bin/../lib/gcc/arm-none-eabi/10.3.0/../../../../arm-none-eabi/bin/ld: /Users/nico/.platformio/packages/toolchain-rp2040-earlephilhower/bin/../lib/gcc/arm-none-eabi/10.3.0/../../../../arm-none-eabi/bin/ld: DWARF error: can't find .debug_ranges section. Full error here :
Any idea ? Thanks ! |
I suggest trying the w5500 example first. That is built by the CI and is tested to work by me. The UDP example was also run by me today (after adjusting to use ETH and not WiFi). The logs look like youree trying to build for the PicoW or calling WiFi.xxx but without an MCVE all that can be done is guess. You should be building for the stock Pico or your specific board. |
You are right, it's seems the library do some strange imports for the Pico W, so it's not working. Also, for now, the lwip stack seems to not be the best solution for my problem, because I don't see where I can change some settings that I can change in the Ethernet library (Like the ETHERNET_LARGE_BUFFERS). I will try to keep to the Ethernet library for now. thanks for your answer. |
Your call. We're using the Ethernet adapters as dumb NICs just like the Wi-Fi chip, so things like ETHERNET LARGE BUFFERS don't make sense. The main Pico memory is being used, not the onboard adapter sram. To make the library work proper you'd probably just need to tweak the Pico W port not to use Wifi. and instead use Eth. |
The DNS lookup in LWIP doesn't specify a netif, so a single call is all that's needed. No need to keep a list of DNS lookup callbacks.
Unfortunately, it's half working for me. I've done like you said, tweaking the library to use "WifiUdp" class instead of "EthernetUdp" class, and everything is fine, I can receive the data and send data using the lwip stack, like I want, but it's too slow for me. I send really a lot of packets in a short amount of time, and I need no latency. And everything is really slow in comparaison to the Ethernet library, like just the ping function. Example : this is the result of a ping with the lwip stack. No data is send to the pico, I'm just binding my udp port with the WifiUdp class
This is the result of a ping with the Ethernet stack, same case, binding the udp port using the EthernetUdp library, same setup
To setup the stack, I'm using the code you provided in the WiFiClient-W5500 example Do you have the same ping result as me using the lwip stack ? Thank you |
As Knuth said, "Premature optimization is the root of all evil" 😆 I've been focused on functionality and stability and not performance so much. That and not breaking WiFi (since all share the same backbone now). I have a feeling increasing the SPI speed would improve things a lot. I just used whatever the default is for the examples and did not try and find a datasheet to figure out the W5500's max speed. I'm also doing a check of the W5500 at 50ms intervals which could easily be made to 10ms or 5ms in LWIPEthernet:138. That also pumps LWIP, meaning you might have an average of 20-25ms between receiving something in the ethernet module and seeing it in the Pico. I suggest changing that Also, just generally WRT to pings, is that handled inside the W5500 itself and not the Ethernet library? That might be the case...we use the dumb NIC model since we already run LWIP here so a ping needs to get read in from the outside world (at 50ms heartbeat) and then responded to (which would happen almost immediately once it was read it, but you'd still wait that ~50% of a period on average). |
Yup, we're running default Arduino SPI clk of 4MHZ in this driver. The W5500 datasheet says this about SCLK (33MHz):
|
Ok I understand ! I will take a try. I think you have the point, the SPI speed is too slow for my usage at this time. For the ping function, I don't really understand how it's works in the W5500, so I can't tell. Do you know where I can change it ? it's seems that in the SPIClassRP2040 the clock divider function is deprecated, I really have no idea how in this driver or in arduino in general we can set the SPI clock, so maybe I don't have the point Thanks ! |
Changing to a 5ms heartbeat for LWIP:
Increasing SPI speed to 30MHZ
not much of a change
Making LWIP run 1K/sec (1ms):
Probably can make the SPI speed a per-driver option, and the LWIP cycle a per-system one. |
And for crazy fast, 1ms delays, 30MHZ SPI, and overclocked Pico:
|
Given those #s, I'd say |
Also, the currentW5500 driver does not use the IRQ line. Using the IRQ line would allow for a lot of the lower LWIP latency w/o needing to run a polling operation every 5ms or so. But, again, that just wasn't implemented in the ESP8266 core I'm taking this from AFAIK. |
Just tested it, it's better with these settings ! But also, no enough fast for my usage (I'm sending a lot of UDP packets to test it), and the Ethernet library is doing a better job I control a led panel using these udp packets, so I can really see where it's not working. Like in this video, we can see that some packets are dropped panel.mp4I think, maybe it's related to the IRQ line, or maybe, it's because we don't use the onboard adapter sram to do some fancy stuff, so some buffer is overloaded and packets are loose. I don't really understand what's going on here, but, with these settings that we experiments, I'm near the performance that i've got using esp32 and LAN8720. |
Supports higher SPI SCK by an app
Ah well, too bad. The In any case, much thanks for reporting this. It was trivial to add user configurable options (and give better default timers). Doing so improved the responsiveness of the web server (I can get >30 page refreshes/sec in the AdvancedWebServer at 133MHZ CPU), so 50ms was really a bottleneck I think. |
@earlephilhower you are awesome ! |
The WizNet 5100S EVB Pico also tested and working with the following setup
|
Allows wired networking support for all the WiFi-related classes (WebServer, WiFiClient, WiFiServer, etc.)
Supports WizNet W5500, WizNet 5100, and ENC28J60 modules.
Fixes #775