BPI-R2 SPI Communication

i’ve found some other users having that name…so that should be ok…currently i have no glue what the problem can be…i don’t have a spi-device here for testing (at least no with kernel-support…only a dip204 display anywhere :D)

Ok, thanks for your input. I will figure out the problem.

I will also test MISO/MOSI swap and make sure the SPI is working. But I am also fear that whether GPIOs are working or not on R2 board. There are some of your older github issues reported that GPIOs were not working. Please confirm the current status of GPIOs as well.

TIA

i had not tested all GPIOs, the main-problem was the wrong numbering in the official documentation (https://bananapi.gitbooks.io/banana-pi-bpi-r2-open-source-smart-router/content/bpi-r2-gpio-pin-define.html) which seems to be corrected now and the usage of a additional application for some “special GPIO”. also had some strange experience with uart and arduino, which seems to be arduino-specific (hardware-uart-rx on arduino uno does not work if usb is connected to a PC).

if you don’t need hdmi you can test my 4.14 kernel…maybe you have more luck with it…there is no need for the additional application, but gpio-access is a it different (look in my wiki)

My highest priority is SPI communication. R2 board is useless for me in case of SPI wont work on the GPIO. I am not sure about the status of other peripherals like ethernets, USB, OTG, PCI,.etc.

I dont required HDMI. Is your kernel 4.14 working with SPI?.

TIA.

I have it enabled it, but also not tested (because of missing device). But with other gpio i have less problems as with 4.4.

you can use loopback to see spi0 works or not on your setup.

I had tested spi0 with the way before, it should be okay for me. but I’ve not tested with a real spi device.

for loopback testing, please tie MOSI, MISO and then do the following command, and then have the base on the following dts structure

# spidev_test -s 1000000 -D /dev/spidev0.0
spi mode: 0
bits per word: 8
max speed: 1000000 Hz (1000 KHz)

FF FF FF FF FF FF <--- linkersosa commented: rx buffer printed , that is identical to tx buffer
40 00 00 00 00 95
FF FF FF FF FF FF
FF FF FF FF FF FF
FF FF FF FF FF FF
DE AD BE EF BA AD
F0 0D

and what the spi node i used looks like in devicetree.

/* child node should be added under the master node */​
&spi0 {
       spidev: spidev@0 {
               compatible = "rohm,dh2228fv";
               //compatible = "spidev";
               spi-max-frequency = <1000000>;
               reg = <0>;
       };
};

He uses my 4.4-kernel…dts is here: https://github.com/frank-w/BPI-R2-4.4/blob/master/linux-mt/arch/arm/boot/dts/mt7623n-bpi-r2.dts

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

Hi @linkerosa @frank-w Thanks for your further inputs & support. Shall I use mt7623n-bpi-r2.dts and recompile your 4.4 kernel?.

TIA.

My last compiled version contains the spi-changes, so you don’t need to recompile it if using that.

But you must build the test-application linkerosa uses

I guessed the compatible strings you used here can’t help the device being probed in latest kernel

as https://elixir.bootlin.com/linux/v4.16-rc5/source/drivers/spi/spidev.c#L667 the spidev_dt_dis table defining the available compatible strings for spidev strings would be

static const struct of_device_id spidev_dt_ids[] = {
	{ .compatible = "rohm,dh2228fv" },
	{ .compatible = "lineartechnology,ltc2488" },
	{ .compatible = "ge,achc" },
	{ .compatible = "semtech,sx1301" },
	{},
};

I added spidev-compatible :slight_smile:

See linked discussion with patch from ryder.lee

it’s fine. but you break native kernel, want to be noticed when you port these code between kernels with a different version.

In addition to those points @frank-w mentioned in the last reply. It’s also better to know what characteristics SPI slaves you used should have. especially for CPOL and CPHA . Everything works well should be according to a proper setup on what timing phase/polarity to transmit or receive the data between the master and the slave.

If you know what CPOL and CPHA your slave should have, you can set them up in child node under &spi0 with a extra value for spi-cpol and/or spi-cpha. Can refer to below binding document to know details.

https://elixir.bootlin.com/linux/v4.16-rc5/source/Documentation/devicetree/bindings/spi/spi-bus.txt#L66

You mean it’s better using the existing values and not adding spidev-compatible?

yes, don’t change the native if the change is not necessary

Hi. Here is my testing.

  • I looped MISO/MOSI (PINS 19 & 21)
  • I am using the same 4.4.120 KERNEL.
  • Loop test result :

./spidev_test -s 1000000 -D /dev/spidev32766.0

spi mode: 0x0

bits per word: 8

max speed: 1000000 Hz (1000 KHz)

I am not getting any tx/rx datas printed.

@linkerosa Can you share your kernel for quick testing?.

TIA.

reverted the spi-compatible (now “rohm,dh2228fv”), build and uploaded as 120 again

https://drive.google.com/open?id=1kkFyxeHoskszI7CpSsL6Wi6ROjDrBLOB

my 4.14 do not use spidev as compatible-string

https://drive.google.com/open?id=1EGN1TvqCpDHdOAS-mjRg9ipi0kahnOUV

@linkerosa i also tried the loopback…it seems nothing is being sent…

[18:16] root@bpi-r2:~# ./spidev_test -D /dev/spidev0.0                          
spi mode: 0x0                                                                   
bits per word: 8                                                                
max speed: 500000 Hz (500 KHz)                                                  
[18:18] root@bpi-r2:~# ./spidev_test -s 1000000 -D /dev/spidev0.0               
spi mode: 0x0                                                                   
bits per word: 8                                                                
max speed: 1000000 Hz (1000 KHz)                                                
[18:19] root@bpi-r2:~# ./spidev_test --help                                     
./spidev_test: unrecognized option '--help'                                     
Usage: ./spidev_test [-DsbdlHOLC3vpNR24SI]                                      
  -D --device   device to use (default /dev/spidev1.1)                          
  -s --speed    max speed (Hz)                                                  
  -d --delay    delay (usec)                                                    
  -b --bpw      bits per word                                                   
  -i --input    input data from a file (e.g. "test.bin")                        
  -o --output   output data to a file (e.g. "results.bin")                      
  -l --loop     loopback                                                        
  -H --cpha     clock phase                                                     
  -O --cpol     clock polarity                                                  
  -L --lsb      least significant bit first                                     
  -C --cs-high  chip select active high                                         
  -3 --3wire    SI/SO signals shared                                            
  -v --verbose  Verbose (show tx buffer)                                        
  -p            Send data (e.g. "1234\xde\xad")                                 
  -N --no-cs    no chip select                                                  
  -R --ready    slave pulls low to pause                                        
  -2 --dual     dual transfer                                                   
  -4 --quad     quad transfer                                                   
  -S --size     transfer size                                                   
  -I --iter     iterations                                                      
                                                                                
[18:19] root@bpi-r2:~# ./spidev_test -l -D /dev/spidev0.0                       
can't set spi mode: Invalid argument                                            
Aborted                                                                         
[18:19] root@bpi-r2:~# ./spidev_test -D /dev/spidev0.0 -p 123                   
spi mode: 0x0                                                                   
bits per word: 8                                                                
max speed: 500000 Hz (500 KHz)                                                  
[18:20] root@bpi-r2:~#

Must the spi-mode of the gpio enabled somehow?

Its really strange that the SPI is not yet working on this board. BPI-R2 is useless even its specifications are looking good. Need help to make it work. @linkerosa @frank-w @sinovoip

TIA.

Any updates for me?.