Using an enc28j60 on the zero

Hi @Enoch_Lee,

How to build a custom kernel is well described on the Radxa wiki: https://wiki.radxa.com/Zero/dev/kernel
If you need help with that, I suggest you open another thread, rather than continue posting on this one which should be limited to the enc28j60 modules specifically.

Can you test this image? This one should contain the overlay and the driver.

Oh, I needed to have a look at the device and I nearly forgot about you, sorry. But I see they have taken care of you…

Yes, the wiring seems OK. But you definitely need the module, as stated by others. I did compile the module in a “dirty way” just by downloading the appropriate directory enc28j60 with the module sources from the large kernel source tree (ideally the very same kernel version you are running). It is basically just one source file. I do not remember exactly how I compiled it using make (so stupid not to write down things!), but I found the proper command to compile just a single kernel module somewhere. The Makefile only contains a single line: obj-m = enc28j60.o. Of course, one needs at least the current kernel headers package installed to compile the module against.

Oh, yes. The instructions from https://docs.kernel.org/kbuild/modules.html seem to work. The original directory only has three files, the Makefile mentioned above and two source files: enc28j60.c and enc28j60_hw.h. When I run make -C /lib/modules/`uname -r`/build M=$PWD, I get the module compiled. I suppose that the next step would then install it: make -C /lib/modules/`uname -r`/build M=$PWD modules_install.

@wanthalf Could you please post the full image that have the Ethernet SPI overlay works?
Somehow, I could not get it to work.
Thanks

The https://github.com/radxa-build/radxa-zero/releases/download/20230201-0149/radxa-zero_debian_bullseye_cli_2023-02-01T1038+0000_msdos.img.xz image does not work. It stuck at the bootloader.

Did you type all those nonsense characters, or is that because of a poor serial connection? If the latter, try booting without the uart cable. The bootloader thinks you’re trying to interrupt the boot sequence.

I did not type anything.
I only flash the image to a SD card and install the SD card to the Radxa Zero 2.
The text came out from the HDMI screen.
I used a USB hub with a USB keyboard and a mouse

I unplugged the USB hub. There was only HDMI cable connected between Radxa and the monitor. The Radxa image stuck at the bootloader with random characters.

You can see on your screen it says “Hit any key to stop autoboot”. You either have input from serial port or USB keyboard (they display the same console) that interrupt the boot process.

Please take a picture of your connections so we can check what might causing the issue.

Oops, something spilling garbage to your USB serial!

The radxa-ubuntu images used to be defect out-of-the-box since last summer, but I reported elsewhere how to fix them. But the debian images worked, just used a different kernel and overlay system. @RadxaYuntian posted a special image above. Are you testing that one?
(Sending my working image would be desperate indeed. Remember it is expanded to the whole SD card and may contain just any additional rubbish and my personal data.)

Once you get past the serial garbage problem, you can check the serial output, whether the overlay gets actually loaded or not. In the dmesg I can see the module loading:

[    6.960784] enc28j60: loading out-of-tree module taints kernel.
[    6.960923] enc28j60: module verification failed: signature and/or required key missing - tainting kernel
[    6.961693] enc28j60 spi0.0: Ethernet driver 1.02 loaded

And later things like:

[    9.341604] enc28j60 spi0.0 eth0: link up - Half duplex
[   14.202587] enc28j60 spi0.0 eth0: multicast mode

As far as I remember, I did no other configuration except compiling and installing the overlay and the kernel module.

Right now my Zero samples are not able to detect the SPI device. Looking to validate the overlay on some other devices.

@RadxaYuntian I had UART_A0_A_TXD and UART_A0_A_TXD (pin-8, pin-10) pins were connected. I removed them, the kernel could boot up.
I logged in using: radxa, radxa.
However the kernel could not load the enc28j60. When I searched for “enc28” from the dmesg, it responded -> “not found”.

How is your enc28j60 connected to the board?

Here is the connection:

Today I loaded the module and had the overlay in the /boot/uEnv.txt file, but still could not load the enc28j60 ethernet.
pi@radxa-zero:~$ sudo lsmod | egrep ‘enc’
enc28j60 45056 0
pi@radxa-zero:~$ cat /boot/uEnv.txt | egrep enc28
overlays=meson-g12a-uart-ao-a-on-gpioao-0-gpioao-1 meson-g12a-spi-spidev meson-g12a-spi-b-enc28j60
pi@radxa-zero:~$ sudo ifconfig
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
loop txqueuelen 1000 (Local Loopback)
RX packets 1442 bytes 161504 (157.7 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 1442 bytes 161504 (157.7 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
pi@radxa-zero:~$ uname -a
Linux radxa-zero 5.10.165-1-stable #179624a57 SMP PREEMPT Tue Jan 31 03:53:59 UTC 2023 aarch64 GNU/Linux

According to the ENC28J60 datasheet, the VDD pin is rated for an absolute maximum of +3.6V. If you’ve got it connected to +5V, you’ve probably fried your chip unless you’re using a module of some sort that is stepping the VCC voltage down to +3.3V.

Thanks @wanthalf, @theophile , I got the enc28j60 ethernet to work, I also updated the 3.3 volt label.
Following are my main steps:

  1. Get the updated kernel:
    https://github.com/radxa-pkg/linux-stable/releases/download/0.1-1/linux-image-5.10.156-1-stable_5.10.156-1-6d46ef50b_arm64.deb
  2. Install the updated kernel:
    sudo dpkg -i linux-image-5.10.156-1-stable_5.10.156-1-6d46ef50b_arm64.deb
  3. copy the ./usr/lib/modules/5.10.165-1-stable/kernel/drivers/net/ethernet/microchip/enc28j60.ko
    to: ./usr/lib/modules/5.10.165-1-stable/enc28j60.ko
  4. load the module:
    sudo modprobe enc28j60
  5. copy *.dtbo from: ./usr/lib/linux-image-5.10.165-1-stable/amlogic/overlays/
    to: ./usr/lib/linux-image-5.10.165-1-stable/amlogic/overlay/
    Somehow the subfolder name changed from “overlay“ to “overlays"
  6. edit /boot/uEnv.txt
    overlays=meson-g12a-spi-gpio-enc28j60
    Make sure the file name is correct.

Hi all,
The enc28j60 overlay seems to work but it is not stable. The enc28j60 LAN ethernet hung after about 10 minutes.
I used the eth0 to ping another device, after a while, it hung. I could not do another ping nor using ssh to connect to it.
I attached the dmesg log file.
Please advice!
Thanks
enc28j60_up_down.zip (14.4 KB)

The SPI circuitry or the enc28j60 driver is sluggish and un-reliable.
I let the Radxa zero ran overnight - Wi-Fi disabled, the ec28j26 LAN Ethernet connection hung. My router still recognized the enc28j60 LAN ethernet ip address; however, I could ssh/network connect to the device.

Hi, dennisnguy
We have not tested the stability of enc28j60 using spi-gpio to connect to ethernet, we will test it later