Can't Enable SPI on DietPi Radxa zero

Creating a bug report/issue

I have searched the existing open and closed issues

Required Information

  • DietPi version |
    G_DIETPI_VERSION_CORE=9 G_DIETPI_VERSION_SUB=8 G_DIETPI_VERSION_RC=0 G_GITBRANCH='master' G_GITOWNER='MichaIng'
  • Distro version | bookworm
  • Kernel version | Linux hyperion 6.6.65-current-meson64 #1 SMP PREEMPT Wed Dec 11 15:13:43 UTC 2024 aarch64 GNU/Linux
  • Architecture | arm64
  • SBC model | Radxa Zero (aarch64)
  • Power supply used | 5V 4A
  • SD card used | SanDisk ultra

Steps to reproduce

Hello DietPi Community,

I’m trying to enable SPI on my DietPi setup but haven’t been able to find the option in dietpi-config.

Here’s some additional info about my setup:

Steps I’ve already tried:

  1. Edited /boot/config
  2. Rebooted the system and checked with lsmod | grep spi, but no SPI modules are loaded.

Is there a specific step I’m missing, or how do I enable SPI on this DietPi version?

Any help or guidance would be greatly appreciated!

Thanks in advance,

Expected behaviour

Enable SPI

Actual behaviour

best to my knowlage, /boot/config.txt ha no effect on Radxa device as config.txt as a RPI SBC configuration file. You would need to enable SPI/overlay on /boot/dietpiEnv.tx

I don’t have a Radxa device, but maybe following could help Can't get SPI to work with Rock Pi 4 - #4 by Nasker

getting this error

sudo modprobe spi-spidev
modprobe: FATAL: Module spi-spidev not found in directory /lib/modules/6.6.65-current-meson64
sudo modprobe meson-spi-spidev
modprobe: FATAL: Module meson-spi-spidev not found in directory /lib/modules/6.6.65-current-meson64

I see

root@hyperion:~# ls -la /boot/dtb-6.6.65-current-meson64/amlogic/overlay/meson-g12a-radxa-zero-spi-spidev.dtbo
-rw-r--r-- 1 root root 1028 12. Dez 13:05 /boot/dtb-6.6.65-current-meson64/amlogic/overlay/meson-g12a-radxa-zero-spi-spidev.dtbo

and I put

cat /boot/dietpiEnv.txt
overlays=meson-g12a-radxa-zero-spi-spidev
param_spidev_spi_bus=0
param_spidev_max_freq=10000000

But no overlay is loaded

~# lsmod | grep -i "spi"
~# 

and

sudo modprobe meson-g12a-radxa-zero-spi-spidev
modprobe: FATAL: Module meson-g12a-radxa-zero-spi-spidev not found in directory /lib/modules/6.6.65-current-meson64
~# 

in dmesg I see only

root@hyperion:~# dmesg | grep -i "spi"
root@hyperion:~# dmesg | grep -i "error"
[    7.081568] panfrost ffe40000.gpu: error -ENODEV: _opp_set_regulators: no regulator (mali) found
[    7.396556] brcmfmac mmc2:0001:1: Direct firmware load for brcm/brcmfmac43430-sdio.radxa,zero.bin failed with error -2

maybe @MichaIng has an idea

I also tried this

root@hyperion:~# ls /dev/spi*
ls: Zugriff auf '/dev/spi*' nicht möglich: Datei oder Verzeichnis nicht gefunden
root@hyperion:~# ls -la /boot/dtb/
insgesamt 20
drwxr-xr-x 3 root root  4096 23. Dez 21:28 .
drwxr-xr-x 5 root root  4096 23. Dez 21:25 ..
drwxr-xr-x 3 root root 12288 22. Dez 11:16 amlogic
lrwxrwxrwx 1 root root    25 23. Dez 21:28 overlay -> /boot/dtb/amlogic/overlay
root@hyperion:~# cat /boot/dietpiEnv.txt 
rootdev=UUID=a3c519cc-ba3f-498f-a9a3-2e58ea9254e6
rootfstype=ext4
# The init system logs to the console defined last.
consoleargs=console=ttyAML0,115200 console=tty1
usbstoragequirks=
extraargs=net.ifnames=0
docker_optimizations=off
overlay_path=amlogic
overlay_prefix=meson
user_overlays=dietpi-usb-otg
overlays=g12a-radxa-zero-spi-spidev
param_spidev_spi_bus=0
param_spidev_max_freq=10000000
root@hyperion:~# 

but still spi is not enabled

Is there any help on this?

