DART-MX8M SPI: Difference between revisions

From Variscite Wiki
(Created page with "{{PageHeader|DART-MX8M - SPI}} {{DocImage|category1=DART-MX8M}}Category:Yocto __toc__ In this example we will show how to configure SPI1 on DART-MX8M = Kernel configuratio...")
 
No edit summary
Line 1: Line 1:
{{PageHeader|DART-MX8M - SPI}} {{DocImage|category1=DART-MX8M}}[[Category:Yocto]] __toc__
{{PageHeader|DART-MX8M - SPI}} {{DocImage|category1=DART-MX8M|category2=Yocto}} __toc__
In this example we will show how to configure SPI1 on DART-MX8M
In this example we will show how to configure and test SPI1 on DART-MX8M
= Kernel configuration=
= Kernel configuration=
Verify that the User mode SPI driver (CONFIG_SPI_SPIDEV) is enabled in your kernel configuration:
Verify that the User mode SPI driver (CONFIG_SPI_SPIDEV) is enabled in your kernel configuration:
Line 6: Line 6:


=SPI 1=
=SPI 1=
== Edit arch/arm64/boot/dts/variscite/imx8m-var-dart-common.dtsi and add spidev node ==
== Add spidev node ==
Edit arch/arm64/boot/dts/variscite/imx8m-var-dart-common.dtsi and add spidev node
<pre>
<pre>
&ecspi1 {
&ecspi1 {
Line 43: Line 44:
Note: The pins here were set arbitrarily. You should set them based on your hardware design, and make sure they are not conflicting with other devices in the device tree.<br>  you can also have multiple chip selects.<br>
Note: The pins here were set arbitrarily. You should set them based on your hardware design, and make sure they are not conflicting with other devices in the device tree.<br>  you can also have multiple chip selects.<br>


= Compile =
= Recompile the kernel =
Compile the kernel and device tree and update the SOM.
Compile the kernel and device tree and update the SOM.
= Testing =
 
There's an SPI testing utility C code example in the kernel source tree: tools/spi/spidev_test.c (in older kernels: Documentation/spi/spidev_test.c)<br>
= Compile SPI test application =
There's an SPI test utility C code example in the kernel source tree: tools/spi/spidev_test.c (in older kernels: Documentation/spi/spidev_test.c)<br>
To cross compile it use the following command
To cross compile it use the following command
<pre>
<pre>
Line 53: Line 55:


= Run SPI Test =
= Run SPI Test =
Transfer  
Transfer spidev_test binary to DART-MX8M and run
# ./spidev_test -v -l -D /dev/spidev32766.0
 
The output of successful test should look like this:
<pre>
spi mode: 0x20
bits per word: 8
max speed: 500000 Hz (500 KHz)
TX | FF FF FF FF FF FF 40 00 00 00 00 95 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF F0 0D  | ......@....�..................�.
RX | FF FF FF FF FF FF 40 00 00 00 00 95 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF F0 0D  | ......@....�..................�.
</pre>
 
== SPI 1 External Connector ==
== SPI 1 External Connector ==
SPI 1 will be accessible on the following EVK pins:
SPI 1 will be accessible on the following EVK pins:

Revision as of 16:04, 11 July 2018

DART-MX8M - SPI

In this example we will show how to configure and test SPI1 on DART-MX8M

Kernel configuration

Verify that the User mode SPI driver (CONFIG_SPI_SPIDEV) is enabled in your kernel configuration:

  • In menuconfig: Device Drivers -> SPI support -> <*> User mode SPI device driver support

SPI 1

Add spidev node

Edit arch/arm64/boot/dts/variscite/imx8m-var-dart-common.dtsi and add spidev node

&ecspi1 {
	#address-cells = <1>;
	#size-cells = <0>;
	num-cs = <1>;
	pinctrl-names = "default";
	pinctrl-0 = <&pinctrl_ecspi1>;
	status = "okay";

        chip1: spidev@0 {
               compatible = "spidev";
               spi-max-frequency = <12000000>;
               reg = <0>;
        };
};

Configure SPI1 pins

&iomuxc {
	imx8mq-evk {
                ...
		pinctrl_ecspi1: ecspi1grp {
			fsl,pins = <
				MX8MQ_IOMUXC_ECSPI1_SCLK_ECSPI1_SCLK		0x11
				MX8MQ_IOMUXC_ECSPI1_MOSI_ECSPI1_MOSI		0x11
				MX8MQ_IOMUXC_ECSPI1_MISO_ECSPI1_MISO		0x11
				MX8MQ_IOMUXC_ECSPI1_SS0_ECSPI1_SS0		0x11
			>;
		};
                ...
	};
};

Note: The pins here were set arbitrarily. You should set them based on your hardware design, and make sure they are not conflicting with other devices in the device tree.
you can also have multiple chip selects.

Recompile the kernel

Compile the kernel and device tree and update the SOM.

Compile SPI test application

There's an SPI test utility C code example in the kernel source tree: tools/spi/spidev_test.c (in older kernels: Documentation/spi/spidev_test.c)
To cross compile it use the following command

$ $CC ./tools/spi/spidev_test.c -o ./spidev_test

Run SPI Test

Transfer spidev_test binary to DART-MX8M and run

# ./spidev_test -v -l -D /dev/spidev32766.0 

The output of successful test should look like this:

spi mode: 0x20
bits per word: 8
max speed: 500000 Hz (500 KHz)
TX | FF FF FF FF FF FF 40 00 00 00 00 95 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF F0 0D  | ......@....�..................�.
RX | FF FF FF FF FF FF 40 00 00 00 00 95 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF F0 0D  | ......@....�..................�.

SPI 1 External Connector

SPI 1 will be accessible on the following EVK pins:

  • J16.2 - SPI1.SCLK
  • J16.4 - SPI1.SS0
  • J16.6 - SPI1.MOSI
  • J16.8 - SPI1.MISO