P2 Ethernet
JohnC
Posts: 64
Anyone currently working on ethernet for P2? Seems like a Wiznet W5500 coupled with a port of the old Spinneret webserver code would be useful.
John
John
Comments
http://forums.parallax.com/discussion/170022/enc28j60-ethernet-driver
This does a robust UDP client and server. Harrison had to really strip down his TCP implementation to fit it in 32K, so a much better solution could probably be fleshed out for P2, but I mostly use UDP in my projects anyway.
https://www.mouser.com/datasheet/2/268/39935b-29829.pdf
Another option, also from Microchip:
KSZ8851SNLI
https://www.mouser.com/datasheet/2/268/00002381a-1138397.pdf
Hopefully, Harrison's code could be adapted for this chip, as suggested...
I like the idea of offloading much of the stack and its logic to a separate processor. Wiznet has a pretty substantial Github these days which definitely didn't exist the back when P1 was getting started.
https://github.com/Wiznet/W5500_EVB
https://github.com/Wiznet -
Firmware flash over ethernet, and moving forward, some sort of encrypted firmware delivery service like what Dr. Bob has come up with (http://www.tracesystemsinc.com/sums/sums-overview.html) would be really useful. And yes, I know P2 itself can't be code-locked.
Found the Eagle footprint here: https://github.com/Wiznet/EagleCAD_library
Not of fan of it not coming with a MAC address though...
The ENC424J600 comes with a MAC.
Actually, I guess I'm still on the fence on which way I'd go...
If you need an unique MAC address have a look over this microchip parts (they come factory pre-programmed with 48 and 64 bit MAC)
Flash: 16Mbit 32Mbit and 64Mbit
They have also a series of lower size EEPROMs with the same MAC address options
Of course they have Microchip OUI
@Roger in all your travels have you ever met a modern switch that wouldn't negotiate down to 10bT? I've not seen it myself, just heard rumors in other forums.
Yes, the MAC address is pre-programmed in the flash. It is a globbaly unique MAC with Microchip OUI (the first 3 bytes which identify the producer)
Beside the MAC it have also a nearly 2KB of user OTP area. Except for this is a normal flash that is accessed via SPI and/or SQI. I presume it could be used for P2 boot
Performance wise I am finding that the w5500 is very snappy and especially so on the p2 with the higher bus speeds that are possible. Before I used to dole out a file sector by sector but I can see now that by increasing the block size using multi block card reads that it will be even snappier. But all of this including the TAQOZ console are working out of the same cog and when I move the server into its own cog it should be even better.
EDIT: I've attached a screenshot from Wireshark during an FTP transfer which at present seems to indicate a 512 byte packet every 650us or so. Using a continuous non-breaking multi-block read with 2k packets should make it really zip.
The whole server code including diagnostic routines and the W5500 driver take up just a tiny corner of memory, less than 6KB:
Pin toggling speed is more than enough, but I don't know how much layer 2 functionality you can fit before you start taking a significant chunk of resources.
Given that the Wiznet W5500 chip in single unit pricing is ~AUD$4 from Mouser, and there are a number of fairly mature SPI solutions for the P2, what circumstances would motivate for this approach?
As far as transfer speeds go, MII is 25 MHz nibble oriented transfers. The P2 can do this even with bit banging, though overclocking will help as will making use of the streamer. I believe ozpropdev is bit banging a 8 bit HyperRAM bus faster than this.
RMII is two bits at 50MHz. Probably quite doable as well but more shifting is needed and there are not really that many native instructions to work on two bit quantities unlike nibbles, so you might need to accumulate them in software somewhere with your own shifting and that adds overhead. The streamer does have support for two bit quantities so it might do this for you.
RGMII is 125MHz 4 bit DDR. This could be pushing the P2 a bit on receive side processing but raw transmission out at this speed could be doable, given the chip is already capable of outputting DVI data at a similar 250Mt/s. You may of course then have to start to deal with signal integrity issues and board layouts etc.
Now while the P2 can probably transfer the raw data in and out at these rates, there would be additional overhead needed to do the framing and other control signal processing, any CRC etc. That's where it will get more interesting, and you may not be able to do line speed for long (which is probably ok if you can use Ethernet flow control or just allow TCP to try to rate adapt for the consequent packet loss if you are doing IP and have an IP stack to go with it).
The biggest issue here is probably the clock source for receive data from the PHY. It would not be the same as the P2 clock if the P2 has its own crystal oscillator, and it will be derived from the recovered incoming data. I don't think the P2 can reliably clock data in that is asynchronous to it, as it's always synchronously sampled in using the P2 clock, right? However if you were to clock the P2 from the 125MHz or 25MHz received clock from the PHY and this clock remains active the entire time and doesn't shut off in between packets, that perhaps that could potentially work.
Would be an interesting project to try...and supporting full duplex would need at least two COGs of course.
I'm not sure what speeds P2 USB can sustain, but USB is somewhat proven on P2.
Or, maybe a more common part like W5500 or W6100 can do 'good enough' Ethernet ?
To begin I'm working with this fork of Wiznet's GitHub:
https://github.com/sstaub/Ethernet3
...which so far (I think) just requires edits to the Arduino SPI library:
https://github.com/arduino/ArduinoCore-avr/blob/master/libraries/SPI/src/SPI.h
I'll start with bit banging, then move up to using smart pins and the streamer.
Finally I'm hoping to recreate most of the functionality of their Wiz-web platform, including web page serving via SD card or flash and remote firmware flashing over ethernet.
https://github.com/Wiznet/WIZ550web
Anyone interested in playing along? Or maybe I'm unknowingly duplicating a stack of existing work?
@"Peter Jakacki" Super naive question here, but can Taqoz run other objects (C, spin...) in other cogs? Clearly I need to do more research.
John
I have some of these devices linked below myself and plan to use one with the P2D2 at some point after it arrives in my own custom project. Having some code that can drive the Wiznet5500 devices would be great.
https://forums.parallax.com/discussion/157167/iot5500-p8-ethernet-server-lan-ant-ultra-compact-module
The Arduino codebase is C++, are you going to run with that language or translate to something else first? Which C++ compiler are you targeting for P2? P2gcc?
I've not yet looked into the code for adding socket support etc myself. But it makes sense to base it off something already available, or at least learn from that first before doing a P2 version if there are things you can do to optimize for that, or if porting APIs to SPIN2 etc. I imagine Peter Jakacki probably already has some Forth code that can drive these modules too. That could be of use if you know Forth and want to work in that environment.
Then I have a W5500 layer on top of that which can access the registers the same as it would memory, so dumping and changing values interactively is very possible. There are also the fast block transfer routines too of course which can write at 3MB/s @250MHz and there are the little extras to look after the W5500 quirks.
Write from 0 in hub to 0 in the currently selected W5500 memory for 2048 bytes while using LAP to time and report it.
You can assign the pinout at runtime so it is also possible to have multiple devices running and you can configure IP and other settings interactively. (The & prefix is to force dotted decimal notation which is also useful to pass up to 4 parameters in a single long when setting pins for instance)
On top of this is the socket interface, named registers and modes etc, a basic Telnet layer, and then FTP and HTTP server layers. It is possible to execute Forth code remotely too and the Telnet socket defaults to a Forth console anyway.
By default the software reports activity and status to the serial console and extra message layers can be enabled.
So, even if you don't program in Forth, there is no reason why you can't "use the Forth".
Making a version of this stable on Prop2 would be pretty useful to the community. In my own applications, I need a couple UDP or TCP sockets, T/FTP, and a webserver.
https://github.com/Wiznet/W5500_EVB
Of course the old Spinneret code is still around as well at https://www.parallax.com/product/32203. I gave up on it years ago because so much codespace was chomped up by the SD and webserver code that I didn't have much left to do what I needed.
Also, it looks like the riscvp2 compiler will handle C++ code but I don't know if I'm smart enough to get it stable: http://forums.parallax.com/discussion/170295/riscvp2-a-c-and-c-compiler-for-p2/
I wonder if ultimately something could be developed to run as a standalone "Network COG" that provided network services to other COGs written in other languages via simple hub RAM / mailbox type API calls. Then you could develop it in whatever language you wanted and other environments could still make good use of it. The key thing to do then is probably the development of a generic useful API that covers almost all use cases.
My case is a bit special. I don't need an IP stack but access to the raw packet level. But I think that would be no problem. Once the SPI and register level driver is working there should also be a way to bypass the IP stack.
Then dumped the socket registers and part of the receive buffer to check it a bit more.
I will have to play with that part of it a bit more yet in the morning but I will try out UDP as well.