BPI-R2 SPI Communication

I can’t figure out what happened here. Try “mdev -s” to create /dev/* …

Btw. Sample-application seems to be here (not Documentation): https://github.com/torvalds/linux/blob/master/tools/spi/spidev_test.c

with the changes from @Ryder.Lee i got a kernel-crash when loading spidev:

root@bpi-r2:~# lsmod                                                            
Module                  Size  Used by                                           
bridge                151552  0                                                 
mt76x2e                61440  0                                                 
mt76                   32768  1 mt76x2e                                         
pwm_mediatek           16384  0                                                 
mtk_thermal            16384  0                                                 
spi_mt65xx             20480  0                                                 
thermal_sys            61440  1 mtk_thermal                                     
mt6577_auxadc          16384  0                                                 
ip_tables              24576  0                                                 
x_tables               28672  1 ip_tables                                       
ipv6                  409600  23 bridge                                         
root@bpi-r2:~# modprobe spidev                                                  
[  100.293178] spidev spi0.0: buggy DT: spidev listed directly in DT            
[  100.299303] ------------[ cut here ]------------                             
[  100.303914] WARNING: CPU: 0 PID: 699 at drivers/spi/spidev.c:730 spidev_prob]
[  100.312840] Modules linked in: spidev(+) bridge mt76x2e mt76 pwm_mediatek mt]
[  100.328025] CPU: 0 PID: 699 Comm: modprobe Tainted: G        W       4.14.181
[  100.336489] Hardware name: Mediatek Cortex-A7 (Device Tree)                  
[  100.342043] [<c0113208>] (unwind_backtrace) from [<c010d6b0>] (show_stack+0x)
[  100.349737] [<c010d6b0>] (show_stack) from [<c08b85e0>] (dump_stack+0x9c/0xb)
[  100.356914] [<c08b85e0>] (dump_stack) from [<c0125478>] (__warn+0xf8/0x110)  
[  100.363832] [<c0125478>] (__warn) from [<c0125560>] (warn_slowpath_null+0x30)
[  100.371362] [<c0125560>] (warn_slowpath_null) from [<bf131370>] (spidev_prob)
[  100.380362] [<bf131370>] (spidev_probe [spidev]) from [<c05d9b44>] (spi_drv_)
[  100.388747] [<c05d9b44>] (spi_drv_probe) from [<c0476994>] (driver_probe_dev)
[  100.397137] [<c0476994>] (driver_probe_device) from [<c0476c88>] (__driver_a)
[  100.405608] [<c0476c88>] (__driver_attach) from [<c04745b4>] (bus_for_each_d)
[  100.413736] [<c04745b4>] (bus_for_each_dev) from [<c0476170>] (driver_attach)
[  100.421690] [<c0476170>] (driver_attach) from [<c0475b1c>] (bus_add_driver+0)
[  100.429645] [<c0475b1c>] (bus_add_driver) from [<c0477978>] (driver_register)
[  100.437686] [<c0477978>] (driver_register) from [<c05d9a70>] (__spi_register)
[  100.446249] [<c05d9a70>] (__spi_register_driver) from [<bf137098>] (spidev_i)
[  100.455417] [<bf137098>] (spidev_init [spidev]) from [<c0101c38>] (do_one_in)
[  100.463978] [<c0101c38>] (do_one_initcall) from [<c01b1110>] (do_init_module)
[  100.472020] [<c01b1110>] (do_init_module) from [<c01afff0>] (load_module+0x1)
[  100.479976] [<c01afff0>] (load_module) from [<c01b0a68>] (SyS_finit_module+0)
[  100.487758] [<c01b0a68>] (SyS_finit_module) from [<c0108b80>] (ret_fast_sysc)
[  100.495922] ---[ end trace c412506263de5bee ]--- 

mt7623.dtsi (33,6 KB) mt7623n-bananapi-bpi-r2.dts (17,7 KB)

it seems that something is wrong in devicetree (spidev spi0.0: buggy DT: spidev listed directly in DT)

https://groups.google.com/forum/m/#!msg/acmesystems/55IZJE_HbnY/c_2GfZTSCgAJ

1 Like
root@bpi-r2:~# modprobe spidev                                                                 
root@bpi-r2:~# lsmod                                                            
Module                  Size  Used by                                           
spidev                 20480  0                                                 
bridge                151552  0                                                 
mt76x2e                61440  0                                                 
mt76                   32768  1 mt76x2e                                         
spi_mt65xx             20480  0                                                 
mtk_thermal            16384  0                                                 
mt6577_auxadc          16384  0                                                 
thermal_sys            61440  1 mtk_thermal                                     
pwm_mediatek           16384  0                                                 
ip_tables              24576  0                                                 
x_tables               28672  1 ip_tables                                       
ipv6                  409600  23 bridge                                         
root@bpi-r2:~# ls /dev/spi*                                                     
/dev/spidev0.0                                                                  

i used the dts-way in the link…

&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>;
    };
};

but i have not figured out how to compile the test-binary…

arm-linux-gnueabihf-gcc spidev_test.c -Igithub/include/

my kernel-source is in github/…

spidev_test.log (4,8 KB)

tools/spi$ make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf-

seems to do this job…spidev_fdx (17,3 KB) spidev_test (29,0 KB)

root@bpi-r2:~# ./spidev_test -D /dev/spidev0.0 
spi mode: 0x0
bits per word: 8
max speed: 500000 Hz (500 KHz)

Hi. Frank.

Thanks. I will try this way in monday.

You added the following

&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>;
    };
};

to mt7623n_bpi_r2.dts file? Right?

on 4.4 right (the 4.14 pendant)

Good Job Frank.

I tested and verified that “spidev32766.0” is creating at boot time. I can open the port.

Thanks for your efforts.

Hi. I am trying to use GPIO SPI communication on BPI-R2 board. Currently I am using your kernel 4.4.118. Still I need to recompile the kernel to enable SPI or your 4.4.118 kernel already enabled SPI?.

TIA.

I have not tried it yet, but Spi should work without recompile

See here for configuration: https://github.com/frank-w/BPI-R2-4.4/blob/master/linux-mt/arch/arm/configs/mt7623n_evb_bpi_defconfig

Maybe you need only

modprobe spi-dev

to enable the spidev-device

edit: maybe you need to enable spi0 in arch/arm/boot/dts/mt7623.dtsi and maybe add spidev-node like it’s done here: BPI-R2 SPI Communication

edit2: updated github-repo and added spi-nodes (hopefully right), buildt and currently uploading 4.4.120 with SPI - upload complete, ready for testing :wink:

Hi Frank, Thanks for the updated kernel. I tested the SPI. I can see that the SPI module loaded & spi device available during boot.

The SPI test gives the following result,

./spidev_test -D /dev/spidev32766.0

spi mode: 0x0

bits per word: 8

max speed: 500000 Hz (500 KHz)

However, my existing SPI program (working on RPI board) is not working on BPI-R2, the SPI PIN numbers are, 17-VCC,19-MOSI,21-MISO,23-SCK,24-CS,25-GND.

Am I missed anything here to work with SPI port?.

TIA.

  • your device works with 3v3?
  • have you tried swapping MOSI (master-out-slave-in = TX of BPI) and MISO (master-in-slave-out = RX of BPI)?
  • have you set CS (chip-select) to high/low depending on your device?

strange is that your spi-device (also of @Yusuf_Bulbul) is named spidev32766.0 and not spidev0.0 @ryder.lee is that right?

  • Yes, my device works with 3v3.
  • I did not tried with swapping MOSI & MISO. Should I?
  • Yes, I set CS from high to low. Note that my SPI module & program working fine on RPI3 same SPI ports. So I would like to use BPI-R2 instead of RPI3.

Yes, my SPI device is spidev32766.0. Should I rename spidev32766.0 into spidev0.0?

TIA.

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>;
    };
};