BPI-R2 SPI Communication

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)

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

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.

TIA.

@Ryder.Lee I am struck up with SPI communication on BPI-R2 for long time. Can you please point the right kernel for BPI-R2 with working SPI communication.

TIA.

Please see my posts at 3/29. I think there’s no SPI issue in each Kernel version. Could you try to check your SPI pins are okay or not?

@asprakash imho you need to add your device with matching driver in your dts. I have not found a way for low-level spi yet (without define driver in dts).

@Ryder.Lee I am currently using the prebuilt kernel from Frank. I was not able to proceed with testing since there was no SPI device present on this kernel. Shall I use BPI official kernel 4.4.70?.

@frank-w I am intended to use LORA radio with SPI communication on BPI-R2 board. It wont required any special driver since I am using the same way with other boards like RPI.

TIA.

To get it running ypu can try this driver: https://lwn.net/Articles/758774/

And a modified version of this dts (direct in bananapi-r2.dts not as dto: https://github.com/afaerber/dt-overlays/blob/master/bcm2836-rpi-2-b%2Barpi600%2Bdragino-lora.dts

@asprakash have you got it working?

New uboot also supports dto. You have to use kernel without appended dts. You find example in my kernel-repo: https://github.com/frank-w/BPI-R2-4.14/commit/8eaba24d23997d13b3d76f4478f375527a6a5ac5