0
Serge

NanoPI Neo Core. How to activate a second SPI

Recommended Posts

board: http://nanopi.io/nanopi-neo-core.html

image: Armbian Bionic mainline based kernel 4.19.38 from https://www.armbian.com/nanopi-neo/

There are two SPI separated buses with separated pins on NanoPi Core: SPI0 and SPI1

 

 /boot/armbianEnv.txt:

...

overlay-prefix=sun8i-h3

overlays=analog-codec i2c0 spi-spidev uart1 usbhost3

param_spidev_spi_bus=0

...

/dev/spidev0.0 presents

 

How to activate a SPI1?

Share this post


Link to post
Share on other sites
2 hours ago, Serge said:

How to activate a SPI1?

With the current overlays, you can't have both SPIs at the same time, but you can create a custom SPI overlay that won't need any params and having both enabled by default.

Share this post


Link to post
Share on other sites

does it mean the way to ./build/patch/kernel/sunxi-dev/my-super-2spi.patch?

Share this post


Link to post
Share on other sites
40 minutes ago, Serge said:

does it mean the way to ./build/patch/kernel/sunxi-dev/my-super-2spi.patch?

Not necessarily ...

Such overlay could be compiled locally on the nanopi if you install DT compiler there. You can download it from http://ftp.debian.org/debian/pool/main/d/device-tree-compiler/device-tree-compiler_1.4.7-3_armhf.deb

Then, you can have something like this (not tested) :

/dts-v1/;
/plugin/;

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

    fragment@0 {
	target-path = "/aliases";
	__overlay__ {
            /* Path to the SPI controller nodes */
            spi0 = "/soc@01c00000/spi@01c68000";
            spi1 = "/soc@01c00000/spi@01c69000";
        };
    };
    fragment@1 {
        target = <&spi0>;
        __overlay__ {
            pinctrl-names = "default";
            pinctrl-0 = <&spi0_pins>;
            status = "okay";
            #address-cells = <1>;
            #size-cells = <0>;
            spidev@0 {
                compatible = "spidev";
                reg = <0x0>;
                spi-max-frequency = <500000>;
            };
        };
    };
    fragment@2 {
        target = <&spi1>;
        __overlay__ {
            pinctrl-names = "default";
            pinctrl-0 = <&spi1_pins>;
            status = "okay";
            #address-cells = <1>;
            #size-cells = <0>;
            spidev@0 {
                compatible = "spidev";
                reg = <0x0>;
                spi-max-frequency = <500000>;
            };
        };
    };
};

 

Share this post


Link to post
Share on other sites

martinayotte, I've decompile original ...nanopi-neo.dtb file and found there are both spi's are enabled in .dtb file

the question is about correct parameter in armbianEnv.txt:

param_spidev_spi_bus=0

param_spidev_spi_bus=1

or

param_spidev_spi_bus=0 1 or how?

 

I didn't find any examples for using both SPIs. The most examples about SPI0 only.

 

