Raspberry Pi Zero W with SPI Ethernet modules

I've been using a Raspberry Pi Zero 1.3 (no W) with an SPI 12-pin ENC28J60 ethernet as a test environment for some network related code, and found it worked very well (2 crashes in 8 weeks due to a broken cable, none after a cable replacement). I'd also been experimenting with a couple of Pi Zero W a bit.

When I found that the wifi device that was moonlighting as my Pi cluster's wifi network was braindead (Sanho CloudFTP, via a kickstarter), and I wouldn't be able to dig into it's guts, I decided to use a Pi Zero W as it's replacement.

However by default, the OpenWrt release images for the Pi Zero W don't contain drivers for a lot of the SPI and I2C modules (I was trying to attach an RTC to the Pi Zero W too). That started my search into how to get this fixed, and below is the process I ended up using to make the changes:

  • Create a VM build environment as described in Beginner's build guide.

  • Jump from there to Quickstart build images to checkout the code, switch to branch openwrt-19.07 and set up the packages.

    git clone https://git.openwrt.org/openwrt/openwrt.git
    cd openwrt
    git checkout openwrt-19.07
    ./scripts/feeds update -a
    ./scripts/feeds install -a
    
  • Make config with make menuconfig

  • Apply all kernel patches for the bcm2708 target as detailed in Use Patches with Buildsystem with modifications as described here:

    make target/linux/{clean,prepare} V=s QUILT=1
    cd build_dir/target-*/linux-*/linux-4.14*
    quilt push -a
    cd ../../../..
    
  • Modify kernel submodule config as described here with make kernel_menuconfig CONFIG_TARGET=subtarget to include the drivers for the ENC28J60 and wiznet modules.

  • Run make and profit.

it would be beneficial to others if you provide a diff of your target/linux/BOARD/config-A.B...

takes the guesswork out of what the 'wiznet/ENC' selections ( KCONFIG values ) are...

also include the additional packages you needed to select ( i2c, spi? or mention that the kernel auto-selects these as DEPENDS if this is what happens )... otherwise someone will follow your tutorial and have no idea about the software components for i2c and spi...

Hello there.
This looks interesting to me.
How about its performance? Are you using 2 separate ethernet modules for WAN + LAN? Could you please share a photo how does it look like? And some screenshots maybe?
Tbh I'm really sorry bombarding you with questions all at once. Please accept my apologies.
ulpian

@ulpian

  • I'm using the WiFi as Lan and one SPI ethernet module as WAN (connected to a BSNL India FTTH EPON by SyRoTech).
  • From a performance viewpoint, as the ethernet module is a 10M module, the WAN speed is restricted to 10 MBPS. However the upstream connection is limited to 6 MBPS, so it doesn't affect my overall internet speed. I have not tested my intra-network speed yet. I will test and post the results here. The details of the wiring are almost identical to what is described for a Pi Zero 1.3 in https://github.com/samveen/PiZBMC (the wiring for the 3v3 pins, instead of the 5v pins).

-

@anon50098793 good idea. I will add the KConfig diff (or atleast the selection paths to the modules).

2 Likes
  • The kernel configuration diff (for kernel 4.14) is as follows:
diff --git a/target/linux/brcm2708/bcm2708/config-4.14 b/target/linux/brcm2708/bcm2708/config-4.14
index 284d7cfa4b..8dce68c4ca 100644
--- a/target/linux/brcm2708/bcm2708/config-4.14
+++ b/target/linux/brcm2708/bcm2708/config-4.14
@@ -145,6 +145,7 @@ CONFIG_DUMMY_CONSOLE=y
 CONFIG_EDAC_ATOMIC_SCRUB=y
 CONFIG_EDAC_SUPPORT=y
 CONFIG_ENABLE_MUST_CHECK=y
+CONFIG_ENC28J60=y
 CONFIG_EXT4_FS=y
 CONFIG_EXT4_FS_POSIX_ACL=y
 CONFIG_EXT4_FS_SECURITY=y
@@ -346,9 +347,16 @@ CONFIG_RAW_DRIVER=y
 # CONFIG_RCU_NEED_SEGCBLIST is not set
 # CONFIG_RCU_STALL_COMMON is not set
 CONFIG_REGMAP=y
+CONFIG_REGMAP_I2C=y
 CONFIG_REGMAP_MMIO=y
+CONFIG_REGMAP_SPI=y
 CONFIG_REGULATOR=y
 CONFIG_REGULATOR_FIXED_VOLTAGE=y
+CONFIG_RTC_CLASS=y
+CONFIG_RTC_DRV_DS1307=y
+CONFIG_RTC_DRV_DS1307_CENTURY=y
+CONFIG_RTC_I2C_AND_SPI=y
+CONFIG_RTC_MC146818_LIB=y
 CONFIG_RWSEM_XCHGADD_ALGORITHM=y
 # CONFIG_SCHED_INFO is not set
 CONFIG_SCSI=y
@@ -368,6 +376,12 @@ CONFIG_SERIAL_DEV_BUS=y
 CONFIG_SERIAL_OF_PLATFORM=y
 CONFIG_SG_POOL=y
 CONFIG_SPARSE_IRQ=y
