Homepage Wiki Forum Buy

Ethernet over SPI

From GNUBLIN

severity (level) requirement Gnublin family
Gnublin logo easy.png load kernel modules, network basics Alle

Contents


Quickstart

Now it's also possible to have ethernet connected to GNUBLIN via SPI:

Module enc28j60.jpg

Therefore you only need to buy an ethernet-spi module from the embedded projects online shop.

http://shop.embedded-projects.net/index.php?module=artikel&action=artikel&id=89


You can find the datasheet of the ENC28J60 at following link:

http://ww1.microchip.com/downloads/en/devicedoc/39662a.pdf

Note: The ribbon cable has a red mark on one side. This must be on the Gnublin board where GPA0 stands.

Here we go in the area for beginners.

For beginners

First you have to connect the ENC28J60 with Gnublin.

At the beginning of course you have to load the correct driver.

Note: All SPI driver as CAN, ENC28J60, etc. must first be unloaded! (e.g. modprobe -r enc28j60 or modprobe -r spidev)

modprobe enc28j60

Output:

enc28j60 spi0.0: enc28j60 Ethernet driver 1.01 loaded net eth0: enc28j60 driver registered

Then you can assign an IP address manually

ifconfig eth0 up

Output:

net eth0: link down net eth0: multicast mode net eth0: multicast mode ADDRCONF(NETDEV_UP): eth0: link is not ready net eth0: multicast mode root@gnublin:~# net eth0: link up - Half duplex ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready net eth0: multicast mode

Or you let do it automatically bei DHCP:

dhclient eth0

