ENC28J60 SPI Ethernet


10 posts
by psergiu » Tue Sep 25, 2012 1:08 pm
Hi everyone,

I want to use a ENC28J60 SPI ethernet board with the latest Raspbian.

It's possible, the driver exists in the kernel source code, and Chris Boot already did-it before.

Can anyone give me some hints on how i can accomplish this ? Do i need to recompile the whole kernel or just the enc28j60.c kernel module ? Any pointers on the kernel source (shall i use the kernel.org image or shall i download a RPi-speciffic one, from where) ?

Thanks a lot.
User avatar
Posts: 212
Joined: Mon Nov 07, 2011 8:36 am
Location: Bucharest, Romania
by RaTTuS » Tue Sep 25, 2012 1:14 pm
sudo apt-get update && sudo apt-get upgrade -y
reboot
git clone --depth 1 https://github.com/raspberrypi/linux.git
cd linux
zcat /proc/config.gz >.config
edit .config and enable
CONFIG_ENC28J6
make modules
sudo make modules_install
sacrifice 1st born
reboot

YMMV
1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX - Prosliver FTW
"That's not right, the badgers have moved the goalposts."
User avatar
Posts: 4162
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK
by psergiu » Tue Sep 25, 2012 7:14 pm
Thank you very much.

Thankfully i skiped the last step. And i backed up the old modules.

I somehow managed to compile broken kernel modules. "modinfo" says the are the same as the old ones, "file" says they are the same as the old ones but they are a couple ok Kb smaller and "modprobe" says: "ERROR: could not insert 'enc28j60': Exec format error"

and in "dmesg" i get "enc28j60: no symbol version for module_layout"

s/enc28j60/every_other_newly_compiled_module_i_tried/g
User avatar
Posts: 212
Joined: Mon Nov 07, 2011 8:36 am
Location: Bucharest, Romania
by psergiu » Wed Sep 26, 2012 5:56 am
I succesfuly compiled the module

ln -s /wherever/i/downloaded/the/kernel /usr/src/linux
ln -s /usr/src/linux /lib/modules/`uname -r`/build
cd /lib/modules/`uname -r`/build
make -C /lib/modules/`uname -r`/build

i insmod the enc28j60 module aaaand ... nothing.

further reading on the interwebs tells me that for the 3.2.x kernel i have to edit a file somewhere to tell the kernel where my board is physically connected SPI BUS & CS

something like:
Code: Select all
static struct spi_board_info spi1_board_info[] __initdata = {
 

   {
      .modalias       = "enc28j60",
      .mode          = SPI_MODE_0,
      .irq         = AT32_EXTINT(0),
      .max_speed_hz      = 12000000,
      .chip_select      = 0,   
   },
};

and some init code.

http://www.avrfreaks.net/index.php?name ... ic&t=75282
http://ww2.cs.fsu.edu/~rosentha/linux/2 ... e1197.html
http://www.jumpnowtek.com/index.php?opt ... &Itemid=62

But where i'm supposed to put those code snippets and are there any specifics for Raspberry Pi ?
User avatar
Posts: 212
Joined: Mon Nov 07, 2011 8:36 am
Location: Bucharest, Romania
by psergiu » Thu Sep 27, 2012 10:00 pm
Success.

file to edit: arch/arm/mach-bcm2708/bcm2708.c

