Enable SPI in Debian

Has anybody had any luck getting SPI to work with the debian image? I’ve followed the advice here and enabled the device tree overlay, but I’m not certain this is sufficient to get SPI working. When I try to enable spi devices in /boot/hw_intfc.conf, I do get some dmesg errors however:

[ 2.132127] rockchip-spi ff1d0000.spi: Failed to request TX DMA channel
[ 2.132137] rockchip-spi ff1d0000.spi: Failed to request RX DMA channel
[ 2.132146] rockchip-spi ff1d0000.spi: no high_speed pinctrl state

There are also no spi devices in /dev, should they show up when SPI is enabled properly, or are one of the other devices the SPI controllers. Btw, I can use i2c just fine.

Thanks in advance.

Hi @dbqpdb

When you want to use a spi device on rockpi through SPI1 as you mentioned, there are several steps you should do.
Fistly, you need to set spi1 as on, like

intfc:spi1=on

and ensble your your dtbo , like

intfc.dtoverlay=spi1-flash # spi1-flash is the name of your dtbo file without suffic .dtbo

in /boot/hw_confc.conf.

Secondly, place your dtbo file, which is about your spi device (e.g. spi1-flash.dtbo), in /boot/overlays.

Thirdly, if necessary, you need to check whether there is the driver module attached to your spi device in the kernel.

By the way, which spi device do you use?

Thank you very much. Is there a standard .dtbo file that I can use for the SPI device? I’m trying to use SPI2.

To clarify, I am not trying to use a specific external SPI device. I am looking for low level access to the SPI bus, through some thing like /dev/spidev (which does not exist), so that I can communicate directly to an external circuit that I have built.

I believe I have it working by updating the device tree. Steps:

Decompile device tree

dtc -I dtb -O dts -o rockpi-4b-linux.dts /boot/dtbs/4.4.154-73-rockchip-00007-g155a65a/rockchip/rockpi-4b-linux.dtb

Update the device tree. I am using spi2, which is ff1e0000. To spi@ff1e0000, I added

spidev@0 {
compatible = “spidev”;
status = “okay”;
reg = <0x00000000>;
spi-max-frequency = <0x00989680>;
};

Recompile

dtc -I dts -O dtb -o /boot/dtbs/4.4.154-73-rockchip-00007-g155a65a/rockchip/rockpi-4b-linux.dtb rockpi-4b-linux.dts

and reboot. You should now have /dev/spidev32766.0 You can use spidev_test with a jumper from pins 29 & 31 to test.

The dmesg errors are still present however, so there may be more issues to resolve.

I’d write an overlay instead of mod the dtb directly. The overlays are working now so it’s the way to go.

Hi,
We have update the rockpi4-dtbo package to control spi1.

To use SPI1, uncomment these two lines.

intfc:spi1=on
intfc.dtoverlay=devspi

There shall be /dev/spidev32766.0.

By the way, libmraa-rockpi4 package is added. See https://wiki.radxa.com/Rockpi4/dev/libmraa

1 Like

Fantastic, thank you very much.

sudo apt-get install libmraa-rockpi4
Reading package lists… Done
Building dependency tree
Reading state information… Done
E: Unable to locate package libmraa-rockpi4

@O635789, now the package libmraa-rockpi4 is only for stretch arm64 and bionic arm64. Are your root filesystem of image is 32-bit? if so, won’t find it.

RIght, arm64 is fine, armhf didn’t get it.

Not working on Debian ARM64:

mraa-gpio list
mraa-gpio: error while loading shared libraries: libjson-c.so.3: cannot open shared object file: No such file or directory

sudo apt-get install libjson-c3
mraa-gpio list
mraa-gpio: /lib/aarch64-linux-gnu/libc.so.6: version `GLIBC_2.27’ not found (required by /usr/local/lib/libmraa.so.2)

I’m still googling how to get glibc 2.27…

I hope you could build your packages on Debian ARM64 instead of Ubuntu, if it works on Debian ARM64 the chance is better to work on Ubuntu, not the case the other way around.

EDIT:
I downloaded libmraa source code and built successfully, made a few calls to the library works fine. However, run the tool “mraa-uart list” got error.

1 Like

And I thought this might be a couple of simple steps like a real Raspberry Pi!

I tried to install libmraa (I’m using Armbian, from the Radxa Download page)

While doing:
sudo apt-get install -y rockchip-overlay rockchip-fstab

I get always the error:
mount all partitions
mount: mount point vfat does not exist

E: Sub-process /usr/bin/dpkg returned an error code (1)

What can I do?
And what is the easiest way for me (newby) to enabel and use SPI

Tried and tried for 3 time, but spi1 still not working (no listing at /dev) dtbo already installed, hw_intfc.conf edited

https://wiki.radxa.com/Rockpi4/dev/libmraa

Test the .c file
./a.output : failed to Initialize SPI device

Using latest-kernel-83

@ggzitha same Problem here

interestingly, on one of my two RockPi’s it works without any Problem, on the other one it doesn’t (at least spi. UART works fine on both).
Same Image, same Kernel, lots of reboots…but it won’t work

I have 3 RockPi’s & both spi devices work on all of them. So sounds like maybe some sort of hardware problem?

The SPI on the GPIO is the same bus for the reserved SPI flash beside the CPU. Make sure it don’t contact the heatsink of other conductor.

I dunno what happen, but i tried to “unminimized” at fresh install and it show up the /dev/spidev

So it needed to unminimize first ?