+CONFIG_SPI=y
+CONFIG_SPI_BCM2835=y
+CONFIG_SPI_BCM_QSPI=y
+CONFIG_SPI_BITBANG=m
+CONFIG_SPI_DYNAMIC=y
+CONFIG_SPI_MASTER=y
 CONFIG_SRCU=y
 # CONFIG_STRIP_ASM_SYMS is not set
 CONFIG_SUSPEND=y
@@ -409,6 +423,10 @@ CONFIG_VT_CONSOLE=y
 CONFIG_VT_CONSOLE_SLEEP=y
 CONFIG_VT_HW_CONSOLE_BINDING=y
 CONFIG_WATCHDOG_CORE=y
+CONFIG_WIZNET_BUS_ANY=y
+CONFIG_WIZNET_W5100=m
+CONFIG_WIZNET_W5100_SPI=m
+CONFIG_WIZNET_W5300=m
 CONFIG_XZ_DEC_ARM=y
 CONFIG_XZ_DEC_BCJ=y
 CONFIG_ZBOOT_ROM_BSS=0x0
  • For enabling the module, the following line needs to be added to the config.txt of the boot partition (for the ENC28J60 module, default SPI bus speed is 12000000, max possible is 20000000):

    dtoverlay=enc28j60,int_pin=25,speed=20000000
    
  • The small piece of masking tape attached to the microSD card in the previous image is to ensure good contact of the card to the holder, as one of the microsd card pins had corroded due to a bad MicroSD to Full-SD converter.

  • Please note that the I2C options are for enabling support for the DS1307 RTC, and not required for the SPI Ethernet modules.

  • Internet speed test (via speedtest.net) results via the FTTH connection are as follows:
    SpeedTest results

  • Wifi Network peed test between 2 laptops running IPerf3 gave me the following result on the client (iperf3 -c 192.168.10.225 -n 100M):

    [  5]   0.00-391.75 sec   100 MBytes  2.14 Mbits/sec  9969             sender
    [  5]   0.00-391.77 sec  99.9 MBytes  2.14 Mbits/sec                  receiver
    

    and the following on the server (iperf3 -s):

    [  5]   0.00-391.77 sec  99.9 MBytes  2.14 Mbits/sec                  receiver
    

    The laptops were on opposite sides of the Pi Zero W, with the laptop running the iperf server being in another room around 5 metres away and atleast one concrete wall between it and the Pi (straight line between the 2 would form a triangle around an L shaped wall), and the laptop running the client 5 metres away but in LOS of the Pi.

@anon50098793 please review and let me know if there's anything else I may have overlooked to make this information more complete(I am unfortunately unable to add this information into the original post :confused: )

1 Like

great job... you'll probably find that... some of the spi / i2c KCONFIG would be bundled as an installable kmod(s)...

but as you've found... it's likely that the WIZNET + ENC28J60 likely aren't...

thanks for the great tutorial... as most users who dive in at this level ( sbc's and hats / modules etc ) are assumed to have to do some 'custom' work to add modules / fancy drivers etc...

I think your tutorial is the best starting point for them as every single module will never be bundled as ipk's ( considering the general openwrt userbase ) and many of these 'tinkerer' ic's etc. need some level of manual work...

thankyou!

( note: as i'm sure your aware, differing kernel versions sometimes require alternative KCONFIG... so someone attempting this on say 5.4 would be best to follow your OP and redo the selections via menuconfig... )

if you want to later bundle these as ipks yourself ... take a look in master at;

here
vert@zr:/fs/sdd1/openwrt/RTNGext/FISH$ fgrep -r 'CONFIG_' target/linux/bcm27xx/modules/
target/linux/bcm27xx/modules/other.mk:    CONFIG_PWM=y \
target/linux/bcm27xx/modules/other.mk:    CONFIG_PWM_BCM2835
target/linux/bcm27xx/modules/other.mk:  KCONFIG:=CONFIG_BCM2835_SMI
target/linux/bcm27xx/modules/other.mk:  KCONFIG:=CONFIG_BCM2835_SMI_DEV
target/linux/bcm27xx/modules/i2c.mk:  CONFIG_I2C_BCM2835:drivers/i2c/busses/i2c-bcm2835
target/linux/bcm27xx/modules/hwmon.mk:  KCONFIG:=CONFIG_SENSORS_RASPBERRYPI_HWMON
target/linux/bcm27xx/modules/hwmon.mk:  KCONFIG:=CONFIG_SENSORS_RPI_POE_FAN
target/linux/bcm27xx/modules/spi.mk:    CONFIG_SPI=y \
target/linux/bcm27xx/modules/spi.mk:    CONFIG_SPI_BCM2835 \
target/linux/bcm27xx/modules/spi.mk:    CONFIG_SPI_MASTER=y
target/linux/bcm27xx/modules/spi.mk:    CONFIG_SPI=y \
target/linux/bcm27xx/modules/spi.mk:    CONFIG_SPI_BCM2835AUX \
target/linux/bcm27xx/modules/spi.mk:    CONFIG_SPI_MASTER=y

for inspiration...

( edit: LOVE the masking tape on the sdcard... I was putting a dab of hotglue on mine but it came off every second removal... WINNER! )

1 Like

Thanks for your reply.
Well done you did a great job my friend. I'll give it a shot as soon as possible. Cheers.
ulpian