Hello, we would like to use SPI via wiringPi.

#include <iostream>
#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;

     buffer[0] = 0x55;
     wiringPiSPIDataRW(CHANNEL, buffer, 1);

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


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


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

1 Like


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

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


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.


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.

1 Like

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

1 Like


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 

@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
next setp
$ source env/
next step
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
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

1 Like

@OSHMUHA use this command

$ make kernel && make debs && make 


$ make kernel 

copy dtb and Image file to you board.

Just use make can’t update the kernel


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


May I know what are your configurations for source env/ .
Thanks you very much :slight_smile:

Now I got stuck at that NO any dtb files generated in linux/arch/arm64/boot/dts after I succeeded to run make ARCH=arm64 kvims_defconfig .

I just want to follow this Building Kernels Manually to manually build kernel. Then I could use those updated dtb files to make bootimage

I am using khadas-vims-4.9.y branch and git log shown as below:

This is my configuration and I am not sure if I do make sense:

	amo@ubuntu:~/workspace/vim3/fenix$ source env/ 

	Choose Khadas board:
	1. Edge
	2. VIM1
	3. VIM2
	4. VIM3
	5. VIM3L

	Which board would you like? [2] 4

	Choose uboot version:
	1. uboot-2015.01
	2. uboot-mainline

	Which uboot version would you like? [1] 1

	Choose linux version:
	1. linux-4.9

	Which linux version would you like? [1] 1

	Choose distribution:
	1. Ubuntu
	2. Debian

	Which distribution would you like? [1] 1

	Choose Ubuntu release:
	1. bionic
	2. focal

	Which Ubuntu release would you like? [1] 1

	Choose Ubuntu type:
	1. server
	2. minimal
	3. xfce
	4. lxde
	5. gnome

	Which Ubuntu type would you like? [1] 2

	Set architecture to 'arm64' by default.

	Choose install type:
	1. EMMC
	2. SD-USB

	Which install type would you like? [1] 1
	#VERSION: 1.0.1



	Environment setup done.
	Type 'make' to build.

Then I got error when I run make kernel && make debs && make and log shown below:

    amo@ubuntu:~/workspace/vim3/fenix$ make kernel && make debs && make 
	Info: Build host: bionic
	Info: Installing build dependencies
	Info: Requires root privileges, please enter your passowrd!
	[sudo] password for amo: 
	Hit:1 bionic InRelease
	Hit:2 bionic InRelease         
	Reading package lists... Done           
	Building dependency tree       
	Reading state information... Done
	All packages are up to date.
	Reading package lists... Done
	Building dependency tree       
	Reading state information... Done
	Some packages could not be installed. This may mean that you have
	requested an impossible situation or if you are using the unstable
	distribution that some required packages have not yet been created
	or been moved out of Incoming.
	The following information may help to resolve the situation:

	The following packages have unmet dependencies:
	 gcc-arm-linux-gnueabihf : Depends: gcc-7-arm-linux-gnueabihf (>= 7.3.0-12~)
	 libpython2.7-dev : Depends: libpython2.7-stdlib (= 2.7.15~rc1-1) but 2.7.17-1~18.04ubuntu1.2 is to be installed
						Depends: libpython2.7 (= 2.7.15~rc1-1) but 2.7.17-1~18.04ubuntu1.2 is to be installed
						Depends: libexpat1-dev but it is not going to be installed
	 systemd-container : Depends: systemd (= 237-3ubuntu10)
	 uuid-dev : Depends: libuuid1 (= 2.31.1-0.4ubuntu3) but 2.31.1-0.4ubuntu3.7 is to be installed
	E: Unable to correct problems, you have held broken packages.
	Makefile:25: recipe for target 'kernel' failed
	make: *** [kernel] Error 100

	#### failed to build some targets (7 seconds) ####

Thanks all.

@ChiaHungMou you have dependencies that are not met, try using Ubuntu Focal fossa (20.04 LTS)

1 Like

@ChiaHungMou You host ubuntu is 18.04 , So you can’t build a 20.04 image . You can try to build in docker . About how to build in docker , you can follow README in fenix

1 Like

Hi @Frank ,

Thank you for your dedicated support.
Yes I spent whole night and build up a whole new ubuntu 20.04 environment VM.
And Fenix works well on my new ubuntu 20.04 environment VM indeed.

However I just met some make error which did show on my past ubuntu 18.04 VM.
I am making sure if it’s caused by repo sync uncompleted so I just rm -rf whole repo and running repo sync now.

@ChiaHungMou About android source and compile , you can ask @Terry and @jasonl

1 Like