VIM3 GPIO "WiringPI" SPI

Hello, we would like to use SPI via wiringPi.

#include
#include <errno.h>
#include <wiringPiSPI.h>
#include <unistd.h>

// channel is the wiringPi name for the chip select (or chip enable) pin.
// Set this to 0 or 1, depending on how it’s connected.
//static const int CHANNEL = 1;
static const int CHANNEL = 0;

int main()
{
int fd, result;
unsigned char buffer[100];

std::cout << “Initializing” << std::endl ;

// Configure the interface.
// CHANNEL insicates chip select,
// 500000 indicates bus speed.
fd = wiringPiSPISetup(CHANNEL, 500000);

std::cout << "Init result: " << fd << std::endl;

while(true)
{
buffer[0] = 0x55;
wiringPiSPIDataRW(CHANNEL, buffer, 1);
sleep(5);
}
}

By executing this program we get the message:

Unable to open SPI device: No such file or directory

We tried to load spi:

khadas@Khadas:/boot$ sudo gpio load spi
[sudo] password for khadas:
gpio: Unable to load/unload modules as this Pi has the device tree enabled.
You need to run the raspi-config program (as root) and select the
modules (SPI or I2C) that you wish to load/unload there and reboot.

sudo ls -l /dev/spi*
ls: cannot access ‘/dev/spi*’: No such file or directory

Is it possible to enable SPI without raspi-config?

regards from Norway
Kwklaus

The SPI is not enabled by default, you have to enable it in dts and rebuild the kernel.

1 Like

I want to use SPI in VIM3.
How can I add SPI to Device Tree?
Now I am doing kernel REBUILDING with fenix.

@OSHMUHA

$ cd fenix/linux/arch/arm64/boot/dts/amlogic

edit the kvim3_linux.dts,find spicc1,change disabled to okay

3 Likes

Dear Frank
I have try to rebuild by your commant that is editing the vim3_linux.dts.
and I have sucesse rebuilding in the vim3_linux.dts file by edit spicc1 changed.
But I don’t find spi device at the /dev directory.
Please What I need to do additionally to add SPICC1 device to the / dev directory

@OSHMUHA You can try this steps:

$ make kernel

Then , Copy fenix/linux/arch/arm64/boot/Image to you board and replace /boot/zImage,
copy fenix/linux/arch/arm64/boot/dts/amlogic/kvim3_linux.dtb to you board /boot/dtb.

Final,run $sync && sudo reboot in you board .

You should check the file generate time if update before you copy it .

Or you can rebuild the full image.

$ make kernel && make debs && make 

Then ,reburn it to you board.

2 Likes

It was confirmed that the kvim3_linux.dtb file and Image are newly created.
I copied it to the / boot directory and & sync && sudo reboot also executed normally.
I still can’t find spicc1 in / dev.
Let me know what I don’t know

@OSHMUHA I am soory , I forget that the pwm_f had been open in dts. you need to disabled it .

&pwm_ef {
     status = "disabled";
     pinctrl-names = "default";
     pinctrl-0 = <&pwm_f_pins2>;
 };

pwm_f and spi all used pin35

PWM_EF is disabled.
Nevertheless, the SPI is still not found in / DEV.
Please tell me how to use SPI device driver.

Hei,
It’s very interesting to follow this discussion about SPI here.
Until now we solved this problem for our self, our Project.
We changed for now from Ubuntu to Android 9, because
the problems with HDMI and TS050 Display is until now
in Khadas Queue! we’re waiting for good messages.

But Now, we have the problems with Android…!!
We’re still waiting for a message from Khadas specialist @Terry
it’s not so easy to communicate with him, him’s response time is
average 8 days!

Sorry that I’m not so helpful for you @OSHMUHA

Hello @OSHMUHA

Please revert all the changes before and try this patch.

nick@Nick:~/code/fenix/linux$ git diff arch/arm64/boot/dts/amlogic/kvim3_linux.dts
diff --git a/arch/arm64/boot/dts/amlogic/kvim3_linux.dts b/arch/arm64/boot/dts/amlogic/kvim3_linux.dts
index 920480b..ae40b6a 100644
--- a/arch/arm64/boot/dts/amlogic/kvim3_linux.dts
+++ b/arch/arm64/boot/dts/amlogic/kvim3_linux.dts
@@ -854,7 +854,7 @@
 &pwm_ef {
        status = "okay";
        pinctrl-names = "default";
-       pinctrl-0 = <&pwm_f_pins2>;
+       pinctrl-0 = <&pwm_f_pins1>;
 };
 
 &pwm_AO_cd {
@@ -1390,7 +1390,7 @@
 };
 
 &spicc1 {
-       status = "disabled";
+       status = "okay";
        pinctrl-names = "default";
        pinctrl-0 = <&spicc1_pins>;
        cs-gpios = <&gpio GPIOH_6 0>;

You will see the spi node.

root@Khadas:~# ls /dev/spidev1.0 
/dev/spidev1.0
2 Likes

@OSHMUHA You can use the patch which come from @numbqq . I have test it . It work fine .

@numbqq 's patch is result
It’s so sorry, it is not work fine
but still i can’t spidev1.0 device
First step
$ git clone --depth 1 https://github.com/khadas/fenix
next setp
$ source env/setenv.sh
next step
$make
after building and then i have edit pwm_ef & spicc1 part in the file “linux/arch/arm64/boot/dts/amlogic/kvim3_linux.dts”
next setp
i have run :~/code/fenix/linux$ git diff arch/arm64/boot/dts/amlogic/kvim3_linux.dts


and then i have run
$make
it’s result “VIM3_Ubuntu-xfce-bionic_Linux-4.9_arm64_SD-USB_V0.8.3-20200318.img”
Plaese how can i doing for spidev1.0 device

@OSHMUHA use this command

$ make kernel && make debs && make 

or

$ make kernel 

copy dtb and Image file to you board.

Just use make can’t update the kernel

2 Likes

Dear Frank , @numbqq
I have successfully registered spidev1.0.
Thank you.

1 Like