SPI

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.

    Target (U-Boot)
    setenv default_overlays
    setenv extra_overlays k3-am65xx-phytec-expansion-sample.dtbo
    saveenv
    
  • To exit U-Boot and continue booting into Linux, type boot

    Target (U-Boot)
    boot
    

Note

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.

SPI devices

The four SPI interfaces that can be made available in Linux are as follows:

SPI Devices

Interfaces

Linux Devices

MCU_SPI1

/dev/spi1

SPI1

/dev/spi3

SPI2

/dev/spi4

SPI3

/dev/spi5

Note

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:

SPI Devices

Interfaces

Linux Devices

MCU_SPI0

/dev/spi0

SPI0

/dev/spi2

  • To see what SPI devices are enabled by default run the following command:

    Target (Linux)
    ls /dev/spi*
    
  • 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.

    Expected Output
    root@am65xx-phycore-kit:~# ls /dev/spi*
    /dev/spidev3.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 pre-built 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_MISO to X_SPI1_MOS. In this example expansion connector 23D (SPI1_D0) is connected to 24D (SPI1_D1)

Warning

The expansion connector contains supply and ground rails. Be extra sure you have the correct headers connected to avoid inadvertently shorting/damaging something.

  • Power on the AM65x and boot into Linux.

  • Run the loopback application from the Linux terminal

    Target (Linux)
    /opt/ltp/testcases/bin/ddt/spidev_test -D /dev/spidev3.0
    
  • The received data (rx data) should match the transmitted data (tx data). Below is an example of the expected output:

    Expected Output
    root@am65xx-phycore-kit:~# /opt/ltp/testcases/bin/ddt/spidev_test -D /dev/spidev3.0
    [ 1081.293428] spidev spi3.0: not using DMA for McSPI (-19)
    [ 1081.298991] spidev spi3.0: not using DMA for McSPI (-19)
    [ 1081.306534] spidev spi3.0: not using DMA for McSPI (-19)
    spi mode: 0
    bits per word: 8
    max speed: 500000 Hz (500 KHz)
    number of words to be transfered: 100
    --------tx data-----------
    
    00 01 02 03 04 05
    06 07 08 09 0A 0B
    0C 0D 0E 0F 10 11
    12 13 14 15 16 17
    18 19 1A 1B 1C 1D
    1E 1F 20 21 22 23
    24 25 26 27 28 29
    2A 2B 2C 2D 2E 2F
    30 31 32 33 34 35
    36 37 38 39 3A 3B
    3C 3D 3E 3F 40 41
    42 43 44 45 46 47
    48 49 4A 4B 4C 4D
    4E 4F 50 51 52 53
    54 55 56 57 58 59
    5A 5B 5C 5D 5E 5F
    60 61 62 63
    ---------rx data----------
    
    00 01 02 03 04 05
    06 07 08 09 0A 0B
    0C 0D 0E 0F 10 11
    12 13 14 15 16 17
    18 19 1A 1B 1C 1D
    1E 1F 20 21 22 23
    24 25 26 27 28 29
    2A 2B 2C 2D 2E 2F
    30 31 32 33 34 35
    36 37 38 39 3A 3B
    3C 3D 3E 3F 40 41
    42 43 44 45 46 47
    48 49 4A 4B 4C 4D
    4E 4F 50 51 52 53
    54 55 56 57 58 59
    5A 5B 5C 5D 5E 5F
    60 61 62 63
    

Note

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.

    Target (U-Boot)
    env default -f -a
    saveenv