User Tools

Site Tools


Launch of


ATTENTION: temporarily on the last stable release of Linino (Linux kernel 3.3.8) the SPI test is not available due to compatibility reason. We will resolve the issue as soon as possible

SPI configuration and test

On our board we have two processors that communicate over an SPI bus. The main processor is the AR9331 (MIPS), the secondary processor is an Atmel AVR.

The SPI GPIO Controller

On the AR9331 processor we have a tiny SPI controller used to handle the communication with a memory device. We do not use this SPI controller for the communication with the other processor, instead, we emulate a SPI controller with the AR9331 GPIOs. The Linux kernel already has a GPIO bitbanging SPI controller driver (spi-gpio) and we use it to emulate our SPI controller

To enable the SPI GPIO controller you have to enable it on the OpenWRT configuration (it is already enabled in the default configuration):

make menuconfig
    Kernel Modules -> SPI Support
       enable kmod-spi-gpio module

On the AVR processor, we use its internal SPI controller (hardware).

The Communication Test

To test the communication over the SPI bus we made two programs. The first program is a software loop-back that runs on the secondary processor (AVR): the program store the incoming message in a local buffer and it sends the message back on the next run.

The second program (spi-stress-test) is a test software that runs on the Linux environment. The software use the Linux module spidev to send SPI message directly from user space. To install this module and the test program, you hat to enable it on the OpenWRT configuration:

make menuconfig
    Kernel Modules -> SPI Support
       enable kmod-spi-dev module
       enable spistresstest

Now that all components are installed the system is read for the tests. To run the test program write spi-stress-test on the prompt, the program will print a little help

root@linino:~# spi-stress-test

Usage: spi-stress-test [options] -d <device>

d (Device): the path to the spi device. It is mandatory
i (Interactive): set if you want to run the test in interactive mode
v (Verbose): set if you want verbose output
s (Silent): set if you want see only errors
S (Silent): silent only repetitions
c (Config): specify the path to a custom config file
t (Time delay): delay between test repetitions in nanoseconds
e (Error): stop on error
h (Help): print this help

How to Configure Tests

The spi-stress-test program uses a default set of tests available at /etc/confic/config

root@linino:~# cat /etc/config/config-spi-test 
3 100000 1 1000000000 20 8 8 6 4 2
2 100000 1 1000000000 20 8 11223344FF 0123456789FF 55AA55AAFF

Each line of this file represent a single kind of test. A test requires different parameters to run, these parameters are separated by the space character. Following the meaning of each field:

  1. identification of the kind of test. Possible value: 0, 1, 2, 3. Only test 2 and 3 really work
  2. number of test repetitions
  3. flags. Currently it supports only the loop-back flag. Set to 1 to test loopback
  4. clock speed. Ignored with the default installation. You have to edit the source code of the spi-gpio-ds driver
  5. delay between SPI transfer
  6. number of bits per word (8 with the AVR processor)

All the other fields are interpreted differently by each kind of test. In test 2 each field is an SPI message to send; all message must be terminated with the 0xFF byte. In test 3 each field is the length of an SPI message to send, the data is randomly generated.

The Transfer Delay

The AVR is a little 8bit processors, it can handle only 8bit word transfer. In order to acquire bigger message it is necessary to store each byte on a buffer and this procedure require computation time. But this is not the only task on the AVR, so more code will be executed on this processor and it will increase the computation time.

The delay between each byte transfer is related to the AVR load and it must be adjusted to avoid loss byte.

We measured that about 20us delay can be enought if you do not use the serial communication to control the Linux system. If you want to use the Serial Console you have to increase the delay to 50us of grater values.

wiki/spimaster.txt · Last modified: 2019/05/28 11:22 (external edit)