How to use SPI on Colibri IMX6ULL

Dear guys,

I uses correctly SPI on linux on VF61 and now I want to use the SPI on IMX6ULL.
My configuration is the following:
image: Linux LXDE Image 2.8b6 Ångström LXDE Desktop Environment Image
*linux-toradex *: toradex_5.4-2.1.x-imx
I change the following files: imx6ull-colibri.dtsi and imx6ull-colibri-eval-v3.dtsi
in order to activate the SPI [see the attachments]

imx6ull-colibri-eval-v3.dtsi

   &ecspi1 {        
   status = "okay";
    mcp2515: can@0 {
            compatible = "microchip,mcp2515";
            pinctrl-names = "default";
            pinctrl-0 = <&pinctrl_can_int>;
            reg = <0>;
            clocks = <&clk16m>;
            interrupt-parent = <&gpio2>;
            interrupts = <4 IRQ_TYPE_EDGE_FALLING>;
            spi-max-frequency = <10000000>;
            vdd-supply = <&reg_3v3>;
            xceiver-supply = <&reg_5v0>;
            status = "disabled";
    };


    spidev0: spidev@0 {
            compatible = "toradex,evalspi";
            reg = <0>;
            spi-max-frequency = <1000000>;
            status = "okay";
    };

    spidev1: spidev@1 {
            compatible = "toradex,evalspi";
            reg = <1>;
            spi-max-frequency = <1000000>;
            status = "okay";
    };

    spidev2: spidev@2 {
            compatible = "toradex,evalspi";
            reg = <2>;
            spi-max-frequency = <1000000>;
            status = "okay";
    };

and imx6ull-colibri.dtsi

          pinctrl_ecspi1_cs: ecspi1-cs-grp {
            fsl,pins = <
                    MX6UL_PAD_GPIO1_IO05__UART5_DTE_TX      0x1b0b1 /* SODIMM 21 */
                    MX6UL_PAD_JTAG_TDO__GPIO1_IO12          0x90b1 /* SODIMM 23 */
                    MX6UL_PAD_UART1_CTS_B__UART1_DTE_RTS    0x1b0b1 /* SODIMM 25 */
            >;
    };

    pinctrl_ecspi1: ecspi1-grp {
            fsl,pins = <
                    MX6UL_PAD_LCD_DATA20__ECSPI1_SCLK       0x000a0 /* SODIMM 88 */
                    MX6UL_PAD_LCD_DATA22__ECSPI1_MOSI       0x000a0 /* SODIMM 92 */
                    MX6UL_PAD_LCD_DATA23__ECSPI1_MISO       0x100a0 /* SODIMM 90 */
            >;
    };

and then I built the image and uploaded it on my 1 using the following commands:

On PC in linux-toradex:

make colibri_imx6ull_defconfig make -j3 zImage | tee build.log
make imx6ull-colibri-eval-v3.dtb

The build is right [see attachment].

Then I copied the zImage and imx6ull-colibri-eval.dtb in SD_CARD\Colibri-iMX6ULL_LXDE-Image-Tezi_2.8b7
Using toradex Easy image I installed the image.
The new Image is uploaded. I did not found the three devices /dev/spidev0.0, /dev/spidev0.1 and /dev/spidev0.2 on my IMX&ULL.

Could you tell me what I’m wrong?

Thank you

Best regards

Matteo

HI @Matte

Thanks for writing to the Toradex Community!

Linux LXDE Image 2.8b6 Ångström LXDE Desktop Environment Image linux-toradex : toradex_5.4-2.1.x-imx I change the following files: imx6ull-colibri.dtsi and imx6ull-colibri-eval-v3.dtsi

Please don’t mixup Bsp Versions with Linux Kernel version. Bsp 2.8b6 is based on 4.9.x kernel and not 5.4.x kernel. Thus if you want to use Bsp 2.8.7, then please use 4.9.2.3 branch for the kernel.

The new Image is uploaded. I did not found the three devices /dev/spidev0.0, /dev/spidev0.1 and /dev/spidev0.2 on my IMX&ULL.

Could you share the dmesg.log in a text file?

Thanks and best regards,
Jaski

type “dmesg” at command prompt.

Thank you for your replay.
Where can I find the dmesg.log?
Best regards
Matteo

Dear @jaski.tx,
I changed the branch and I rebuilt the 4.9.2.3 with my changed.But I had again the same problem: I don’t found the spi device.
I attached the dmes.log link text
Could you help me?
Best regards
Matteo

hi @Matte

According to your dmesg.log, you have several pin conflict errors. Could you correct them?

[    1.376123] imx6ul-pinctrl 20e0000.iomuxc: pin MX6UL_PAD_GPIO1_IO05 already requested by 21f4000.serial; cannot claim for 2008000.ecspi
[    1.395653] imx6ul-pinctrl 20e0000.iomuxc: pin-28 (2008000.ecspi) status -22
[    1.406431] imx6ul-pinctrl 20e0000.iomuxc: could not request pin 28 (MX6UL_PAD_GPIO1_IO05) from group ecspi1-cs-grp  on device 20e0000.iomuxc
[    1.426214] spi_imx 2008000.ecspi: Error applying setting, reverse things back
[    1.440829] spi_imx: probe of 2008000.ecspi failed with error -22

Best regards,
Jaski

Dear @jaski.tx,
Thank fir your replay.
I understood the problem, the I’m changing the PIN.
Of I have again any problem, I’ll contact you.
Best regards
Matteo

Perfect. Please let us know if you have any other questions.

Dear @jaski.tx,
I want to use the following pins for the SPI:

              MX6UL_PAD_GPIO1_IO05__GPIO05	0x70a0 /* SODIMM 21 */
              MX6UL_PAD_JTAG_TDO__GPIO1_IO12		0x70a0 /* SODIMM 23 */
              MX6UL_PAD_UART1_CTS__GPIO1_IO18	0x70a0	/* SODIMM 25 */

Can I use them?

Because I have again the conflict problem and I don’t understand how I can to solve it.

Do I need to disable the functionality that I don’t use?
I attachs the files imx6ull-colibri.dtsi and imx6ull-colibri-eval-v3.dtsi. link text

Could you help me?

Best regards

Matteo

Hi @Matte

Can I use them?

Sure, you can use the Pins.

Because I have again the conflict problem and I don’t understand how I can to solve it.

You need to check the Pins you want to use are not defined anywhere else.

Do I need to disable the functionality that I don’t use? I attach the files imx6ull-colibri.dtsi and imx6ull-colibri-eval-v3.dtsi. link text

Yes. You need to choose which Pins you want to use for which functionality.
By the way, the files you sent me, are they compiling without errors?

Best regards,
Jaski

Dear @jaski.tx,
Thank you for your replay.
I sent you a wrong file, I fixed the file and now they compile correctly. link text
Could you confirm me that the the following Pin name it’s right?

              pinctrl_ecspi1_cs: ecspi1-cs-grp {
	         fsl,pins = <
             `         MX6UL_PAD_GPIO1_IO05__GPIO1_IO05	0x70a0 /* SODIMM 21 */
                       MX6UL_PAD_JTAG_TDO__GPIO1_IO12		0x70a0 /* SODIMM 23 */
                       MX6UL_PAD_UART1_CTS_B__GPIO1_IO18  	0x70a0	/* SODIMM 25 */
        	>;
    	};

On thre tree at the moment:

    PIN 21 It's used on **uart5grp** 
    PIN 23 it's used on  **uart1-ctrlgrp1**
    PIN 25 it's used on **uart1-grp**

Do I need to disable this uart1 and uart5 to use them?
Thank you
Best Regards

Hi @Matte

Thanks for the files. They seems to be correct.

Do I need to disable this uart1 and uart5 to use them?

Yes, you need to disable them or use other pins. You can disable UART5 but disabling UART1 will lead to lose of the console and you need to redirect the console to a different UART Port.

Best regards,
Jaski

Dear @jaski.tx,
Thank for your support.
In order to disable the uart5 do I need to change its status on imx6ull-colibri-eval-v3.dtsi

       &uart5 {
            status = "disable";
         };

Is it right?

Best regards

Matteo

You are welcome.

It should be

status = "disabled";

Please check the existing device-tree files for this.

Thank for your replay.

I have a last question about the choose of PIN.

If I want to use the camera’s PIN because I’m sure that to do not used that feature.
I need to remove the pinctrl_hog_2 from iomuxc of file imx6ull-colibri-nonwifi.dtsi
and the I can add those PIN on SPI section or is there any other way to do it?

Best regards

Matteo

You are welcome.

I need to remove the pinctrl_hog_2 from iomuxc of file imx6ull-colibri-nonwifi.dtsi and the I can add those PIN on SPI section or is there any other way to do it?

Yes, or you just make sure that the pinctrl_hog_2 is not used anywhere in the devicetree.

Best regards,
Jaski

Dear @jaski.tx,
I decided to use the UART2 PINS for SPI, I disabled the UART2 and inserted the PINS on SPI Section I compiled the tree link text.

When I do dmesg on the IMX6ULL I have the following error:

[    1.341373] gpmi-nand 1806000.gpmi-nand: driver registered.
[    1.355765] spi_imx 2008000.ecspi: cs1 >= max 1
[    1.363888] spi_master spi0: spi_device register error /soc/aips-bus@02000000/spba-bus@02000000/ecspi@02008000/spidev@1
[    1.381565] spi_master spi0: Failed to create SPI device for /soc/aips-bus@02000000/spba-bus@02000000/ecspi@02008000/spidev@1
[    1.400095] spi_imx 2008000.ecspi: cs2 >= max 1
[    1.408240] spi_master spi0: spi_device register error /soc/aips-bus@02000000/spba-bus@02000000/ecspi@02008000/spidev@2
[    1.426377] spi_master spi0: Failed to create SPI device for /soc/aips-bus@02000000/spba-bus@02000000/ecspi@02008000/spidev@2
[    1.445284] spi_imx 2008000.ecspi: cs3 >= max 1
[    1.453559] spi_master spi0: spi_device register error /soc/aips-bus@02000000/spba-bus@02000000/ecspi@02008000/spidev@3
[    1.471824] spi_master spi0: Failed to create SPI device for /soc/aips-bus@02000000/spba-bus@02000000/ecspi@02008000/spidev@3
[    1.491079] spi_imx 2008000.ecspi: probed

The configuration of the tree is the following:

spidev0: spidev@0 {
        compatible = "toradex,evalspi";
        reg = <0>;
        spi-max-frequency = <1000000>;
            status = "okay";
 };

spidev1: spidev@1 {
        compatible = "toradex,evalspi";
        reg = <1>;
        spi-max-frequency = <1000000>;
        status = "okay";
};

spidev2: spidev@2 {
        compatible = "toradex,evalspi";
        reg = <2>;
        spi-max-frequency = <1000000>;
        status = "okay";
};

spidev3: spidev@3 {
        compatible = "toradex,evalspi";
        reg = <3>;
        spi-max-frequency = <1000000>;
        status = "okay";
};

Could you tell me what I’m wrong?

Hi @Matte

You need to use the num-cs property and not the fsl,spi-num-chipselects since iMX6ULL is using a different spi driver ( drivers/spi/spi-imx.c ) as mentioned in ( arch/arm/boot/dts/imx6ul.dtsi ).

With the patch below you should be able to get the spidev devices you want. The colibri-spi-csx are symbolic links for the spidev0.x devices.

Best regards,
Jaski

diff --git a/arch/arm/boot/dts/imx6ull-colibri-eval-v3.dtsi b/arch/arm/boot/dts/imx6ull-colibri-eval-v3.dtsi
index 96f4438a3569..20084ec7ae0f 100644
--- a/arch/arm/boot/dts/imx6ull-colibri-eval-v3.dtsi
+++ b/arch/arm/boot/dts/imx6ull-colibri-eval-v3.dtsi
@@ -94,15 +94,39 @@
 		spi-max-frequency = <10000000>;
 		vdd-supply = <&reg_3v3>;
 		xceiver-supply = <&reg_5v0>;
-		status = "okay";
-	};
-
-	spidev0: spidev@0 {
-		compatible = "toradex,evalspi";
-		reg = <0>;
-		spi-max-frequency = <23000000>;
 		status = "disabled";
 	};
+
+
+        spidev0: spidev@0 {
+                compatible = "toradex,evalspi";
+                reg = <0>;
+                spi-max-frequency = <1000000>;
+                status = "okay";
+        };
+
+
+        spidev1: spidev@1 {
+                compatible = "toradex,evalspi";
+                reg = <1>;
+                spi-max-frequency = <1000000>;
+                status = "okay";
+        };
+
+
+         spidev2: spidev@2 {
+                compatible = "toradex,evalspi";
+                reg = <2>;
+                spi-max-frequency = <1000000>;
+                status = "okay";
+        };
+
+      spidev3: spidev@3 {
+                compatible = "toradex,evalspi";
+                reg = <3>;
+                spi-max-frequency = <1000000>;
+                status = "okay";
+        };
 };
 
 &can1 {
@@ -298,7 +322,7 @@
 };
 
 &uart2 {
-	status = "okay";
+	status = "disabled";
 };
 
 &uart5 {
diff --git a/arch/arm/boot/dts/imx6ull-colibri.dtsi b/arch/arm/boot/dts/imx6ull-colibri.dtsi
index 10d3605e0ac4..3ef13ae776f7 100644
--- a/arch/arm/boot/dts/imx6ull-colibri.dtsi
+++ b/arch/arm/boot/dts/imx6ull-colibri.dtsi
@@ -106,7 +106,11 @@
 
 /* Colibri SPI */
 &ecspi1 {
-	cs-gpios = <&gpio3 26 GPIO_ACTIVE_HIGH>;
+	fsl,spi-num-chipselects = <4>;
+	cs-gpios =  <&gpio1 20 GPIO_ACTIVE_LOW>,
+				<&gpio1 21 GPIO_ACTIVE_LOW>,
+				<&gpio1 22 GPIO_ACTIVE_LOW>,
+				<&gpio1 23 GPIO_ACTIVE_LOW>;
 	pinctrl-names = "default";
 	pinctrl-0 = <&pinctrl_ecspi1 &pinctrl_ecspi1_cs>;
 };
@@ -319,7 +323,10 @@
 
 	pinctrl_ecspi1_cs: ecspi1-cs-grp {
 		fsl,pins = <
-			MX6UL_PAD_LCD_DATA21__GPIO3_IO26	0x70a0	/* SODIMM 86 */
+			MX6UL_PAD_UART2_CTS_B__GPIO1_IO22	0x70a0 /* SODIMM 32 */
+			MX6UL_PAD_UART2_RTS_B__GPIO1_IO23	0x70a0 /* SODIMM 34 */
+			MX6UL_PAD_UART2_RX_DATA__GPIO1_IO21  	0x70a0	/* SODIMM 38 */
+			MX6UL_PAD_UART2_TX_DATA__GPIO1_IO20  	0x70a0	/* SODIMM 36 */
 		>;
 	};

Thank you,

now I have 4 SPI, and I seem everything right.

Matteo

Perfect that it works. Thanks for that feedback.

Best regards,
Jaski