uC Ethernet & TCP/IP

The test software has proven that the driver for ENC28J60 is able to transmit and receive ethernet packets. Now its time to fill those packets with something usefull.

The protocol of choice has got to be TCP/ IP, its been around for years and used across a variety of technologies.

To make use of TCP/IP, a software stack is required. That is, a collection of files that will implement the TCP/IP protocol.  Fortunately there are a number of stack already written designed to run on embedded systems. Some of these stacks form part of embedded operating system others are stand alone..

The stack used for uCEthernet is uIP 1.0 written by Adam Dunkel. This was chosen for number or reasons.

  1. Its free.
  2. Its well documented.
  3. Relatively easy to implement.
  4. No operating system required

To get the stack up and running on the LPC2106 using the ENC28J60 MAC  requires a little bit of work but not a huge amount.

I spent a bit of time over (aproximately a week) getting an understanding of how the stack works.  Its pretty neet!

The documentation details what is required to port the stack.

A clock.c function is required (or something similar), which is just a simple timer, I used Timer0 to fire an IRQ every 100mS.  This timer is used to drive some of the internals of the stack.

A driver for the MAC is required, I needed to tweak what I'd done for the test code  (Page 5). i.e. use the uip_buf rather than passing ptrs through the procedure calls.

Finally the configuration options need to be set, the configuration file sets variables like number of connections allowed, whether UDP is required etc. It allows the stack to be configured to use as little or a much of the micro's resources as required.

After doing as the documentation suggested I was hoping it was all going to be plain sailing from there on in. ha, not quite!

I hit a few snags. The main trouble I ran into was with a structure decleration. (It took me a good few days to figure this out!)

The internals of the gcc compiler will, in certain structure definitions, add pading between the fields so that fields lie on 32 bit boundaries. This generally speeds things up. However in the case of uIP this causes a few snags. The structure definitions require that they are packd together with no padding. This can be achieved with an (_attribute_(packed)) compiler directive.

With this directive in place, I was able successfully compile and run a Telnet session.

I currently have a a demo that you can log into. Its not particulary fancy but it does demonstrate the LPC2106 running uIP using the ENC28J60 its connected to my home router hence the no-ip.biz domain.

To test the demo, start a Telnet session and connect to  uCEthernet.no-ip.biz. I have only implemented two commands CC - Current Conection and TC - Total Connections. If it doesn't work let me know.

Page 7