Enable SPI in Debian


#1

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.


#2

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?


#3

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


#4

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.


#5

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.


#6

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


#7

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


#8

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


#9

Fantastic, thank you very much.


#10

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


#11

@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.


#12

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


#13

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.