BPI-R2 SPI Communication

Hello, Frank, I use Ubuntu

Any fixes available for this SPI issue?.

TIA.

@Ryder.Lee can you please share your kernel-source for comparison?

I didn’t do anything but just added SPI node in dts. Moreover, I can get the same results when using v4.16.

Maybe i’ve added it in wrong place or missing any kernel-option…

I’ve used the latest kernel version(v4.16-rc1) to test the SPI panel (ili9225).

Panel driver: drivers/gpu/drm/tinydrm/ili9225.c

Share my dts and config for you: mt7623n_evb_defconfig (5.2 KB) mt7623.dtsi (20.9 KB) mt7623n-bananapi-bpi-r2.dts (9.4 KB)

Test command: Capture

IMG_1595

1 Like

the only diference i’ve found:

my spi-block in bpi.dts:

&spi0 {
	pinctrl-names = "default";
	pinctrl-0 = <&spi0_pins_a>;
	status = "okay";
	spidev: spidev@0 {
		compatible = "rohm,dh2228fv";
		spi-max-frequency = <1000000>;
		reg = <0>;
	};
};

your block (direct for the device):

&spi0 {
	pinctrl-names = "default";
	pinctrl-0 = <&spi0_pins_a>;
	status = "okay";

	display@0{
		compatible = "vot,v220hf01a-t", "ilitek,ili9225";
		reg = <0>;
		spi-max-frequency = <1000000>;
		rs-gpios = <&pio 25 GPIO_ACTIVE_HIGH>;
		reset-gpios = <&pio 18 GPIO_ACTIVE_HIGH>;
		rotation = <270>;
	};
};

you have another compatible string and name for the spi-device (and some additional options for your device)…i don’t know if the gpios-options needed, too. Also on you screenshot i see that you have another HW-revision of bpi-board (maybe 1.2), because battery connector is missing and there is the uboot-switch

The difference is I connect a real device to SPI0, so the DTS should be modified accordingly.

Can you test the uImage I provided before (spidev_test)? I think it has nothing to do with HW-revision. I will suggest you to use buildroot or other simple rootfs to test HW.

tested your kernel (without device or shortened pins):

Welcome to Buildroot                                                            
buildroot login: root                                                           
# ls /dev/spidev*                                                               
/dev/spidev32766.0                                                              
# spidev_test -D /dev/spidev32766.0                                             
spi mode: 0x0                                                                   
bits per word: 8                                                                
max speed: 500000 Hz (500 KHz)                                                  
RX | FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF.
# 

as you see there is RX, but no TX i guess that it should be the other way (TX but not RX)

tried to copy your spidev_test (maybe we made a mistake while compiling) to local storage, but seems that no rw-access is possible

# mount -t ext4 -o remount,rw /dev/mmcblk1p2 /mnt
# cp /usr/sbin/spidev_test /mnt/usr/local/sbin/
cp: can't create '/mnt/usr/local/sbin/spidev_test': Read-only file system

also tried with fat-partition…scp/ftp-commands not available in your buildroot

Good news. Did you loop TX and RX pin?

No, pins open, no device no loop. That’s why i wonder about rx…and anything in your Kernel is different

tried my spidev_test-binary in your buildroot:

# ./spidev_test                                                                 
./spidev_test: line 1: syntax error: unexpected word (expecting ")")

both binaries are elf-binaries (beginning with ?ELFAAA)

since file-command not available i cannot compare the binaries more than simply read out the first bytes

my binary seems to need /lib/ld-linux-armhf.so.3 which is not present in buildroot, your binary uses /lib/ld-uClibc.so.0

is SPI attached to any other controller/bus (like internal wifi is attached via btif)? so we are missing any other driver? the only SPI-Option we are missing is SPI_DEBUG

CONFIG_SPI=y
CONFIG_SPI_DEBUG=y
CONFIG_SPI_MT65XX=y
CONFIG_SPI_SPIDEV=y

i guess the boot-message for SPI are resulting from SPI_debug

# dmesg |grep spi
[    0.054854] calling  spi_init+0x0/0xc0 @ 1
[    0.054924] initcall spi_init+0x0/0xc0 returned 0 after 0 usecs
[    4.343917] calling  spidev_init+0x0/0xc4 @ 1
[    4.348301] initcall spidev_init+0x0/0xc4 returned 0 after 49 usecs
[    4.354521] calling  mtk_spi_driver_init+0x0/0x20 @ 1
[    4.361220] initcall mtk_spi_driver_init+0x0/0x20 returned 0 after 1630 usecs

Can you loop rx/tx pin to test ?

mit looped rx/tx (wired pin 19/21) same result (only made window a bit larger):

# spidev_test -D /dev/spidev32766.0 
spi mode: 0x0
bits per word: 8
max speed: 500000 Hz (500 KHz)
RX | FF FF FF FF FF FF 40 00 00 00 00 95 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF F0 0D  | ......@....�.................
#

still no TX

Your test result is ok because the test program use below array as tx and only dump rx data.

    uint8_t tx[] = {
    		0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
    		0x40, 0x00, 0x00, 0x00, 0x00, 0x95,
    		0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
    		0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
    		0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
    		0xDE, 0xAD, 0xBE, 0xEF, 0xBA, 0xAD,
    		0xF0, 0x0D,
    	};

why did i get RX if not connected MISO to MOSI?

is it possible to define a default SPIDEV-Device without a special driver in dts?? simply use it as SPI without kerneldriver or with a driver loaded after booting the kernel

  1. sample code always try to dump rx array if ioctl ok no matter tx is successful or not.

     ret = ioctl(fd, SPI_IOC_MESSAGE(1), &tr);
     	if (ret < 1)
     		pabort("can't send spi message");
    
     for (ret = 0; ret < ARRAY_SIZE(tx); ret++) {
     	if (!(ret % 6))
     		puts("");
     	printf("%.2X ", rx[ret]);
     }
     puts("");
    
  2. There is a similar question in RaspberryPi forum.

https://www.raspberrypi.org/forums/viewtopic.php?t=102171

Documentation/spi/spidev_test.c

 static const char *device = "/dev/spidev1.1";
 static uint8_t mode;
 static uint8_t bits = 8;
 static uint32_t speed = 500000;
 static uint16_t delay;
for (ret = 0; ret < ARRAY_SIZE(tx); ret++) {...
 	printf("%.2X ", rx[ret]);

a dangerous access in my eyes…make a loop over items in tx and read that position in rx…who says that rx is same length as tx? imho it should use ARRAY_SIZE(rx) if reading from rx…

  1. in this discussion main-point should be overlay-dts, but no info how to use them…must they compiled, how to use them (where to place) at runtime and how to load (bpi does not use /boot/config.txt and uboot maybe don’t know dtparam)

it is a sample program to test spi interface in linux kernel source tree. I will suggest you trace the source code if you have any questions about the test result.

In my opinion, test procedure on BPI-R2 is the same as other platform.:grinning:

uint8_t rx[ARRAY_SIZE(tx)] = {0, };
	struct spi_ioc_transfer tr = {
		.tx_buf = (unsigned long)tx,
		.rx_buf = (unsigned long)rx,
		.len = ARRAY_SIZE(tx),
		.delay_usecs = delay,
		.speed_hz = speed,
		.bits_per_word = bits,
	};

Any updates for this SPI communication fix?.,

i have not tried something because of missing time. I guess we need overlay-dts for the specific device (or define it in dts…each user have to do this for his device)