search for "spi_board_info bcm2708_spi_devices" and modify as follows (assuming your ENC28J60 is connected to spi0.0 (CE0):

Code: Select all
static struct spi_board_info bcm2708_spi_devices[] = {
        {
                .modalias = "enc28j60",
                .max_speed_hz = 12000000,
                .bus_num = 0,
                .chip_select = 0,
                .mode = SPI_MODE_0,
        }, {
                .modalias = "spidev",
                .max_speed_hz = 500000,
                .bus_num = 0,
                .chip_select = 1,
                .mode = SPI_MODE_0,
        }
};


Recompile kernel & modules as in the previous post
cp arch/arm/boot/zImage /boot/kernel.img
cp drivers/net/ethernet/microchip/enc28j60.ko /lib/modules/`uname -r`/kernel/drivers/net/ethernet/microchip/
shutdown -r now

then after it starts up: modprobe enc28j60
and victory:
Code: Select all
[  847.810450] enc28j60 spi0.0: enc28j60 Ethernet driver 1.01 loaded
[  847.822819] net eth1: enc28j60 driver registered
[  847.947228] net eth1: link down
[  847.947297] net eth1: normal mode
[  847.947331] net eth1: normal mode
[  847.947558] net eth1: multicast mode
[  850.154955] net eth1: link up - Half duplex


Right now, the network card is working "IRQ-less" so the speed is not great ( ~100KB/sec).
Next step - connecting the network card's IRQ signal to a GPIO.
User avatar
Posts: 212
Joined: Mon Nov 07, 2011 8:36 am
Location: Bucharest, Romania
by RaTTuS » Fri Sep 28, 2012 8:20 am
psergiu wrote:...
cp arch/arm/boot/zImage /boot/kernel.img
....

ooh I never knew you could just copy the zImage .... I've been using the imagetoo-uncompressed.py script ...
/me goes to change my special build machine
1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX - Prosliver FTW
"That's not right, the badgers have moved the goalposts."
User avatar
Posts: 4162
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK
by ezz » Fri Dec 28, 2012 10:20 pm
Anybody has a schematics of connection ?
Posts: 7
Joined: Fri Dec 21, 2012 4:08 pm
by psergiu » Fri Dec 28, 2012 10:50 pm
6 jumper wires:

ENC - RPi
=======
VCC - 3v3
GND - GND
CS - CE0 (gpio 8)
SI - MOSI (gpio 10)
SCK - SCKL (gpio 11)
SO - MISO (gpio 9)

Also, pin INT can be connected to another GPIO pin and the driver configured to use-it as IRQ (haven't done this yet so i cannot tell you exactly how)
User avatar
Posts: 212
Joined: Mon Nov 07, 2011 8:36 am
Location: Bucharest, Romania
by msperl » Wed Nov 06, 2013 1:43 pm
For those of you who try to use this device with a current kernel:
you will need to configure the interrupt edge outside of the driver.

If you use spi-config to configure the SPI-parts (see: viewtopic.php?f=44&t=57157), then assuming you have:
  • the IRQ line on GPIO 25
  • the ENC28j60 CS on CS1

Then with this you can set up the network:
Code: Select all
echo "25" > /sys/class/gpio/export
echo "falling" > /sys/class/gpio/gpio25/edge
echo "25" > /sys/class/gpio/unexport
modprobe spi-config devices=bus=0:cs=1:modalias=enc28j60:speed=12000000:gpioirq=25


the above will load the enc28j60 driver (if you have it compiled as a module) and then start it up as "expected"...
Network is up almost immediately - but do not expect an extremely fast network...

Martin
Posts: 226
Joined: Thu Sep 20, 2012 3:40 pm
by psegura » Wed Mar 19, 2014 7:21 pm
Hello!
As I understand the steps are:

Wired connection:
6 jumper wires:

ENC - RPi
=======
VCC - 3v3
GND - GND
CS - CE0 (gpio 8)
SI - MOSI (gpio 10)
SCK - SCKL (gpio 11)
SO - MISO (gpio 9)

1.-
sudo apt-get update && sudo apt-get upgrade -y
reboot
git clone --depth 1 https://github.com/raspberrypi/linux.git
cd linux
zcat /proc/config.gz >.config
edit .config and enable
CONFIG_ENC28J6

2.-
edit: arch/arm/mach-bcm2708/bcm2708.c
search for "spi_board_info bcm2708_spi_devices" and modify as follows (assuming your ENC28J60 is connected to spi0.0 (CE0):

static struct spi_board_info bcm2708_spi_devices[] = {
{
.modalias = "enc28j60",
.max_speed_hz = 12000000,
.bus_num = 0,
.chip_select = 0,
.mode = SPI_MODE_0,
}, {
.modalias = "spidev",
.max_speed_hz = 500000,
.bus_num = 0,
.chip_select = 1,
.mode = SPI_MODE_0,
}
};

3.-
ln -s /wherever/i/downloaded/the/kernel /usr/src/linux
ln -s /usr/src/linux /lib/modules/`uname -r`/build
cd /lib/modules/`uname -r`/build
make -C /lib/modules/`uname -r`/build

4.-
cp arch/arm/boot/zImage /boot/kernel.img
cp drivers/net/ethernet/microchip/enc28j60.ko /lib/modules/`uname -r`/kernel/drivers/net/ethernet/microchip/
shutdown -r now

If I'm not forgetting nothing please let me know why I do not have the enc28j60.ko file? Can I use enc28j60.o? And, how? modprobe? insmod?
I tried to recompile the module with this:
make -C /lib/modules/3.10.25+/build M=drivers/net/ethernet/microchip/enc28j60.ko
But just recived a ko directory:
root@raspberrypi:/lib/modules/3.10.25+/build# ls -l drivers/net/ethernet/microchip/
total 132
-rw-r--r-- 1 root root 24982 Mar 18 18:29 built-in.o
-rw-r--r-- 1 root root 45356 Mar 4 18:02 enc28j60.c
-rw-r--r-- 1 root root 8913 Mar 4 18:02 enc28j60_hw.h
drwxr-xr-x 3 root root 4096 Mar 19 12:57 enc28j60.ko
-rw-r--r-- 1 root root 24984 Mar 18 18:29 enc28j60.o
-rw-r--r-- 1 root root 1035 Mar 4 18:02 Kconfig
-rw-r--r-- 1 root root 95 Mar 4 18:02 Makefile
-rw-r--r-- 1 root root 50 Mar 18 23:02 modules.builtin
-rw-r--r-- 1 root root 0 Mar 19 12:40 modules.order
-rw-r--r-- 1 root root 0 Mar 19 12:40 Module.symvers

Thanks.
Posts: 1
Joined: Wed Mar 19, 2014 6:45 pm