Jump to content
  • 0

SPI with NanoPi M4


Jeffer
 Share

Question

Hi, I'm currently working to enable SPI on NanoPi M4 but it is not working...

I have edited main DT to the following one and now /dev/spidev0.0 appears.

Quote

        spi@ff1c0000 {

                compatible = "rockchip,rk3399-spi\0rockchip,rk3066-spi";

                reg = < 0x00 0xff1c0000 0x00 0x1000 >;

                clocks = < 0x08 0x47 0x08 0x15b >;

                clock-names = "spiclk\0apb_pclk";

                interrupts = < 0x00 0x44 0x04 0x00 >;

                pinctrl-names = "default";

                pinctrl-0 = < 0x4a 0x4b 0x4c 0x4d >;

                #address-cells = < 0x01 >;

                #size-cells = < 0x00 >;

                status = "okay";

                phandle = < 0x101 >;

                        spidev{

                    compatible = "spidev";

                    status = "okay";

                    reg = <0>;

                    spi-max-frequency = <10000000>;

                };

        };

 

 

But when I checked spi with this tool:https://github.com/torvalds/linux/blob/master/tools/spi/spidev_test.c

I only got the result below and no matrix appears...

spi mode: 0x0

bits per word: 8

max speed: 500000 Hz (500 KHz)

 

Here is what dmesg | grep spi returns 

Quote

[    1.560666] rockchip-spi ff1c0000.spi: Failed to request TX DMA channel

[    1.560679] rockchip-spi ff1c0000.spi: Failed to request RX DMA channel

[    1.560689] rockchip-spi ff1c0000.spi: no high_speed pinctrl state

[    1.561289] spidev spi0.0: buggy DT: spidev listed directly in DT

[    1.561365] WARNING: at drivers/spi/spidev.c:720

[    1.561421] PC is at spidev_probe+0x6c/0x1d8

[    1.561430] LR is at spidev_probe+0x68/0x1d8

[    1.564338] [<ffffff80086f86b0>] spidev_probe+0x6c/0x1d8

[    1.564348] [<ffffff80086f57c4>] spi_drv_probe+0x9c/0xb4

[    1.564433] [<ffffff80086f605c>] spi_add_device+0x12c/0x188

[    1.564443] [<ffffff80086f6424>] of_register_spi_device+0x2c0/0x2d8

[    1.564453] [<ffffff80086f78f8>] spi_register_master+0x448/0x484

[    1.564463] [<ffffff80086f7988>] devm_spi_register_master+0x54/0x94

[    1.564474] [<ffffff80086fac60>] rockchip_spi_probe+0x2ec/0x440

[    1.564568] [<ffffff80090f94f8>] rockchip_spi_driver_init+0x18/0x20

[    1.566326] rockchip-pinctrl pinctrl: pin gpio3-7 already requested by ff1c0000.spi; cannot claim for fe300000.ethernet

 

I have checked the output from the proper GPIO with oscilloscope but found nothing.

almost spent couple weeks on this 

 

Anyone had the same issue or knows what to do here?

Link to comment
Share on other sites

10 answers to this question

Recommended Posts

  • 0

@Nao - Do you have any more details on how you got to this point ?

 

I have made an image using the Armbian repo:

https://github.com/armbian/build/

 

I then use the Device Tools to inspect the tree:
 

# fdtdump /boot/dtb/rockchip/rk3399-nanopi4-rev01.dtb > device_tree.txt

 

This shows:

...
	aliases {
		spi1 = "/spi@ff1d0000";
	};
