Shop OBEX P1 Docs P2 Docs Learn Events
TCP/IP Stack (Includes Beta Code - Responds to Pings / ARP) — Parallax Forums

TCP/IP Stack (Includes Beta Code - Responds to Pings / ARP)

Harrison.Harrison. Posts: 484
edited 2007-10-09 00:19 in Propeller 1
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
1200 x 711 - 119K
923 x 707 - 174K
876 x 666 - 108K

Comments

  • GdSisGdSis Posts: 12
    edited 2006-12-21 05:14
    Harrison,

    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
    Harrison. said...
    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.

    Harrison
  • Harrison.Harrison. Posts: 484
    edited 2006-12-21 05:26
    I think my checksum problem was related to me sending an incorrect number of bytes in a packet. I am going to try udp first since tcp is so dang long with its annoying syn, ack, fin, etc flags. I am hoping to eventually hook this up to some christmas lights and controlling it via network.
  • Ym2413aYm2413a Posts: 630
    edited 2006-12-22 00:28
    Oh, this is cool.
    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.
  • Harrison.Harrison. Posts: 484
    edited 2006-12-22 06:48
    A web browser would be pretty cool. It would take some work making a much more robust tcp stack to be able to run connect to other servers.

    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
  • william chanwilliam chan Posts: 1,326
    edited 2006-12-22 08:26
    How did you manage to wire it to a PCI card?
    What's the IC in the breadboard?
    Can you interface to a Wifi module?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.fd.com.my
    www.mercedes.com.my
  • ciw1973ciw1973 Posts: 64
    edited 2006-12-22 09:24
    Ym2413a said...
    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.

    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.
  • Dave PatonDave Paton Posts: 285
    edited 2006-12-22 14:11
    william chan said...
    How did you manage to wire it to a PCI card?
    What's the IC in the breadboard?
    Can you interface to a Wifi module?
    I'm not the OP, but a little close examination netted me these tentative answers:

    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.
  • Harrison.Harrison. Posts: 484
    edited 2006-12-22 16:52
    Dave is correct, I am not using the PCI interface on the computer NIC. I am only using the ethernet magnetics (the rectangle on the PCB labeled FB2022) and the ethernet jack (the silver box with the RJ45 cable plugged in).

    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
  • CatweazleCatweazle Posts: 17
    edited 2006-12-22 20:09
    Very exciting!

    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?
  • Harrison.Harrison. Posts: 484
    edited 2006-12-22 20:35
    The only problems I ran into with the current B5 rev were:
    - 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
  • acantostegaacantostega Posts: 105
    edited 2006-12-23 01:25
    Dave Paton said...
    william chan said...
    How did you manage to wire it to a PCI card?
    What's the IC in the breadboard?
    Can you interface to a Wifi module?
    I'm not the OP, but a little close examination netted me these tentative answers:

    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

    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
  • BenoitBenoit Posts: 47
    edited 2006-12-23 05:18
    Really cool project.

    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
  • CatweazleCatweazle Posts: 17
    edited 2006-12-25 00:21
    Hello,

    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
  • Harrison.Harrison. Posts: 484
    edited 2006-12-25 04:25
    Very nice. I might eventually make a breakout board for the chip so I don't have to bother with the mess I have right now.

    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
  • william chanwilliam chan Posts: 1,326
    edited 2006-12-26 02:20
    Catweazle said...
    Hello,

    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

    Where are the connections to the Propeller?
    I can't find it.....

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.fd.com.my
    www.mercedes.com.my
  • Harrison.Harrison. Posts: 484
    edited 2006-12-26 04:37
    This is highly beta code so you will have to look around in the source to see how to configure the mac address, ip address, and i/o.

    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
  • GavinGavin Posts: 134
    edited 2006-12-26 07:26
    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
  • CatweazleCatweazle Posts: 17
    edited 2006-12-26 14:59
    William,
    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
  • Harrison.Harrison. Posts: 484
    edited 2006-12-26 20:58
    About revision compatibility: The NIC driver start() method has a few lines of code which read the revision register and compares it to the required revision number (B5 in this case). If you find out the driver isn't loading then try commenting out those lines and seeing if it works.

    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
  • william chanwilliam chan Posts: 1,326
    edited 2006-12-30 01:59
    CatWeazle,

    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
  • Harrison.Harrison. Posts: 484
    edited 2006-12-30 17:38
    Interesting links. I used http://www.edtp.com/download/enc28j60/enc28j60_driver.zip while working on this since I am much more familiar with the PIC line of micros and C compilers. In any case, I resorted to using a tcp scheme thats extremely simliar to the one described in the http/tcp with the atmega micro link you posted.

    Harrison
  • TransistorToasterTransistorToaster Posts: 149
    edited 2007-01-11 23:46
    What documents should one read to become more familiar with embedded ethernet. Do you know these by Fred Eady and if so, which one is better:

    http://www.edtp.com/netbook_page.htm
    http://www.edtp.com/airdropbook_page.htm

    Or could you recommend some other reading?
    Frank
  • KlossKloss Posts: 43
    edited 2007-01-12 10:24
    Take a look at this:
    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
  • TransistorToasterTransistorToaster Posts: 149
    edited 2007-01-12 17:51
    That ISA card usage with the Realtek RTL8019 chp is quite interesting. Do you know of any documentation that doesn't require the Babelfish translator?
    Frank
  • Harrison.Harrison. Posts: 484
    edited 2007-01-12 18:07
    TransistorToaster,
    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
  • TransistorToasterTransistorToaster Posts: 149
    edited 2007-01-12 23:46
    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
  • TransistorToasterTransistorToaster Posts: 149
    edited 2007-01-18 15:58
    Harrison,
    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
  • parts-man73parts-man73 Posts: 830
    edited 2007-10-09 00:19
    I thought I might bump this old thread due to it's relevance to the new PropNIC

    Lots of good information for those who may have never seen it.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Brian

    uController.com - home of SpinStudio
Sign In or Register to comment.