To apply device tree overlays in general:

  1. Check /boot/dtb/*/overlay for actually available overlays.
  2. Check the overlay_prefix variable in /boot/dietpiEnv.txt.
  3. Apply the filename of the overlay without the prefix and first dash, and without the .dtbo file extension.

For the Radxa Zero, the overlay prefix is meson, and these are the available overlays:

You hence need to set overlays=g12a-radxa-zero-spi-spidev to enable SPI. Those parameters cannot be applied here, I guess you would need to apply them via /etc/modprobe.d config as kernel module/driver parameters.

Although, I just checked the source code of that overlay, and weirdly it explicitly disables two SPI nodes: build/patch/kernel/archive/meson64-6.6/overlay/meson-g12a-radxa-zero-spi-spidev.dts at 9ce005ff2a56859a22fb952377e501c690a24994 · armbian/build · GitHub

No idea why, probably they are enabled OOTB on Radxa’s own kernel builds, and Armbian did not check whether it hence makes sense like that. There is however an alternative device tree as well, which enables at least SPI1: build/patch/kernel/archive/meson64-6.6/dt/meson-g12a-radxa-zero-spidev.dts at 9ce005ff2a56859a22fb952377e501c690a24994 · armbian/build · GitHub

Can you try this: Remove the overlays= line again (and the param_ line anyway, and instead:

G_CONFIG_INJECT 'fdtfile=' 'fdtfile=amlogic/meson-g12a-radxa-zero-spidev.dtb' /boot/dietpiEnv.txt
reboot
G_CONFIG_INJECT 'fdtfile=' 'fdtfile=amlogic/meson-g12a-radxa-zero-spidev.dtb' /boot/dietpiEnv.txt

is perfect :slight_smile:
What is the difference to

this?

  overlays activation in /boot/dietpiEnv.txt

Just for my learning and understanding :slight_smile:

Since the overlay is obviously broken, probably really only meant to explicitly disable SPI instead of enabling it (we can further test this, when I find some time), I found this whole alternative device tree instead. So instead of applying an overlay/change to the default device tree, a different device tree with SPI enabled (obviously correctly enabled) is used now.

Actually, we can derive the needed diff for an overlay from the diff of those two device trees.

Only /dev/spi1 is available now, not /dev/spi0, right?

correct

ls /dev/spi*
/dev/spidev1.0

1 Like

Can you check this:

for i in /proc/device-tree/spi*; do ls -l "$i"; cat "$i/status"; echo; done
for i in /proc/device-tree/spi*; do ls -l "$i"; cat "$i/status"; echo; done
ls: Zugriff auf '/proc/device-tree/spi*' nicht möglich: Datei oder Verzeichnis nicht gefunden
cat: '/proc/device-tree/spi*/status': Datei oder Verzeichnis nicht gefunden

Interesting, are those in the soc sub directory?

for i in /proc/device-tree/soc/spi*; do ls -l "$i"; cat "$i/status"; echo; done

I followed this solution, but after the add of the string in the ‘dietpiEnv.txt’ file, the system failed to boot. Once removed, my Zero 3E boot again.

Found a solution that work for me.

My overlay prefix is rk3588, so I modified the dietpiEnv.txt file:

overlay_prefix=rk3588
overlays=spi0-m1-cs0-spidev
param_spidev_spi_bus=0
param_spidev_max_freq=10000000

and added missing groups to /etc/group (for me spi and gpio), then configured UDEV:

echo -e 'SUBSYSTEM=="i2c-dev", GROUP="i2c", MODE="0660"\nSUBSYSTEM=="spidev", GROUP="spi", MODE="0660"\nSUBSYSTEM=="gpio", KERNEL=="gpiochip*", GROUP="gpio", MODE="0660", TAG+="uaccess"' > /etc/udev/rules.d/99-i2c_spi_group.rules

once rebooted, I have correct devices and group permission:

crw-rw---- 1 root gpio 254, 0 Jan 13 23:59  /dev/gpiochip0
crw-rw---- 1 root gpio 254, 1 Jan 13 23:59  /dev/gpiochip1
crw-rw---- 1 root gpio 254, 2 Jan 13 23:59  /dev/gpiochip2
crw-rw---- 1 root gpio 254, 3 Jan 13 23:59  /dev/gpiochip3
crw-rw---- 1 root gpio 254, 4 Jan 13 23:59  /dev/gpiochip4
crw-rw---- 1 root gpio 254, 5 Jan 13 23:59  /dev/gpiochip5
crw-rw---- 1 root i2c   89, 0 Jan 13 23:59  /dev/i2c-0
crw-rw---- 1 root i2c   89, 3 Jan 13 23:59  /dev/i2c-3
crw-rw---- 1 root i2c   89, 6 Jan 13 23:59  /dev/i2c-6
crw-rw---- 1 root spi  153, 0 Jan 13 23:59  /dev/spidev0.0
for i in /proc/device-tree/soc/spi*; do ls -l "$i"; cat "$i/status"; echo; done
ls: Zugriff auf '/proc/device-tree/soc/spi*' nicht möglich: Datei oder Verzeichnis nicht gefunden

Non capisco il tedesco!!!

May be you are searching in the wrong place:
ls -d /proc/device-tree/spi*
I find:

/proc/device-tree/spi@fe300000  /proc/device-tree/spi@fe620000  /proc/device-tree/spi@fe640000
/proc/device-tree/spi@fe610000  /proc/device-tree/spi@fe630000

And we don’t understand Italian :wink: