1. Purpose[edit source]
This article describes how to use SPI. The SPI overview is described in SPI overview article.
2. SPI Loop between MOSI and MISO[edit source]
2.1. Board connections[edit source]
A wire has to be added to connect MISO and MOSI pins (D12 et D11 pins on STM32MP157X-DKX ARDUINO connector)
2.2. DT configuration (board level)[edit source]
Board DT configuration has to be updated to:
- configure cs-gpios and activate spi4 node
- add spidev configuration to spi4 node
&spi4 { pinctrl-names = "default", "sleep"; pinctrl-0 = <&spi4_pins_a>; pinctrl-1 = <&spi4_sleep_pins_a>; status = "okay"; cs-gpios = <&gpioe 11 0>; spidev@0{ compatible = "spidev"; reg = <0>; spi-max-frequency = <4000000>; #address-cells = <1>; #size-cells = <0>; }; };
2.3. Simple data transfer[edit source]
echo -ne "\xAA\xBB" > /dev/spidev0.0 more /dev/spidev0.0
2.4. Data transfer with spidev_test[edit source]
2.4.1. spidev_test compilation[edit source]
The Linux® kernel provides the spidev_test tool that provides a test tool for spidev.
The Linux® kernel spidev_test tool source code can be found under tools/spi[1].
This tool is not compiled by default when compiling the Linux kernel for the target board. It can be compiled independently: [How to build Linux kernel user space tools] and then installed on the target.
2.4.2. List the spidev options[edit source]
spidev_test doesn't include an help option. Nevertheless if an invalid option is used, a default option case will display the list of supported options
spidev_test -h Usage: spidev_test [-DsbdlHOLC3vpNR24SItx] -D --device device to use (default /dev/spidev1.1) -s --speed max speed (Hz) -d --delay delay (usec) -b --bpw bits per word -i --input input data from a file (e.g. "test.bin") -o --output output data to a file (e.g. "results.bin") -l --loop loopback -H --cpha clock phase -O --cpol clock polarity -L --lsb least significant bit first -C --cs-high chip select active high -3 --3wire SI/SO signals shared -v --verbose Verbose (show tx buffer) -p Send data (e.g. "1234\xde\xad") -N --no-cs no chip select -R --ready slave pulls low to pause -2 --dual dual transfer -4 --quad quad transfer -S --size transfer size -I --iter iterations -t --txonly simplex tx transfer -r --rxonly simplex rx transfer
2.4.3. 32 data in full-duplex transfer with spidev_test[edit source]
spidev_test -D /dev/spidev0.0 -v spi mode: 0x0 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 | ......@.... .................. .