The TI AM65x processor can support up to six SPI interfaces. In the phyCORE-AM65x SOM design, up to four of these SPI interfaces are made available to the Carrier Board with one enabled by default. This guide provides information on how to view, access, and interact with a SPI interface on the Linux development kit.
Set up Software Configuration
In order to be accessible in Linux, the SPI interfaces need to be configured in the Linux device tree. PHYTEC has provided a sample device tree overlay in the boot directory of the root file system which configures expansion connector interfaces used in this Peripheral Guide. To enable this device tree overlay:
- The device tree overlay is set in U-Boot.
- To enter U-Boot, hit any key within 3 seconds of powering on or resetting the board, to halt autoboot.
Clear the "default_overlays" variable and modify the "extra_overlays" variable to point to the sample dtbo: "k3-am65xx-phytec-expansion-sample.dtbo". The "default_overlays" variable needs to be cleared because it is set to k3-am65xx-phytec-lcd-018.dtbo which conflicts with the sample.
To exit U-Boot and continue booting into Linux, type boot
The Expansion Sample overlay k3-am65xx-phytec-expansion-sample.dtbo conflicts with the LCD-018 overlay due to the PWM being used for backlight in the LCD-018. Make sure to disconnect the display when using this overlay before powering on the development kit.
The four SPI interfaces that can be made available in Linux are as follows:
You may have noticed that /dev/spi0 and /dev/spi2 are missing in the above table. These correspond to two of the six AM65x SPI ports that are not brought out to the Carrier Board in the phyCORE-AM65x SOM design. If the interfaces were available, they would appear as the following devices:
- To see what SPI devices are enabled by default run the following command:
- You should see at least one device (named /dev/spidev3.0 in the device tree overlay) which has been enabled in the Linux BSP for general use. This corresponds to the SPI1 interface on chip select 0.
SPI1 Loopback test
A simple loopback test can be used to verify transmit and receive on the SPI1 interface. The Linux file system contains a prebuilt test application called spidev_test that can be used to transmit data on the Master Out/Slave In line (MOSI/X_SPI1_D0) and read it back on the Master In/Slave Out line (MISO/X_SPI1_D1).
- With the AM65x Development Kit powered off and with the power supply removed, use a wire to connect X_SPI1_MOSI to X_SPI1_MISO. In this example MikroBUS X8-A5 (SPI1_D1) is connected to X8-A6 (SPI1_D0)
If you have an ALPHA kit, there is a silkscreen error on the Carrier Board at X8 which identifies it as X24.
The mikroBUS Socket contains supply and ground rails. Be extra sure you have the correct headers A5 and A6 connected to avoid inadvertently shorting/damaging something.
- Power on the AM65x and boot into Linux.
Run the loopback application from the Linux terminal
The received data (rx data) should match the transmitted data (tx data). Below is an example of the expected output:
If SPI communication is not functioning properly, only "FF"s will be printed in the "rx data".
This can be demonstrated by running the previous command again with the wire removed.
Revert to the Default Software Configuration
This guide requires disabling the LCD-018 and enabling a sample expansion overlay. In order to revert back to the default overlay settings, the following needs to be run in U-Boot:
- To enter U-Boot:
Hit any key within 3 seconds of powering on or resetting the board, to halt autoboot.