Jump to content

How to enable hardware SPI


hajs

Recommended Posts

I seem to have lost the SPI while versions have changed. Tried installing a new "zero" with latest kernel...

 

root@orangepizero:~# uname -a
Linux orangepizero 4.19.57-sunxi #5.90 SMP Fri Jul 5 17:58:43 CEST 2019 armv7l armv7l armv7l GNU/Linux

 

root@orangepizero:~# more /boot/armbianEnv.txt
verbosity=1
logo=disabled
console=serial
disp_mode=1920x1080p60
overlay_prefix=sun8i-h3
overlays=spi-spidev usbhost2 usbhost3
rootdev=UUID=63cd3251-93f4-4395-a5c0-6d25301ea2ff
rootfstype=ext4
param_spidev_spi_bus=0
usbstoragequirks=0x2537:0x1066:u,0x2537:0x1068:u

 

Reboot...

 

But, no /dev/spidev.....

 

I have read this string, and my understanding is that this should be sufficient with recent kernel....

 

Humbly,

Gullik

Link to comment
Share on other sites

Hmmm....

 

Dumping the contents of the overlay file, /boot/dtb/overlay/sun8i-h3-spi-spidev.dtbo there ARE commands for the spi, but these

are disabled. So, would it make more sense to have possible conflicting devices disabled ( as of now ) and the overlay file

enabling selected, by the armbianEnv.txt mechanism?

 

Gullik

Link to comment
Share on other sites

So, boldly decompiled the spi-spidev dtbo, edited the dts to enable spi's, compiled back, replaced the dtbo, rebooted....

 

Nah....did not work....so obviously my brain did not filter out the correct structure of this....

No trace of anything interesting in dmesg.....

 

Gullik

Link to comment
Share on other sites

12 minutes ago, Gullik said:

there is a ko named spidev, but modprobe does not make any change either....

No needs to do "modprobe", if loading overlay succeed, module will be loaded automatically.

 

During early boot, using USB-TTL Serial dongle on debug port, what do you see when overlay is loaded and applying fixup script ?

Link to comment
Share on other sites

Early boot:

 

looks like it is applying sun8i-h3-spi-spidev.dtbo, it is "stock" except I changed "disabled" to "okay" in two places....

 

there is no /boot/boot.env on my SD, cannot see it mentioned earlier.

 

 

U-Boot SPL 2019.04-armbian (Jul 06 2019 - 00:40:48 +0200)
DRAM: 512 MiB
Trying to boot from MMC1


U-Boot 2019.04-armbian (Jul 06 2019 - 00:40:48 +0200) Allwinner Technology

CPU:   Allwinner H3 (SUN8I 1680)
Model: Xunlong Orange Pi Zero
DRAM:  512 MiB
MMC:   mmc@1c0f000: 0, mmc@1c10000: 1
Loading Environment from EXT4... ** File not found /boot/boot.env **

** Unable to read "/boot/boot.env" from mmc0:1 **
In:    serial
Out:   serial
Err:   serial
Net:   phy interface0
eth0: ethernet@1c30000
starting USB...
USB0:   USB EHCI 1.00
USB1:   USB OHCI 1.0
USB2:   USB EHCI 1.00
USB3:   USB OHCI 1.0
USB4:   USB EHCI 1.00
USB5:   USB OHCI 1.0
scanning bus 0 for devices... 1 USB Device(s) found
scanning bus 1 for devices... 1 USB Device(s) found
scanning bus 2 for devices... 1 USB Device(s) found
scanning bus 3 for devices... 1 USB Device(s) found
scanning bus 4 for devices... 1 USB Device(s) found
scanning bus 5 for devices... 1 USB Device(s) found
       scanning usb for storage devices... 0 Storage Device(s) found
Autoboot in 1 seconds, press <Space> to stop
switch to partitions #0, OK
mmc0 is current device
Scanning mmc 0:1...
Found U-Boot script /boot/boot.scr
3798 bytes read in 2 ms (1.8 MiB/s)
## Executing script at 43100000
U-boot loaded from SD
Boot script loaded from mmc
265 bytes read in 1 ms (258.8 KiB/s)
8127296 bytes read in 624 ms (12.4 MiB/s)
7494704 bytes read in 578 ms (12.4 MiB/s)
Found mainline kernel configuration
29807 bytes read in 11 ms (2.6 MiB/s)
772 bytes read in 5 ms (150.4 KiB/s)
Applying kernel provided DT overlay sun8i-h3-spi-spidev.dtbo
504 bytes read in 7 ms (70.3 KiB/s)
Applying kernel provided DT overlay sun8i-h3-usbhost2.dtbo
504 bytes read in 7 ms (70.3 KiB/s)
Applying kernel provided DT overlay sun8i-h3-usbhost3.dtbo
4155 bytes read in 8 ms (506.8 KiB/s)
Applying kernel provided DT fixup script (sun8i-h3-fixup.scr)
## Executing script at 44000000
libfdt fdt_path_offset() returned FDT_ERR_NOTFOUND
## Loading init Ramdisk from Legacy Image at 43300000 ...

 

 

