TCP/IP Stack (Includes Beta Code - Responds to Pings / ARP)
Harrison.
Posts: 484
I have started working on a tcp /ip stack for the Propeller (since no one answered my last question pertaining to if anyone was working on their own implementation). So far I have implemented ARP and PING. These are simple protocols and are useful for testing. I have tested the ping code with 20+ ping windows open with no dropped packets. The only issue is the response times are > 44ms due to the slowness of the sloppy spin code.
You could use this code to control stuff (send variable length pings to signal different things). This would be very useful since you would get direct feedback if your command was successful via a ping reply. Kind of a simple idea, but hey, its cheap and simple network communication.
I am working on implementing a simple HTTP server. I am having some difficulty with checksums so it may take a while...
Attached is my working PING code and some pictures. The code is 'copyrighted' just in case. You are free to use this in any non-commercial product. (It's highly beta so no one in their right mind would use it in a commercial product anyways).
Edit: I forgot to mention that you must use the ENC28J60 B5 silicon revision. The code checks for this and will not run if an incorrect revision is detected. You may be able to use B2 and B3 if you change the required version constant. B4 is out of the question since it requires > 8mhz spi clock, which I don't think is possible with the prop.
Edit 2: Updated driver. There was a problem with the send_frame where it ended up sending one extra random byte which could lead to the packet being dropped due to bad checksum.
Edit 3: Driver removed temporarily while I put in licensing information and post it on it's own site.
Edit 4: Complete project moved to code.google.com/p/proptcp/. All code is now released under Open Source GPL v3.
Harrison
Post Edited (Harrison.) : 8/29/2007 9:20:01 PM GMT
You could use this code to control stuff (send variable length pings to signal different things). This would be very useful since you would get direct feedback if your command was successful via a ping reply. Kind of a simple idea, but hey, its cheap and simple network communication.
I am working on implementing a simple HTTP server. I am having some difficulty with checksums so it may take a while...
Attached is my working PING code and some pictures. The code is 'copyrighted' just in case. You are free to use this in any non-commercial product. (It's highly beta so no one in their right mind would use it in a commercial product anyways).
Edit: I forgot to mention that you must use the ENC28J60 B5 silicon revision. The code checks for this and will not run if an incorrect revision is detected. You may be able to use B2 and B3 if you change the required version constant. B4 is out of the question since it requires > 8mhz spi clock, which I don't think is possible with the prop.
Edit 2: Updated driver. There was a problem with the send_frame where it ended up sending one extra random byte which could lead to the packet being dropped due to bad checksum.
Edit 3: Driver removed temporarily while I put in licensing information and post it on it's own site.
Edit 4: Complete project moved to code.google.com/p/proptcp/. All code is now released under Open Source GPL v3.
Harrison
Post Edited (Harrison.) : 8/29/2007 9:20:01 PM GMT
Comments
This is great, thanks!·
Any success on those checksums? Some·old Scenix·app notes and source code showed
a clever·routine to do that, in few bytes of code.
Having udp/tcp on prop would be great.
GdS
A propeller based web server. *grins*
HEY!! why not write a propeller based browser in its 4-color glory?
I have seen a browser for the C64 before, it was pretty neat to say the least.
So far I have managed to slap together a really really bad implementation of a tcp server. UDP is working well (it echos udp packets). At this stage, it would be very easy to add simple I/O, but doing stuff like hosting images and files is out of the question since the stack only supports one frame (1500 bytes).
You can try my test setup at wx.fwdweb.com:88/ . Note that it may not be up all the time since I work on it throughout the day when I have time.
Harrison
Post Edited (Harrison.) : 12/22/2006 6:52:13 AM GMT
What's the IC in the breadboard?
Can you interface to a Wifi module?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
www.fd.com.my
www.mercedes.com.my
Or just go for a text based one along the lines of Lynx (but the site seems to be down), better still Links (but this hasn't been updated since 2003) or ELinks, which is still actively being developed. They actually offer a very effective browing experience, and are open source, so you could grab the code to help you along the way.
The PCI card is wired to the chip on the breadboard, the PCI circuitry isn't active.
The IC on the breadboard is a Microchip ENC28J60 (rev B5 or better). It's a purpose built 10bT Ethernet interface chip for 8 bit micros.
The possibility of a WiFi interface is a longshot I think.
-dave
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
This is not a sig. This is a duck. Quack.
I would recommend a prebuilt module from edtp.com or sparkfun.com . I used the schematic from http://www.edtp.com/download/ft/framethrower_package.pdf to wire up my test bench.
Harrison
two little questions:
1. I heared there are some bugs in the ENC28... (Microchip Errata), did you haven't any?
2. are the the transformer values (filter,ratio ...) critical?
- RX Buffer should start at 0x0000 since crossing the 8kb circular buffer end would corrupt the buffers
- Buffer pointers should only contain odd values
- Auto half duplex detection via LED polarity errors
I worked around all these issues in software. The driver now sets most, if not all the parameters so the chip doesn't have to infer any major settings. I haven't run into any odd bugs after fixing the ones listed above.
--
I am not sure how critical the ethernet magnetic ratio / discrete components are. I just hooked the magnetics straight into the ENC chip and used the recommended 47 ohm resistors. I completely omitted the inductor / ferrite bead recommended by Microchip. My setup worked perfectly with my dlink router / switch
If you're willing to spend some money, it isn't hard to interface to Wi-Fi from a micro:
www.lantronix.com/device-networking/embedded-device-servers/wiport.html
www.edtp.com/ (scroll down a bit)
www.dpactech.com/wireless_products/embedded-802.11-wireless-module.asp
The reference to the C64 browser reminded me of the contiki uIP TCP stack. Maybe you can use parts of it for your own stack.
www.sics.se/~adam/uip/
-Ben
Post Edited (couch-pilot) : 12/23/2006 5:25:23 AM GMT
You've done a great work with the Ethernet Stack!!
I have created a little adapter PCB for the ENC28J60 (www.microchip.com -> Samples [noparse];)[/noparse]
It's for the DIL version of the chip and a LF1S022 RJ45 connector with integrated transformer and filters (+2 LEDs)
Here's the schematic and the EAGLE files (schematic and PCB-layout)
gtz
Eric
Also, if you don't have a 25mhz crystal on hand then you can use the Propeller to generate the 25mhz clock. That's what I did because I couldn't find a 25mhz crystal.
Harrison
Where are the connections to the Propeller?
I can't find it.....
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
www.fd.com.my
www.mercedes.com.my
Here are some pointers:
In driver_enc28j60.spin, there is a start method with the paramters start(i_cs, i_sck, i_si, i_so, i_int, clkout) . These are the pins that are used to communicate with the enc28j60 chip. In driver_tcpstack.spin, you will see that the start method calls the enc28j60 driver's start method with pin numbers that correspond with those hooked up to the enc28j60 chip.
The above may be confusing so heres some more info:
start(i_cs, i_sck, i_si, i_so, i_int, clkout)
cs = hook to enc28j60's cs pin (CS)
sck = hook to enc28j60's sck pin (SCK)
si = hook to enc28j60's spi in pin (SI)
so = hook to enc28j60's spi out pin (SO)
clkout = hook to enc28j60's xtal1 in (XTAL1) if you are not using a 25mhz crystal, otherwise leave this pin disconnected
You will need to use your own judgment on how to get this to work. Read the datasheets to make sure you hooked up stuff correctly.
Harrison
Well done, you are making it easier for the rest of us to follow in your footsteps.
I have some premade modules.
Will need to check if they are B5 silicon.
Date code is 05 27, how do I know if it is B5?
From the errata data I need to get it working first to read address 0312 ?
Hmm just read your last post re versions, guess I should just plug it in and test it.
http://www.olimex.com/dev/enc28j60-h.html
Gavin
on the schematic the connections to the prop is on the left side, it's a 8pin connector labeled JP1.
(CS,SCK,SI,SO,RESET,INT,WOL,CLKOUT)
It's mainly copied from the Olimex schematic.
In the Eagle PCB (.brd) file the connector is on the right upper side.
The www.microchip.com Erratas sais that you should use a 2k7 bias resistor (ENC28J60 pin 14) for revision B1 and B4,
and 2k34 for revision 5
- Eric
Also, in theory B4 revisions may work if you are using the propeller to clock the enc28j60 chip. The reason why there was a 8mhz spi clock requirement was due to a clocking synchronization between the 25mhz enc28j60 clock and the spi clock. Using the propeller to provide the 25mhz using the counter modules would in theory mean that the clocks are somewhat in sync so it may work. Then again I could be entirely wrong, but you could always try.
Also, the code posted in the original post only does ping responses. The current revision I am working on isn't ready for release yet.
Harrison
Can you make another schematic and PCB based on ExpressPCB that is easily plugged on as a daughter board
on top of the Propeller Demo board?
I think a lot of people will buy the board from you.
Thanks.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
www.fd.com.my
www.mercedes.com.my
HTTP/TCP with an atmega88 microcontroller (AVR web server)
Harrison
http://www.edtp.com/netbook_page.htm
http://www.edtp.com/airdropbook_page.htm
Or could you recommend some other reading?
Frank
http://mikrocontroller.cco-ev.de/de/avr_webserver.php
They're using an ISA ethernet card (NE2000 or 3COM) as an interface.
Not a bad idea, as you can get this type of cards for free or less
than a buck.
cu
Karl
Frank
I personally haven't used any books as reference material for embedded ethernet so I couldn't recommend a specific book. I usually search on google for examples or refer to wikipedia.
Kloss,
I have used an ISA ethernet card in other designs that utilized a PIC microcontroller. It was a good learning experience, but it turns out that it isn't that easy to get a hold of ISA ethernet cards. I was lucky to have two laying around from old gutted computers, but I looked around for more and couldn't find any. I then gave up and bought commercial embedded ethernet products that costed > $30 each.
Later, I found out that Microchip released their ENC28J60 nic chip that used a simple spi protocol that requires only 4 wires to the host controller. Not only was this controller simple to use, it only costs about 4 bucks in single quantities. This was ingenious and the protocol was so simple that I decided to take another stab at embedded ethernet and tcp stacks. I have already implemented a partial http server (max file size of 1400 bytes due to single packet restrictions), http authentication, i/o port control, udp, and arp send / request. I am hoping to release this stuff eventually (it may take a few months since I am busy with other projects).
Harrison
Thanks for your response. I'll follow through the Wikipedia approach and study your sample code. My immediate goal would be just to replace RS232 and transfer packets of my own data. My knowledge of tcp ip is more through understanding of linux firewalls. I am eager to learn the mechanism of what happens when an new device apprears on ethernet adn how it becomes available.
Frank
I studied the code you posted. I would like to ask if you could say a few words on how 127.0.0.1 discovers the microcontroller's IP address. I found that the NIC gets its MAC address from the ENC28j60 driver and that you put DAT ip_addr BYTE 10.10.0.4 in the code. The IP address is given in many types of packets, but you don't have DHCP implemented yet. So what is the the first thing the PC does to register the IP address?
Frank
Lots of good information for those who may have never seen it.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Brian
uController.com - home of SpinStudio