BPI-R2 SPI Communication

(Frank W.) #102

tested your kernel (without device or shortened pins):

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

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?

(Frank W.) #104

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


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 ?

(Frank W.) #106

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

(moore liu) #107

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,

(Frank W.) #108

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

(moore liu) #109
  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))
     	printf("%.2X ", rx[ret]);
  2. There is a similar question in RaspberryPi forum.



 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;

(Frank W.) #110
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)

(moore liu) #111

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,

(Prakash) #112

Any updates for this SPI communication fix?.,

(Frank W.) #113

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)


SPI is functioning properly as I could enable the SPI panel.

I don’t really understand the problem explanation here. Something doesn’t look right as we shouldn’t have to change anything, but I just don’t get what you a

(Prakash) #115

May I know if we have one more SPI in BPI-R2. If so, please share the PIN connection details on the 40 pin header.