DART-MX8M SPI: Difference between revisions
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
{{PageHeader|DART-MX8M - SPI}} {{DocImage|category1=DART-MX8M|category2=Yocto}} __toc__ | {{PageHeader|DART-MX8M - SPI}} {{DocImage|category1=DART-MX8M|category2=Yocto}} __toc__ | ||
In this example we will show how to configure and test SPI1 on DART-MX8M | In this example we will show how to configure and test SPI1 on DART-MX8M. The SPI pins on external connector J16 | ||
are used for SPI loopback test. | |||
= 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: | ||
* In menuconfig: Device Drivers -> SPI support -> <*> User mode SPI device driver support<br> | * In menuconfig: Device Drivers -> SPI support -> <*> User mode SPI device driver support<br> | ||
=SPI | = Device Tree configuration = | ||
The default DART-MX8M SPI configuration is for resistive touch controller on CS0. | |||
For the purpose of loopback test the configuration should be modified to use different CS line. | |||
== Add spidev node == | == Add spidev node == | ||
Edit arch/arm64/boot/dts/variscite/imx8m-var-dart-common.dtsi and add spidev node | Edit arch/arm64/boot/dts/variscite/imx8m-var-dart-common.dtsi and add cs-gpios property and spidev node.<br> | ||
GPIO1_12 will be used in this example to control SPI CS0. | |||
<pre> | <pre> | ||
&ecspi1 { | &ecspi1 { | ||
Line 13: | Line 21: | ||
#size-cells = <0>; | #size-cells = <0>; | ||
num-cs = <1>; | num-cs = <1>; | ||
pinctrl-names = "default"; | |||
pinctrl-0 = <&pinctrl_ecspi1>; | pinctrl-0 = <&pinctrl_ecspi1>; | ||
status = "okay"; | status = "okay"; | ||
cs-gpios = <&gpio1 12 0>; | |||
chip1: spidev@0 { | chip1: spidev@0 { | ||
Line 35: | Line 44: | ||
MX8MQ_IOMUXC_ECSPI1_MOSI_ECSPI1_MOSI 0x11 | MX8MQ_IOMUXC_ECSPI1_MOSI_ECSPI1_MOSI 0x11 | ||
MX8MQ_IOMUXC_ECSPI1_MISO_ECSPI1_MISO 0x11 | MX8MQ_IOMUXC_ECSPI1_MISO_ECSPI1_MISO 0x11 | ||
MX8MQ_IOMUXC_ECSPI1_SS0_GPIO5_IO9 0x11 | |||
MX8MQ_IOMUXC_GPIO1_IO12_GPIO1_IO12 0x11 | |||
>; | >; | ||
}; | }; | ||
Line 42: | Line 52: | ||
}; | }; | ||
</pre> | </pre> | ||
= Recompile the kernel = | = Recompile the kernel = | ||
Compile the kernel and device tree and update the SOM. | Compile the kernel (only if kernel configuration was changed) and device tree and update the SOM. | ||
= Compile SPI test application = | = Compile SPI test application = | ||
There's an SPI test utility | There's an SPI test utility 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> | ||
$ $CC ./tools/spi/spidev_test.c -o ./spidev_test | $ $CC ./tools/spi/spidev_test.c -o ./spidev_test | ||
</pre> | </pre> | ||
== 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 | |||
= Run SPI Test = | = Run SPI Test = | ||
Transfer spidev_test binary to DART-MX8M and | Transfer spidev_test binary to DART-MX8M.<br> | ||
# ./spidev_test -v | Loop SPI1.MOSI and SPI1.MISO by putting a jumper on J16.6 and J16.8<br> | ||
Configure GPIO5_9 (the default CS0 pin) as output with value 1 to prevent it from interfering with new CS0 pin | |||
# echo 137 > /sys/class/gpio/export | |||
# echo out > /sys/class/gpio/gpio137/direction | |||
# echo 1 > /sys/class/gpio/gpio137/value | |||
Run SPI test tool | |||
# ./spidev_test -v -D /dev/spidev32766.0 | |||
The output of successful test should look like this: | The output of successful test should look like this: | ||
Line 67: | Line 91: | ||
</pre> | </pre> | ||
= | = Using GPIOs to control SPI CS lines = | ||
SPI | The i.MX8M SPI controllers support up to 4 chip select lines. You can use GPIOs to control multiple CS lines.<br> | ||
In the example below GPIO1_12 and GPIO1_15 are used to control CS0 and CS1.<br> | |||
When selecting CS GPIO pins make sure they are not already used to control other peripherals. | |||
<pre> | |||
&ecspi1 { | |||
#address-cells = <1>; | |||
#size-cells = <0>; | |||
num-cs = <2>; | |||
pinctrl-names = "default"; | |||
pinctrl-0 = <&pinctrl_ecspi1>; | |||
status = "okay"; | |||
cs-gpios = <&gpio1 12 0>, | |||
<&gpio1 15 0>; | |||
}; | |||
&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_GPIO1_IO12_GPIO1_IO12 0x11 | |||
MX8MQ_IOMUXC_GPIO1_I015_GPIO1_IO15 0x11 | |||
>; | |||
}; | |||
... | |||
}; | |||
}; | |||
</pre> |
Revision as of 16:22, 12 July 2018
In this example we will show how to configure and test SPI1 on DART-MX8M. The SPI pins on external connector J16 are used for SPI loopback test.
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
Device Tree configuration
The default DART-MX8M SPI configuration is for resistive touch controller on CS0. For the purpose of loopback test the configuration should be modified to use different CS line.
Add spidev node
Edit arch/arm64/boot/dts/variscite/imx8m-var-dart-common.dtsi and add cs-gpios property and spidev node.
GPIO1_12 will be used in this example to control SPI CS0.
&ecspi1 { #address-cells = <1>; #size-cells = <0>; num-cs = <1>; pinctrl-names = "default"; pinctrl-0 = <&pinctrl_ecspi1>; status = "okay"; cs-gpios = <&gpio1 12 0>; 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_GPIO5_IO9 0x11 MX8MQ_IOMUXC_GPIO1_IO12_GPIO1_IO12 0x11 >; }; ... }; };
Recompile the kernel
Compile the kernel (only if kernel configuration was changed) and device tree and update the SOM.
Compile SPI test application
There's an SPI test utility 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
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
Run SPI Test
Transfer spidev_test binary to DART-MX8M.
Loop SPI1.MOSI and SPI1.MISO by putting a jumper on J16.6 and J16.8
Configure GPIO5_9 (the default CS0 pin) as output with value 1 to prevent it from interfering with new CS0 pin
# echo 137 > /sys/class/gpio/export # echo out > /sys/class/gpio/gpio137/direction # echo 1 > /sys/class/gpio/gpio137/value
Run SPI test tool
# ./spidev_test -v -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 | ......@....�..................�.
Using GPIOs to control SPI CS lines
The i.MX8M SPI controllers support up to 4 chip select lines. You can use GPIOs to control multiple CS lines.
In the example below GPIO1_12 and GPIO1_15 are used to control CS0 and CS1.
When selecting CS GPIO pins make sure they are not already used to control other peripherals.
&ecspi1 { #address-cells = <1>; #size-cells = <0>; num-cs = <2>; pinctrl-names = "default"; pinctrl-0 = <&pinctrl_ecspi1>; status = "okay"; cs-gpios = <&gpio1 12 0>, <&gpio1 15 0>; }; &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_GPIO1_IO12_GPIO1_IO12 0x11 MX8MQ_IOMUXC_GPIO1_I015_GPIO1_IO15 0x11 >; }; ... }; };