One you are supplied with an IP address, you can ping your own router (replace your own router's IP address

ping 192.168.1.1

Output is:

PING 192.168.1.1 (192.168.1.1): 56 data bytes 64 bytes from 192.168.1.1: seq=0 ttl=64 time=19.572 ms 64 bytes from 192.168.1.1: seq=1 ttl=64 time=7.373 ms 64 bytes from 192.168.1.1: seq=2 ttl=64 time=7.395 ms 64 bytes from 192.168.1.1: seq=3 ttl=64 time=7.306 ms --- 192.168.1.1 ping statistics --- 4 packets transmitted, 4 packets received, 0% packet loss round-trip min/avg/max = 7.306/10.411/19.572 ms

Once you have carried out a ping to host successfully, the ENC28J60 was successfully connected and initialized.

Nameserver manually set

In the file /etc/resolv.conf you have to type following entry:

nameserver 8.8.8.8

The IP address 8.8.8.8 is the DNS server from Google.

Set default route manually to get into the Internet

To route all the Internet packages to the internet, you have to set a default route

route add default gw 192.168.1.1



for advanced

NOTE This section applies to a kernel prior 11.2012 In any newer kernel everything was already supplemented and optimized.



preparations

To connect the adapter only 7 lines are required. The following diagram illustrates this, along with the pin names.

Schaltung draw2.png

If you are not familiar with the structure of hardware, so you can also use the [completed module] down from the shop. This is simply connected via a 14-pin ribbon cable with GNUBLIN.


For all who have never modified the kernel this would be the perfect start. The connected adapter generates an interrupt, to react to the board, and this function in normal LPC3131 kernel does not exist, you have to modify the kernel. The following section describes STEP BY STEP how this interrupt is initialized in the kernel!

Da noch ein Chipselect Pin benötigt wird und das Löten bei der normalen GNUBLIN Version sehr riskant ist(da der Testpunkt sehr klein ist), wäre es momentan besser die Extended Version zu benutzen, da hier alle Pins nach außen geführt sind. Jedoch wurden auch für die normale GNUBLIN Version kleine Testpunkte angelegt wie man im folgendem Bild sehen kann.

As an chip select pin is needed and the soldering at normal GNUBLIN version is very risky (the test point is very small), it would currently be better to use the extended version, since all pins are brought out. But also for the normal version GNUBLIN were small test points created as you can see in the image below.

250px‎



Modifications to the kernel

How you have seen on the draw, the SPI chip gots one interrupt line (5 - INT). The interrupt is used in order to tell GNUBLIN, that data has just arrived over ethernet and are ready for collecting. But the standard kernel doesn't have any interrupt pin for, so no interrupt will be handled! In this article we will use the GPIO11 PIN.

Event Router

The LPC3131 has an interrupt controller, and an event router. Most peripherals (except timers, I2C, DMA, MCI and others) goes directly into the event router (Events) and this then generates on one of its four outputs a signal to the interrupt controller.

Initialize interrupt in the kernel

here only 4 changes have to be done, to tell the kernel that there is now an interrupt pin.

First you have to add the following (in file arch/arm/mach-lpc313x/include/mach/irqs.h):

.
.
.
#define IRQ_WDT        30  /* Watchdog interrupt */
#define IRQ_VBUS_EN    31  /* VBUS power enable  */
#define IRQ_VBUS_OVRC  32  /* Detect VBUS over current - Host mode */
#define IRQ_USB_ID     33  /* Detect ID pin change - OTG */
#define IRQ_PIN11      34  				     <--------ADD THIS LINE--------|
.
.
.

Then add the following macro:

.
.
.
#define _INTERNAL_IRQ_EVENT_MAP	\
	{IRQ_WDT, EVT_wdog_m0, EVT_RISING_EDGE}, \
	{IRQ_VBUS_EN, EVT_usb_otg_vbus_pwr_en, EVT_FALLING_EDGE}, \
	{IRQ_VBUS_OVRC, EVT_USB_VBUS, EVT_FALLING_EDGE}, \
	{IRQ_USB_ID, EVT_USB_ID, EVT_ACTIVE_LOW}, \
	{IRQ_PIN11,EVT_GPIO11,EVT_FALLING_EDGE}, \		<--------THIS LINE--------|
.
.
.

Next, in the following section a number changed:

.
.
.
#else
#define CHIP_IRQ_EVENT_MAP   _INTERNAL_IRQ_EVENT_MAP
#define NR_IRQ_CHIP_EVT	     5    			 <--------THIS LINE--------|      
#endif
.
.
.

After this, you have to change in file arch/arm/mach-lpc313x/ea313x.c this

struct spi_board_info info =
	{
		.modalias = "spidev",
		.max_speed_hz = 1000000,
		.bus_num = 0,
		.chip_select = 0,
	};

to this:


struct spi_board_info info =
	{
		.modalias = "enc28j60",
		.max_speed_hz = 25000000,
		.bus_num = 0,
		.irq = IRQ_PIN11,
		.chip_select = 0,
	};

This struct is important thereby the driver of the ENC28J60 is been told about the hardware to controll. The modalias is an information in order to get found by the driver. I'm working on a method to configure that at the user space of linux.

Include the kernel module

Of course, it's also important to compile the ENC28J60 driver.

make menuconfig

Then select the driver: device drivers --> network device support --> ethernet (10 or 100mbit) --> ENC28J60 support and start compiling.

make modules && make modules_install INSTALL_MOD_PATH=/[Path_to_install]/

How to install modules on your root fs, you can find here.

GNUBLIN Booten

After all changes have been done to the kernel you can boot linux and do the following:

root@gnublin:~# modprobe enc28j60 enc28j60 spi0.0: enc28j60 Ethernet driver 1.01 loaded net eth0: enc28j60 driver registered root@gnublin:~# ifconfig eth0 192.168.1.2 net eth0: link down net eth0: multicast mode net eth0: multicast mode ADDRCONF(NETDEV_UP): eth0: link is not ready net eth0: multicast mode root@gnublin:~# net eth0: link up - Half duplex ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready net eth0: multicast mode root@gnublin:~# ping 192.168.1.1 PING 192.168.1.1 (192.168.1.1): 56 data bytes 64 bytes from 192.168.1.1: seq=0 ttl=64 time=19.572 ms 64 bytes from 192.168.1.1: seq=1 ttl=64 time=7.373 ms 64 bytes from 192.168.1.1: seq=2 ttl=64 time=7.395 ms 64 bytes from 192.168.1.1: seq=3 ttl=64 time=7.306 ms --- 192.168.1.1 ping statistics --- 4 packets transmitted, 4 packets received, 0% packet loss round-trip min/avg/max = 7.306/10.411/19.572 ms

As soon as the ping command to the host succeeds, you can assume, that the ENC28J60 has been connected successfully.


Measurement

Measurements of datarate have shown 65,8kbit/s with SSH and 67,7kbit/s with an Webserver and wget.

In other languages