...
    spi@ff1c0000 {
        compatible = "rockchip,rk3399-spi", "rockchip,rk3066-spi";
        reg = <0x00000000 0xff1c0000 0x00000000 0x00001000>;
        clocks = <0x00000008 0x00000047 0x00000008 0x0000015b>;
        clock-names = "spiclk", "apb_pclk";
        interrupts = <0x00000000 0x00000044 0x00000004 0x00000000>;
        pinctrl-names = "default";
        pinctrl-0 = <0x0000004c 0x0000004d 0x0000004e 0x0000004f>;
        #address-cells = <0x00000001>;
        #size-cells = <0x00000000>;
        status = "disabled";
        phandle = <0x00000105>;
    };
    spi@ff1d0000 {
        compatible = "rockchip,rk3399-spi", "rockchip,rk3066-spi";
        reg = <0x00000000 0xff1d0000 0x00000000 0x00001000>;
        clocks = <0x00000008 0x00000048 0x00000008 0x0000015c>;
        clock-names = "spiclk", "apb_pclk";
        interrupts = <0x00000000 0x00000035 0x00000004 0x00000000>;
        pinctrl-names = "default";
        pinctrl-0 = <0x00000050 0x00000051 0x00000052 0x00000053>;
        #address-cells = <0x00000001>;
        #size-cells = <0x00000000>;
        status = "disabled";
        cs-gpios = <0x00000035 0x0000000a 0x00000001>;
        phandle = <0x00000106>;
        spidev@0 {
            compatible = "rockchip,spidev";
            reg = <0x00000000>;
            spi-max-frequency = <0x00989680>;
            status = "okay";
            phandle = <0x00000107>;
        };
    };

 

I noticed it says its disabled, but if I enable it with:
 

# fdtput /boot/dtb/rockchip/rk3399-nanopi4-rev01.dtb spi1 status -t s "okay"

Then the device wont boot.

 

If you dont mind sharing some of the commands you used to get the debug output and enable the interface, that'd be great.

Link to comment
Share on other sites

When discussing a problem make sure to provide full logs!

  • 0
On 2/18/2019 at 1:44 PM, Exie said:

If you dont mind sharing some of the commands you used to get the debug output and enable the interface, that'd be great.

sorry I edited a status at a wrong spi (actually it was spi@ff1c0000, which corresponds to the SPI0 which is only for SPIFlash) and after edited the status at spi@ff1d0000, my machine doesn't boot...

 

basically I followed an instruction mentioned here, 

 

Link to comment
Share on other sites

  • 0

Just a follow up on SPI .....

 

I found updating the device tree (dtb file) like so:

# fdtput /boot/dtb/rockchip/rk3399-nanopi4-rev01.dtb /spi@ff1d0000 status -t s "okay"
# fdtput /boot/dtb/rockchip/rk3399-nanopi4-rev01.dtb /serial@ff370000 status -t s "disabled"

I found disabling the serial thing made it all stable so the device didnt lock up.

 

This enabled the device in the tree like so:

    spi@ff1d0000 {
        compatible = "rockchip,rk3399-spi", "rockchip,rk3066-spi";
        reg = <0x00000000 0xff1d0000 0x00000000 0x00001000>;
        clocks = <0x00000008 0x00000048 0x00000008 0x0000015c>;
        clock-names = "spiclk", "apb_pclk";
        interrupts = <0x00000000 0x00000035 0x00000004 0x00000000>;
        pinctrl-names = "default";
        pinctrl-0 = <0x00000050 0x00000051 0x00000052 0x00000053>;
        #address-cells = <0x00000001>;
        #size-cells = <0x00000000>;
        status = "okay";
        cs-gpios = <0x00000035 0x0000000a 0x00000001>;
        phandle = <0x00000106>;
        spidev@0 {
            compatible = "rockchip,spidev";
            reg = <0x00000000>;
            spi-max-frequency = <0x00989680>;
            status = "okay";
            phandle = <0x00000107>;
        };
    };

I can see the device here:

root@nanopim4:~# ls -l /dev/spidev1.0
crw------- 1 root root 153, 0 Feb 28 11:46 /dev/spidev1.0

 

However loading the fbtft driver still doesnt seem happy, reporting the controller is busy....

[   45.573108] fbtft: module is from the staging directory, the quality is unknown, you have been warned.
[   45.592470] fbtft_device: module is from the staging directory, the quality is unknown, you have been warned.
[   45.594705] spidev spi1.0: spidev spi1.0 10000kHz 8 bits mode=0x00
[   45.594949] spidev spi1.0: Deleting spi1.0
[   45.595969] fbtft_device: GPIOS used by 'fb_st7789v':
[   45.595985] fbtft_device: 'reset' = GPIO32
[   45.595994] fbtft_device: 'dc' = GPIO56
[   45.596013] spi spi1.0: fb_st7789v spi1.0 32000kHz 8 bits mode=0x00
[   45.608977] fb_st7789v: module is from the staging directory, the quality is unknown, you have been warned.
[   45.618367] rockchip-spi ff1d0000.spi: spi controller is in busy state!

 