at present project SPI1 will be used as well (it's a hardware connections of the shield) and SPI0 pins wil be used as GPIO pins.

later, I'd like to have possibility to use SPI0 also.

 

upd.:

param_spidev_spi_bus=1 - doesn't work .....upd2: conflict with serial because pin PA15  already requested by 1c28cc00.serial.....

PA15 is used bu uart3_rts_cts also (according original .dts file) but no UART3 interfaces on pinout:

http://wiki.friendlyarm.com/wiki/index.php/NanoPi_NEO_Core

I'm not going to use uart3 with rts_cts.

 

 

udp3:

I've remove all uart3 sections from decompiled .dts

now "param_spidev_spi_bus=1" is working and I can see /dev/spidev1.0

 

last question: for both SPIs using how I must setup a "param_spidev_bus"?

 

Share this post


Link to post
Share on other sites
2 hours ago, Serge said:

last question: for both SPIs using how I must setup a "param_spidev_bus"?

Unfortunately, as I said before the current overlays and fixup.scr don't support double SPI.

So, use my custom overlay I've provided, compile it and place it into /boot/overlay-user/ along with entry "user_overlays=mydualspi" in /boot/armbianEnv.txt, you don't "param_spidev_bus" anymore with that.

Share this post


Link to post
Share on other sites

martinayotte, I've tried to use a SPI1 only. 

/dev/spidev1.0 presents.

tried to use a standard IO C functions (open(), read()....) and with wiringPI lib - no result

tried to analyse a phisical levels with PulseView - looks like confusion between pins and signals and wrong timing of signal.

checked pins deffinition in .dts file - all according pin names from datasheeet

tried to assign pins in .dts according results of signals from PulseView... no result

because of urgent I wrote SPI "driver" manually - now all works

please advice how to check what's wrong with hardware SPI1?

 

Share this post


Link to post
Share on other sites

Hello martinayotte

done. Double SPI is working

1. decompile /boot/dtb/sun8i-h3-nanopi-neo.dtb by command 
dtc -b 0 -O dts -I dtb -o sun8i-h3-nanopi-neo.dts sun8i-h3-nanopi-neo.dtb

all warnings ignored
2. remove all rows with UART3 because pins conflict (https://docs.armbian.com/User-Guide_Allwinner_overlays/  Overlay pinmux conflicts)

3. backup a old .dtb and compile a new .dtb

dtc -b 0 -O dtb -I dts -o sun8i-h3-nanopi-neo.dtb sun8i-h3-nanopi-neo.dts

all warnings ignored

4. create a new double-spi.dts  as you wrote before (similar to https://github.com/armbian/sunxi-DT-overlays/blob/master/sun8i-h3/sun8i-h3-spi-spidev.dts)

5.  compile a double-spi.dts with

armbian-add-overlay double-spi.dts (refer to https://docs.armbian.com/User-Guide_Allwinner_overlays/)

after that checked /boot/overlay-user for double-spi.dtbo presenting

6. in /boot/armbianEnv.txt remove from "overlay=...." all parameters about spi and all rows with "param_spi_xxx"

7. reboot

8. both spidev0.0 and spidev1.0 in /dev presents

9. in armbian-config load all kermel sources and compile spidev_test in

/usr/src/linux-source-xxx/tools/spi

10. MISO_0 and MOSI_0 are connected, MISO_1 and MOSI_1 are connected (refer to https://github.com/rm-hull/spidev-test)

spidev_test --device /dev/spidev0.0 -v
spidev_test --device /dev/spidev1.0 -v
all responds are identical

 

PS. how to use a new sun8i-h3-nanopi-neo-core.dtb with all modufucations which I need instead sun8i-h3-nanopi-neo.dtb?

Share this post


Link to post
Share on other sites
2 hours ago, Serge said:

PS. how to use a new sun8i-h3-nanopi-neo-core.dtb with all modufucations which I need instead sun8i-h3-nanopi-neo.dtb?

What do you mean exactly ?

Do you simply wish that U-Boot should use a different file name ?

That could be workarounded in /boot/armbianEnv.txt by declaring "fdtfile=/boot/sun8i-h3-nanopi-neo-core.dtb" if I remember the syntax ...

 

 

Share this post


Link to post
Share on other sites

I mean:

now in /boot/armbianEnv.txt no "fdtfile" field

only "overlay_prefix=sun8i-h3"

Original DTB file which loadaed by the system is /boot/dtb/sun8i-h3-nanopi-neo.dtb (board is NanoPI Neo Core)

I'd like to keep /boot/dtb/sun8i-h3-nanopi-neo.dtb as is and create /boot/dtb/sun8i-h3-nanopi-neo-core.dtb with all modifications described above.

But in this case I have to direct the system to use a new DTB file.

Share this post


Link to post
Share on other sites
1 hour ago, Serge said:

now in /boot/armbianEnv.txt no "fdtfile" field

Of course : the default value of fdtfile is hard coded at u-boot compile time, but it can be overwritten by adding it to /boot/armbianEnv.txt .

 

EDIT: BTW, I've looked at /boot/boot.scr, it seems that "fdtfile" should be without path, only the DTB filename...

Share this post


Link to post
Share on other sites

where to read about it? in forum information is sketchy

Share this post


Link to post
Share on other sites
15 hours ago, Serge said:

where to read about it?

The "fdtfile" trick isn't explain anywhere, you need to learn about Armbian U-Boot internals...

As I'm a developer, I've simply remembered that /boot/boot.scr is responsible of loading the DTB with specific filename according to that "fdtfile" variable with default value assign at compile time.

But any U-Boot variables values could be overwritten by assigning them new value in /boot/armbianEnv.txt since this is loaded before actually loading DTB/Kernel/uInitrd.

 

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...
0