Link to comment
Share on other sites

7 minutes ago, Gullik said:

looks like it is applying sun8i-h3-spi-spidev.dtbo, it is "stock" except I changed "disabled" to "okay" in two places....

You don't have to change that, the fixup script will take care of applying an "okay" to the specified "param_spidev_spi_bus=1".

8 minutes ago, Gullik said:

libfdt fdt_path_offset() returned FDT_ERR_NOTFOUND

That is the error which seem to be the cause of the problem...

Do you still have this error if you revert to the original overlay ?

(I've just tested on my OPiZero with DEV 5.2.y, and everything just ran fine ...)

 

Link to comment
Share on other sites

And this is the spidev dts, that i processed with dts and stored under it's default name in /boot/dtb/overlays/

sun8i-h3-spi-spidev.dtbo

It is 772 bytes, as opposed to 780 original, two times disabled changed to okay.

 

od -a shows "okay" in the dtbo now....

 

 

root@orangepizero:~# more test1.dts
/dts-v1/;

/ {
        compatible = "allwinner,sun8i-h3";

        fragment@0 {
                target-path = "/aliases";

                __overlay__ {
                        spi0 = "/soc/spi@1c68000";
                        spi1 = "/soc/spi@1c69000";
                };
        };

        fragment@1 {
                target = <0xffffffff>;

                __overlay__ {
                        #address-cells = <0x1>;
                        #size-cells = <0x0>;

                        spidev {
                                compatible = "spidev";
                                status = "okay";
                                reg = <0x0>;
                                spi-max-frequency = <0xf4240>;
                        };
                };
        };

        fragment@2 {
                target = <0xffffffff>;

                __overlay__ {
                        #address-cells = <0x1>;
                        #size-cells = <0x0>;

                        spidev {
                                compatible = "spidev";
                                status = "okay";
                                reg = <0x0>;
                                spi-max-frequency = <0xf4240>;
                        };
                };
        };

        __fixups__ {
                spi0 = "/fragment@1:target:0";
                spi1 = "/fragment@2:target:0";
        };
};

Link to comment
Share on other sites

Same error with original dtbo

## Executing script at 43100000
U-boot loaded from SD
Boot script loaded from mmc
265 bytes read in 2 ms (128.9 KiB/s)
8127296 bytes read in 629 ms (12.3 MiB/s)
7494704 bytes read in 577 ms (12.4 MiB/s)
Found mainline kernel configuration
29807 bytes read in 11 ms (2.6 MiB/s)
780 bytes read in 6 ms (127 KiB/s)
Applying kernel provided DT overlay sun8i-h3-spi-spidev.dtbo
504 bytes read in 7 ms (70.3 KiB/s)
Applying kernel provided DT overlay sun8i-h3-usbhost2.dtbo
504 bytes read in 6 ms (82 KiB/s)
Applying kernel provided DT overlay sun8i-h3-usbhost3.dtbo
4155 bytes read in 7 ms (579.1 KiB/s)
Applying kernel provided DT fixup script (sun8i-h3-fixup.scr)
## Executing script at 44000000
libfdt fdt_path_offset() returned FDT_ERR_NOTFOUND
## Loading init Ramdisk from Legacy Image at 43300000 ...
   Image Name:   uInitrd
   Image Type:   ARM Linux RAMDisk Image (gzip compressed)
   Data Size:    8127232 Bytes = 7.8 MiB
   Load Address: 00000000
   Entry Point:  00000000
   Verifying Checksum ... OK
## Flattened Device Tree blob at 43000000
   Booting using the fdt blob at 0x43000000
EHCI failed to shut down host controller.
   Loading Ramdisk to 4983f000, end 49fff300 ... OK
   Loading Device Tree to 497cf000, end 4983efff ... OK

Starting kernel ...

 

Link to comment
Share on other sites

root@orangepizero:~# uname -a
Linux orangepizero 4.19.57-sunxi #5.90 SMP Fri Jul 5 17:58:43 CEST 2019 armv7l armv7l armv7l GNU/Linux

 

picked up from the armbian download page

 

I could probably build myself, but am not set up for that. I have an older OPI Z with working SPI, will look at

what kernel it has. All my devices are loaded from armbian download page....

 

Regards,

Gullik

Link to comment
Share on other sites

1 hour ago, Gullik said:

picked up from the armbian download page

I've downloaded this image : https://dl.armbian.com/orangepizero/archive/Armbian_5.90_Orangepizero_Debian_buster_next_4.19.57.7z

Written to SD, booted, setup passwd and new user, and finally added SPI1 overlay in /boot/armbianEnv.txt and rebooted : /dev/spidev1.0 is working out-of-the-box !

 

So, it lead me to think that you SD or image is somehow corrupted ... :wacko:

Re-install usig the above link and report back here ! :P

Link to comment
Share on other sites

Thank you very much martinayotte, that worked like a charm :-)

 

I misspelled spi_spidev at first, and got the same error, I might try the other image again, and triple verify spelling,

something nonprintable?? anyway, the debian buster image is perfect for my use, and once the keyword was right

it behaved exactly as documented / per your instructions.

 

