BPI-R2 SPI Communication


(Yusuf Bülbül) #21

Yes I have also added to mt7623n_bpi_r2.dts following;

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

Actually, Driver is seen, but There is no /dev/spidev

pi@bpi-iot-ros-ai:~$ find /sys/bus | grep spi
/sys/bus/spi
/sys/bus/spi/devices
/sys/bus/spi/drivers
/sys/bus/spi/drivers/spidev
/sys/bus/spi/drivers/spidev/bind
/sys/bus/spi/drivers/spidev/uevent
/sys/bus/spi/drivers/spidev/unbind
/sys/bus/spi/uevent
/sys/bus/spi/drivers_probe
/sys/bus/spi/drivers_autoprobe
/sys/bus/platform/devices/1100a000.spi
/sys/bus/platform/drivers/mtk-spi
/sys/bus/platform/drivers/mtk-spi/bind
/sys/bus/platform/drivers/mtk-spi/1100a000.spi
/sys/bus/platform/drivers/mtk-spi/uevent
/sys/bus/platform/drivers/mtk-spi/unbind

also I have enabled spi user interface from kernel build options.


#22

Please have a look at : https://www.kernel.org/doc/Documentation/spi/spidev


(Yusuf Bülbül) #23

Hi.

I I have looked the link and made some research. I tried to create devices and bind to driver with “mknod” command. But, I couldn’t solve the problem.

Have you any another idea?


#24

Did you have the slave devices connected to host controller? Did you try to use mdev or udev to create /dev/* node?


(Yusuf Bülbül) #25

Sorry. I didn’t try to create device node from udev and mdev. Because I didn’t find any Info how to create it.

Can you send or tell me how to create spidev from mdev and udev? I will be very glad for this.


#27

enable CONFIG_SPI_SPIDEV and CONFIG_SPI_MT65XX.

Add spidev node to spi bus:

&spi {

  pinctrl-names = "default"; 
  pinctrl-0 = <&spi_pins_a>; 
  status = "okay"; 

 spidev: spidev@0 { 
    compatible = "spidev"; 
    spi-max-frequency = <1000000>; 
    reg = <0>; 
 }; 

};

build user space test code :Documentation/spi/spidev_test.c and copy to board.

./spidev_test -D /dev/spidevxxx

The below log indicates that spi bus loopback success.

spi mode: 0x0 bits per word:[ 1366.441051] <0>(O) max speed: 500000 Hz (500 KHz) 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 DE AD BE EF BA AD F0 0D


(Yusuf Bülbül) #28

Nope… I can’t it. There is still no /dev/spidev and also device can’t opened at example program.


#29

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


(Frank W.) #30

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


(Frank W.) #31

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)


#32

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


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

SPI touchscreen ads7846 (xpt2046) on UBUNTU images (BPI-R2)
(Yusuf Bülbül) #34

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?


(Frank W.) #35

on 4.4 right (the 4.14 pendant)


(Yusuf Bülbül) #36

Good Job Frank.

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

Thanks for your efforts.


(Ethicstech) #37

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.


(Frank W.) #38

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:


(Ethicstech) #39

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.


(Frank W.) #40
  • 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?


(Ethicstech) #41
  • 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.