So I'm not 100% certain its working, but I feel like I'm getting closer.

Link to comment
Share on other sites

  • 0

Update:

I modified the device tree file via...

# dtc -@ -I dtb -O dts -o rk3399-nanopi4-rev01.dts /boot/dtb/rockchip/rk3399-nanopi4-rev01.dtb
# vi rk3399-nanopi4-rev01.dts
... add spidev section to spi@ff1c0000 ..
... update spi@ff1c0000 to status "okay"
# mv /boot/dtb/rockchip/rk3399-nanopi4-rev01.dtb /boot/dtb/rockchip/rk3399-nanopi4-rev01.dtb.backup
# dtc -@ -I dts -O dtb -o /boot/dtb/rockchip/rk3399-nanopi4-rev01.dtb rk3399-nanopi4-rev01.dts

 

.. but after booting dmesg shows:

[    2.518765] rockchip-pinctrl pinctrl: pin gpio3-7 already requested by ff1c0000.spi; cannot claim for fe300000.ethernet
[    2.518777] rockchip-pinctrl pinctrl: pin-103 (fe300000.ethernet) status -22
[    2.518786] rockchip-pinctrl pinctrl: could not request pin 103 (gpio3-7) from group rgmii-pins  on device rockchip-pinctrl

So I checked my device tree and it looks like its configured like so:
 

    spi@ff1c0000 {
        compatible = "rockchip,rk3399-spi", "rockchip,rk3066-spi";
        reg = <0x00000000 0xff1c0000 0x00000000 0x00001000>;
        clocks = <0x00000008 0x00000047 0x00000008 0x0000015b>;
        clock-names = "spiclk", "apb_pclk";
        interrupts = <0x00000000 0x00000044 0x00000004 0x00000000>;
        pinctrl-names = "default";
        pinctrl-0 = <0x0000004c 0x0000004d 0x0000004e 0x0000004f>;
        #address-cells = <0x00000001>;
        #size-cells = <0x00000000>;
        status = "okay";
        phandle = <0x00000105>;
        spidev {
            compatible = "spidev";
            status = "okay";
            reg = <0x00000000>;
            spi-max-frequency = <0x00989680>;
        };
    };

So...... it sounds like its complaining about pin-103 ? but I cant see any reference to that in the spi specification. So I'm not 100% sure where the conflict is.

For reference, it DID create a new device (/dev/spidev32766.0) ... which is not really what I was expecting.

 

Given the voodoo magic that seems to drive this device, is there any useful reference we can use to line up exactly what ff1c0000 and ff1d0000  should be ? Some posts suggest that spi@ff1c0000 is mapped to the eMMC slot or something.

Link to comment
Share on other sites

  • 0

I did the same thing with the nightly and got the following 

Quote

$ ls -l /dev/spidev*

crw------- 1 root root 153, 0 Mar 19 02:38 /dev/spidev0.0

crw------- 1 root root 153, 1 Mar 19 02:38 /dev/spidev1.0

$ dmesg | grep spi

[    2.608230] rockchip-spi ff1c0000.spi: Failed to request TX DMA channel

[    2.608293] rockchip-spi ff1c0000.spi: Failed to request RX DMA channel

[    2.611627] rockchip-spi ff1d0000.spi: Failed to request TX DMA channel

[    2.611676] rockchip-spi ff1d0000.spi: Failed to request RX DMA channel

[    3.101184] rockchip-pinctrl pinctrl: pin gpio3-7 already requested by ff1c0000.spi; cannot claim for fe300000.ethernet

 

so I tested this spidev1.0 with spidev_test.c

but again, it returned this

Quote

$ sudo ./a.out -D /dev/spidev1.0

[sudo] password for pi:

spi mode: 0x0

bits per word: 8

max speed: 1000000 Hz (1000 KHz)

 

Link to comment
Share on other sites

  • 0

Hi 

i am using Nano pi M4 board and friendly arm lubuntu.

 

tried with npi-config to enable SPI but it was not allowed to enable.and showing error!!

I also tried to enable through terminal , but spidev is not shown in /dev/,

also i saw some of comments for enabling spi from dtb file , but for me inside boot directory it was empty . please help how to enable the SPI pin for nanopi m4.

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
Answer this question...

×   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...
 Share

×
×
  • Create New...