W5500 Driver for the P2
lab_ges
Posts: 91
in Propeller 2
Hi All, I need a P2 driver for the W5500 SPI to ethernet chip for a project I am working on and was wondering if anone has looked at this before?
I like to look of the P1 version in OBEX but have no idea where to start converting the Machine code from the P1 to the P2. I can just about cope with SPIN1 to SPIN2 conversion but have no idea how to start converting the PASM1 part to PASM2 at this time.
Are there any Tutorials / hint sheets relating to converting existing PASM1 into PASM2?
Any tips apreciated, thanks all.
Comments
I wrote a driver for the W6100 that supports SPI. Let me take a look at the W5500 datasheet and see of different it is. We might be able to get it working easily.
Looking at the datasheet they look almost identical. This post, essentially says the same thing.
I think I may have a W5500 in an Arduino shield that I bought in the RadioShack going out of business sale years ago.
Here's a driver I wrote a while back for the WIZ550io module to function as a client for a project, since expanded to use as a server just to play around with.
Wiznet W5500 server demo
@ChrisGadd very nice!
Wow, thanks very much @ChrisGadd & @ke4pjw.
Sorry it has taken me several days to reply but I left that message on Friday afternoon here in the UK and I was busy all weekend & it is now Monday morning before I could get back into it.
I searched the OBEX for W5500 on the P2 and got no results, I never thought to do a search for Wiznet5500 or even just 5500 & P2.
I even searched the forums and saw a few discussions but nothing about the P2.
That will save me a lot of work, as at the same time I am trying to learn to program the P2 for the first time.
All my previous projects have involved the P1 but I couldn't resist trying the P2 on this occasion.
Thanks again, I hope I can help out in some way on a future ocasion.
Hi @ChrisGadd
I have been looking through your "Wiz550io driver.spin2" code.
In PUB init() you do a divide by 20_000_000.
I am still trying to understand smartpins but I assume this is refering to the standard 20Mhz P2 clock?
Can you confirm that please? My board has a 25Mhz clock, so I guess I need to divide by 25_000_000 instead?
This line
is setting the SCK pin to transition mode which when used to generate pulses, results in a 10MHz clock (2 transitions per clock phase). In transition mode the X register holds system ticks between transitions. In this case the timing will be 1/20_000_000 second (clkfreq is ticks in 1 second).
I ran this as a test:
As you can see in this image, 50 transitions created a pulse train of 25 pulses at 10MHz
When I uses smart pins to create a clock, I use pulse mode, but it requires a little extra setup because you're setting the period and low time separately. This is a clock setup blurb from a P2 SPI project
I'm not suggesting you change Chris's code -- just letting you know there are other smart pin modes that can be helpful.
Thank you very much @JonnyMac, that is the clearest description I have seen anywhere for smart pins (for transition mode anyway) and I have been looking for a while.
I worked out for myself that it was "transition mode" after manually doing this bit Bitwise OR Using the information in "Smart Pins rev 5.docx" at
https://drive.google.com/file/d/1iTA4dwbntgaUVnpt0-9pDcFCVSsvCUnU/view
So I had a good try, but had no real understanding of what that meant, other than it was fairly obviously generating the SPI clock.
I was stumped reading the "Smart Pins rev 5.docx" on-line as the images overlay the text so i couldn't read the words.
I just tried downloading "Smart Pins rev 5.docx" and it reads OK locally in Word.
Thanks again for your assistance, very helpfull as always.
Glad I could help. An important detail in that information from Jon Titus is that the timing between pulses is limited to 16 bits.
Hi All,
I am not sure many here can help anyone familiar with Ethernet might be able to see where I am going wrong as i am guessing few would have access to both a P2 board and a W5500 module?
I have been struggling a bit since I haven't used a P2 or TCP/IP before and all the Demo code I can find seems to be for HTML which I am not using.
I am using Chris Gadds 's W5500 driver to simulate 2 serial to ethernet ports to 2 x Tera-term (TT) TCP/IP Terminal Programs for now.
This program is just as a test of concept to get things working before moving on to more complex things, but even this has me stumped.
It took me a while and lots of reading but I did get these 2 x TCP server ports working (with static data for now) but for some reason Port 7351(Socket1) data stops if I close the TT terminal for Port 7350(Socket0) and I have been unable to find anything in the code to explain this, to my eye (half blind admittedly), the two sockets should be able to operate independently, so that closing one shouldn't affect the other, but in my program it does?
My problem is I don't know what to check or if there is an obvious reason for this, my guess is I have configured something wrong setting up the two TCP ports but they work if I open the TT terminals in order Port 7350(Socket0) then Port 7351(Socket1), or if I re-open Port 7350(Socket0) then Port 7351(Socket1) will once again start receiving data (it also receives garbage at this point which is probably a hint if I were smart enough to recognize it as such).
I know this forum is full of better programmers than me so i am hoping there is something here that is obvious to someone out there.
Thanks all
Just a quick glance:
Why is it local_port + _socket? Should just be local_port I would think. Socket is the virtual socket within the Wiznet. local_port is the actual port used by TCP/IP, right?
Nevermind, I think I see what you are doing there.
Change
local_port word 7350
to
local_port long 7350
and see what that does.
Also, I would make TCPmsg longs.
Thanks @ke4pjw, your hints are appreciated.
I hope you don't think I have been ignoring your suggestions, since i am in the UK that message was sent at the end of day on a Friday, I am not sure where you are located but I would guess the USA and made those comment near the start of your Friday. I am back at work now on the following Monday.
I see no difference there, 7350 will fit into a WORD or a LONG
I have also tried changing this pointer to a LONG but again no difference.
I have left both as longs for now but the programs operation is still the same.
I need to start looking at the packets I am sending (wireshark??) and work out exactly what is changed on port 7351 after 7350 is shut down, and then work out why.
For future programmers, below is what I am seeing on my debug terminal with comments <> after significant lines the ... just means the same thing keeps happening on the same lines below till noted.
Again, thanks for your input, I work in isolation on this so this forum often points out things others see as obvious and I value the different perspectives given.
I found a bug in the sendBuffer method:
I only ever used socket 0 while playing with the webserver demo so I never encountered that bug, corrected it and now the demo works on all sockets.
Thank you @ChrisGadd, I was looking into why socket 0 was significant but it would have taken me some time to get to that correction.
My Program (as detailed above), is now working as expected with that small but vital change.
<For any future searchers, my code above sets up 2 TCP/IP ports and sends different strings to each (will be replaced with real serial data soon).
Either port can be opened or closed independently as needed to receive the data from that source, I can see no reason why this can't be expanded to the full 8 sockets supported by the W5500 chip.
For testing I am using 2 separate instances of the excellent TeraTerm program on Ports 7350 & 7351 (random un-allocated TCP port numbers) as shown below. From past experience these TeraTerm settings work with any serial over Ethernet data and that is what I want my board to emulate. Ultimately, I would like to convert the code and serial Rx routines to machine code to reduce serial latency but that is really out of my comfort zone at this point in time..>
Can I request that someone update the driver on OBEX4746?
Is there a process to offically correct / update the OBEX? Is this up to the Authors or Parallax?
A slight name change could also make this more findable too, as I couldn't find it till Chris pointed me too it, see top posts above.
The other Wiznet drivers all have the chip number as part of the title, I could have / should have searched for WIZNET but didn't so the only W5500 driver I could find was for the P1.
I realise Chris wrote this for a specific Wiznet Ethernet board, but I don't use that board, mine was a generic chinese W5500 board.
A (W5500) somewhere would have made it much more searchable, something like Title: "WizNet (W5500) 5500io Driver"?
Thank you Chris for a great driver and the support.
I'm glad that worked. I'll update the obex title and files.
@lab_ges No worries. My concern was more of about alignment, as it appears A word (local_port) was being added to a long (_socket). I have seen goofy stuff happen when doing that. I am happy @ChrisGadd was able to spot the bug and get it fixed!
--Terry
Thanks for that comment Terry.
I had missed that point completely, I was thinking purely on the lines of a container size, i.e. will it fit rather than how it relates to the item that is being added to it.
I need to pay more attention as sometimes these things can turn arround and bite you.
It is a long now and I will leave it like that!
As a side note... There appears to be a W5500 driver built into micropython. Going to be testing that soon, hopefully,...
I got it mostly converted to pasm for ya, but I don't see any significant difference with your test program regarding latency. Didn't really expect to; all of the time-critical stuff was already in in-line assembly.
It's considerably slower with my web-page demo at the moment, but that's due to the way I'm sending packets.
The Spin-based driver allows for an entire message to be constructed in the buffer which is then sent in one block, as opposed to the (current) PASM version that sends data as soon as loaded into the buffer, resulting in many short packets. That's also the reason for each socket having its own wr_ptr and fsr registers.
Unfortunately, the W5500 Sn_WR_PTR and Sn_FSR registers are only updated following a SEND command; the value written into Sn_WR_PTR cannot be read back out, and so cannot be used to keep track of position inside the buffers.
I'll see about adding that capability into the PASM object after I get back from a long weekend.
Hi Chris, I hope you had a good long Weekend.
I just had a 4 day long weekend myself, and went for a quick visit to Hadrian’s Wall. I love the Roman ruins along the wall, it is a very special place.
Thanks for the continued code development, it is much appreciated by me and I am sure by others here.
Nothing I said above was meant as a criticism of your driver, which, as you say, already buffers the inputs before it is sent.
My concerns about latency were really related to my code writing ability rather than yours, since in my example code I am just sending constant known string values, which is relatively easy.
I need to add code that will read several serial ports (up to 8) and send them to Ethernet via your driver, all hopefully while not adding too much latency to the incoming serial data, but that is still a work in progress.
PS Chris, Don't let me stop you from adding the above changes to the PASM version.
That could be handy to a lot of peope.
If you do finish it, I will happily use it and help you test it.
I have been working on this in the background with Chris Gadd and now wish to conclude this discussion with the working code, see attached ZIP file.
My thanks goes to @ChrisGadd for his help with this code and specifically his wonderful W5500 driver, he has worked tirelessly on this and has now updated his driver on the OBEX [OB#4746].
My thanks also to @"Stephen Moraco" for his "isp_octoport_serial" [OB#4257] that is used here to handle the 8 serial ports. Chris did notice a slight issue with using the Octoport Driver:-
So he made a change to compensate for that:-
Thanks too to @JonnyMac for his "jm_fullduplexserial" [OB#2842] and lots of additional help to me and other community members.
Thanks everyone, I hope this might be of assistance to someone else in the future.