ECSPI2 on i.MX8M Mini EVK

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

ECSPI2 on i.MX8M Mini EVK

6,246 Views
david_ochs1
Contributor III

Hi, 

I see that the ECSPI2 pins are brought out on J1003 on the imx8mmevk board, but I can't seem to make SPI work. I try running the ECSPI unit test, but it fails suggesting the device isn't present. Can someone please provide direction on what needs to be done (modify the device tree maybe?) and how to do it using yocto on top of the fsl-validation-image-imx image?

Thanks,

Dave

Tags (1)
4 Replies

4,636 Views
david_ochs1
Contributor III

In case anyone else has this question, here's what I did to enable it:

Enable User Mode SPI Device Driver Support with menuconfig

bitbake linux-imx -c menuconfig

The rest of the options that Carlos suggester were already enabled.

Add these lines to the iomux section of the fsl-imx8mmevk.dts (<yocto_dir>/<build_dir>/imx8_base_bsp/tmp/work/imx8mmevk-poky-linux/linux-imx/4.14.78-r0/git/arch/arm64/boot/dts/fsl-imx8mmevk.dts):

pinctrl_wdog: wdoggrp {
fsl,pins = <
  MX8MM_IOMUXC_GPIO1_IO02_WDOG1_WDOG_B 0xc6
  >;
};
pinctrl_ecspi2: ecspi2grp {
fsl,pins = <
  MX8MM_IOMUXC_ECSPI2_MISO_ECSPI2_MISO 0x00000116
  MX8MM_IOMUXC_ECSPI2_MOSI_ECSPI2_MOSI 0x00000116
  MX8MM_IOMUXC_ECSPI2_SCLK_ECSPI2_SCLK 0x00001916
  MX8MM_IOMUXC_ECSPI2_SS0_ECSPI2_SS0 0x00000116
  >;
};

...

&micfil {
  pinctrl-names = "default";
  pinctrl-0 = <&pinctrl_pdm>;
  assigned-clocks = <&clk IMX8MM_CLK_PDM_SRC>, <&clk IMX8MM_CLK_PDM_DIV>;
  assigned-clock-parents = <&clk IMX8MM_AUDIO_PLL1_OUT>;
  assigned-clock-rates = <0>, <196608000>;
  status = "okay";
};

&ecspi2 {
   fsl,spi-num-chipselects = <1>;
    cs-gpios = <0>;
   pinctrl-names = "default";
   pinctrl-0 = <&pinctrl_ecspi2>;
   status = "okay";
   spidev@0x00 {
      compatible = "spidev";
      spi-max-frequency = <10000000>;
      spi-cs-high;
      reg = <0>;
      };
};

For some reason, the chip select was the wrong polarity (active high) until I added the spi-cs-high field in the device tree. Either way, it clearly changes the polarity.

I also modified the macro for DEV_SPI1 in the NXP test code (<yocto_dir>/<build_dir>/bsp/imx8_base_bsp3/tmp/work/imx8mmevk-poky-linux/imx-test/1_7.0+AUTOINC+04ec1d8040-r0/git/test/mxc_spi_test/mxc_spi_test1.c) so that it would work with /dev/spidev1.0:

#define DEV_SPI1 "/dev/spidev1.0"

bitbake linux-imx -f -c compile

bitbake fsl-image-validation-imx

After loading the kernal and device tree, I see CONFIG_SPI_SPIDEV=y when I run zgrep SPI /proc/config.gz | grep -v SPIN | grep -v '^#', which tells me that the menuconfig change worked. Also, I see /dev/spidev1.0 on the board, so now ecspi2 is in the device tree.

4,636 Views
rutuja_patil
Contributor II

For 'MX8MM_IOMUXC_ECSPI2_SCLK_ECSPI2_SCLK 0x00001916', which register is configured ? As per my understanding Pad Control Register for the same has access upto 8th bit. But value configured is more than that.

0 Kudos

4,636 Views
leexxa777
Contributor I
For 'MX8MM_IOMUXC_ECSPI2_SCLK_ECSPI2_SCLK', correct is 0x00000016 and it is a 32 bit register.
0x00001916 works, too, because there are reserved fields. 
The screenshot from reference manual attached

pastedImage_1.png

0 Kudos

4,636 Views
CarlosCasillas
NXP Employee
NXP Employee

Hi Dave,

Have you enabled the ECSPI module on the Menu Config? Below you could find the required steps included on section 4.3.8 “Menu Configuration Options” of the i.MX Linux Reference Manual document (IMXLXRM Rev. L4.14.98-2.0.0_ga, 04/2019):

In menu configuration enable the following module:

  • CONFIG_SPI build support for the SPI core. In menuconfig, this option is available under:
    • Device Drivers > SPI Support.
  • CONFIG_BITBANG is the Library code that is automatically selected by drivers that need it. SPI_IMX selects it. In menuconfig, this option is available under:
    • Device Drivers > SPI Support > Utilities for Bitbanging SPI masters.
  • CONFIG_SPI_IMX implements the SPI master mode for ECSPI. In menuconfig, thisoption is available under:
    • Device Drivers > SPI Support > Freescale i.MX SPI controllers.

Hope this will be useful for you.
Best regards!
/Carlos
-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 Kudos