Best Regards,

Gullik

Link to comment
Share on other sites

Hi again,

 

No, first time I tried ( when it failed ) I surely did a cut'n'paste from the web into armbianEnv.txt with these parameters.

 

This time with the image you pointed me at, I wrote

 

overlays=spi_spidev usbhost2 usbhost3

 

instead of

 

overlays=spi-spidev usbhost2 usbhost3

 

by manual editing. Then before I posted the results (fail) , I double-checked, and found the mistake.

 

After that all worked as expected. This lead me to believe that I *might* get a good result if I test again and re-edit the

Env.txt, I cannot understand why it did not work as described, I guess I will do that and post again, just to close this issue properly

If that fails, then there *is* an issue with the OS image I used. I have not observed anything else wrong with that image though.

But Debian Buster is fine with me.

 

Regards & Thanx

 

Gullik

Link to comment
Share on other sites

Respected Martinayotte.

 

I have Cubieboard2, Armbian 21.02.2.

:~# uname -r => 5.10.16 - sunxi.

 

I have checked up and has adjusted all

but SPI0 not working.!!!

 

/boot/armbianEnv.txt^

....

overlays=spi-spidev
param_spidev_spi_bus=0
param_spidev_spi_cs=0
param_spidev_max_freq = 1000000

....

 

/dev/spidev0.0 is OK

find /dev -name spidev* => /dev/spidev0.0

 

Log from ttyS0^

....

Applying kernel provided DT overlay sun7i-a20-spi-spidev.dtbo
5532 bytes read in 12 ms (450.2 KiB/s)
Applying kernel provided DT fixup script (sun7i-a20-fixup.scr)

....

dmesg =>

[    4.171379] spidev spi0.0: probing from DT

 

sun7i-a20-cubieboard2.dts =>

...

                spi@1c05000 {
                        compatible = "allwinner,sun4i-a10-spi";
                        reg = < 0x1c05000 0x1000 >;
                        interrupts = < 0x00 0x0a 0x04 >;
                        clocks = < 0x02 0x2c 0x02 0x70 >;
                        clock-names = "ahb\0mod";
                        dmas = < 0x0c 0x01 0x1b 0x0c 0x01 0x1a >;
                        dma-names = "rx\0tx";
                        status = "okay";
                        #address-cells = < 0x01 >;
                        #size-cells = < 0x00 >;
                        num-cs = < 0x04 >;
                        phandle = < 0x41 >;
                };

...

                pinctrl@1c20800 {
                        compatible = "allwinner,sun7i-a20-pinctrl";
                        reg = < 0x1c20800 0x400 >;

 ...                      

                       spi0-pi-pins {
                                pins = "PI11\0PI12\0PI13";
                                function = "spi0";
                                phandle = < 0x73 >;
                        };

                        spi0-cs0-pi-pin {
                                pins = "PI10";
                                function = "spi0";
                                phandle = < 0x74 >;
                        };

                        spi0-cs1-pi-pin {
                                pins = "PI14";
                                function = "spi0";
                                phandle = < 0x75 >;
                        };

...

 

Out of programm spidev_test.c: (MOSI connect to MISO)

 

root@cubieboard2:~/Public# ./spidev_test
spi mode: 0
bits per word: 8
max speed: 500000 Hz (500 KHz)

00 00 00 00 00 00
00 00 00 00 00 00
00 00 00 00 00 00
00 00 00 00 00 00
00 00 00 00 00 00
00 00 00 00 00 00
00 00

 

Out programm mcp3008test.cpp:

 

root@cubieboard2:~/Public# ./testspi
writing command 1 1 0
transmit failed spi data ... ioctl failed : Invalid argument   ---?
root@cubieboard2:~/Public# ./testspi
writing command 1 1 0
transmit failed spi data ... ioctl failed : Invalid argument  ---?
root@cubieboard2:~/Public# ./testspi
writing command 1 1 0
transmit failed spi data ... ioctl failed : Invalid argument  ---?
root@cubieboard2:~/Public# ./testspi
writing command 1 1 0
reading data 0 0 0
count = 0 voltage 0.0000
writing command 1 1 0
reading data 0 0 0
count = 0 voltage 0.0000
writing command 1 1 0
reading data 0 0 0
count = 0 voltage 0.0000
writing command 1 1 0
reading data 0 0 0
count = 0 voltage 0.0000
writing command 1 1 0
reading data 0 0 0
count = 0 voltage 0.0000
^C
root@cubieboard2:~/Public#

...

 

Not error, SPI0 not working.

 

Help me please^)

Edited by TashaGrabovski
need edit
Link to comment
Share on other sites

Same here. No SPI device. My Linux nanopineo 5.15.25-sunxi #22.02.1 breaks SPI!

How do I downgrade to a previous kernel? Please help!

 

Update:

apt install linux-image-legacy-sunxi (kernel 5.4.88) just killed my NanoPi Neo... Does not boot anymore... :angry:

 

Update 2:

Follow ups to this issue here to have a clean new discussion...

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...

Important Information

Terms of Use - Privacy Policy - Guidelines