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 /[email protected] status okay
fdtput -t s /media/pi/BPI-BOOT/bananapi/bpi-m4/linux/rtd-1395-bananapi-m4-1GB.dtb /[email protected] 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.