greymfm76
(Alexander Grau)
December 11, 2021, 11:03am
1
Hello, I took me some hours to figure out how to get I2C and SPI running on the BPI-M4 (RTD1395), so I document it here:
The below should work for all Banana PI Linux images (Raspbian, Ubuntu etc.), however I tested it with Raspbian and Kernel 4.9.119 (2020-05-18-raspbian-stretch-bpi-m4-sd-emmc.img)
I2C should work out of the box - finding I2C devices with i2cdetect may not work as expected, however communication works - example (read WHOAMI ID from MPU6050 connected to CON1-P03/I2C1_SDA and CON1-P05/I2C1_SCL):
For SPI, I needed to activate it in the Linux device tree.
Approach A): Patching device-tree using fdtput command without building kernel. Make sure boot partition mounted before doing this:
fdtput -t s /media/pi/BPI-BOOT/bananapi/bpi-m4/linux/rtd-1395-bananapi-m4-2GB.dtb /spi@9801BD00 status okay
fdtput -t s /media/pi/BPI-BOOT/bananapi/bpi-m4/linux/rtd-1395-bananapi-m4-1GB.dtb /spi@9801BD00 status okay
reboot
Approach B): Rebuilding kernel package
2.1 Download kernel package to your Linux PC: https://github.com/BPI-SINOVOIP/BPI-M4-bsp
2.2 Activate SPI in device tree (linux-rtk/arch/arm64/boot/dts/realtek/rtd139x/rtd-1395-bananapi-m4-1GB.dts and rtd-1395-bananapi-m4-2GB.dts):
2.3 Optional: change kernel options ./build 4
2.4 Compile kernel: ./build 1
2.5 Transfer kernel to SD card (with ready Raspbian on it): ./build 7
Test SPI with a ‘loopback cable’ (connect together CON1-P19/GSPI-MOSI and CON1-P21/GSPI-MISO)
wget https://raw.githubusercontent.com/torvalds/linux/master/tools/spi/spidev_test.c
gcc -o spidev_test spidev_test.c
RX should return TX data:
Feel free to ask if you have questions, comments etc.
2 Likes
sinovoip
(bpi team)
December 17, 2021, 1:25am
2
very good job, thank you share this
Great article.
Could you share how to enable multiple spi devices? Like /dev/spidev0.0, /dev/spidev0.1, /dev/spidev0.2, /dev/spidev0.3, etc.
They can share the MOSI, MISO and CLK pins, but just use different chip select pins. Thanks
melbadry
(mononymous)
February 17, 2022, 11:03pm
4
Hi,
I’ve been trying to replicate your instructions and failing, the spi-dev-test code does not even build.
Can you please advise? Further, I do not see any /dev/spi* after building custom kernel or patching kernel tree.
Thank you!
Mo
mbyron
(Marcel)
March 21, 2022, 10:41am
5
This is my experience to get the SPI to show /dev/spidev0.0.
Modifying device tree did not work.
In short … rebuild the Kernel and replace the files in your Boot directory with the files generated within the SD directory.
Steps I took:
get the docker image!! so you can build the kernel
ensure the correct SPI ROM is applied to pi
use configure kernel option of build - enable module for the SPI - to use SPIDEV
build everythinggg
copy generated kernel files to boot device…
mart
June 5, 2022, 4:23pm
6
This looks like exactly what I need. Forgive the simple question but for option A… how does one mount the boot partition?
Thanks!
SergiJ
(Sergi)
November 26, 2022, 1:59pm
7
Hello,
Can you advice if this is valid for BPI m2 zero as well? I am trying to get SPI+GPIO working on BPI m2 zero.
Thanks
przebot
(Jan Przebor)
January 25, 2023, 9:44pm
8
Hello!
I just wanted to mention that adding the following lines to armbianEnv.txt had helped me to get SPI working on Banana Pi M2 Zero:
overlays=spi-spidev
param_spidev_spi_bus=0
After I rebooted, the /dev/spidev0.0 showed up normally
I hope that helps!
sheng
April 6, 2023, 10:16am
9
may I ask which base image are you using?
przebot
(Jan Przebor)
April 6, 2023, 10:42am
10
I’ve been using this custom image, since I needed working OV5640 support:
You can find the base image on the github page
sheng
April 7, 2023, 10:32am
11
nice, thank you! I will take a look at it.