3 3
hajs

How to enable hardware SPI

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

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites
3 hours ago, Gullik said:

param_spidev_spi_bus=0

Why SPI0, do you try to access the spi-flash ?

If not, if you wish to get SPI on the header, then you should have "param_spidev_spi_bus=1" instead ...

 

Share this post


Link to post
Share on other sites

Thanks,

 

That's right, but bus=1 does not create any spi device either....so it is something more fundamental...

 

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

 

Gullik

Share this post


Link to post
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 ?

Share this post


Link to post
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 ...

 

 

Share this post


Link to post
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 ...)

 

Share this post


Link to post
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";
        };
};

Share this post


Link to post
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 ...

 

Share this post


Link to post
Share on other sites

and the fixup script is there

 

/boot/dtb/overlay/sun8i-h3-fixup.scr

 

Regards,

Gullik

Share this post


Link to post
Share on other sites
39 minutes ago, Gullik said:

Same error with original dtbo

Which kernel image it is ? (I will give it a try myself)

Are you able to do your own build using DEV 5.2.y ?

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

The old working spi system had

 

Linux orangepizero 3.4.113-sun8i #68 SMP PREEMPT Wed Sep 19 10:23:30 CEST 2018 armv7l GNU/Linux

 

Quite a time lapse, eh?

 

Regards,

Gullik

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites
4 hours ago, Gullik said:

I misspelled spi_spidev at first

Do you mean that you've misspelled the parameter "param_spidev_spi_bus=1" by using "param_spi_spidev_bus=1" instead ?

Share this post


Link to post
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

Share this post


Link to post
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...
3 3