Skip to content

Enabling SPI on Raspberry Pi Yocto

shreyan-collab edited this page May 3, 2022 · 33 revisions

SPI module support for Raspberry-pi

Motivation:

As per the wiki page for yocto, the SPI protocol support was not available for the yocto build. As SPI is one of the important protocols used for communication between two different devices, students can build their user application code that establishes communication between two SPI devices.

Implementation:

Please refer Pull Request: here
Following configurations are verified for Raspberry-pi 3b+

  1. To enable SPI module, add ENABLE_SPI_BUS = 1 or the local.conf can also be modified
  2. To autoload the SPI module,add KERNEL_MODULE_AUTOLOAD:rpi += spidev
  3. To add spi tools support,IMAGE_INSTALL:append = spi-tools.
  4. Checking whether the spi module and autoload the spi module, use the following checks available in the above pull request or see the build.sh
  5. For verification purposes, a loop backtest is performed where MISO and MOSI pins are connected together to verify the SPI functionality. The loopback test code can be found here spi loopback test
  6. The relevant spi package with the loopback code can be found here. The recipe for the SPI test application code can be found under meta-spi layer here or in the pull request above.
  7. We need to modify the bb file to install the executable in the yocto build. The bb file modification can be found in the links shared above
  8. After creating the spi package,in the image add, CORE_IMAGE_EXTRA_INSTALL += spi-config to include the package.
  9. Now run build.sh tom include the SPI support

Verification:

After booting, the following commands can verify whether the SPI module is installed properly

  1. lsmod | grep spi
  2. To access SPI interfaces from user space, the kernel provides us entry points as special files in /dev. This requires the loading of the following module. modprobe spidev
  3. The /dev/spidev0.0 interface can be queried by the following command spi-config -d /dev/spidev0.0 -q

SPI

Running loopback test to verify the SPI functionality. The MOSI and MISO (GPIO 10 and GPIO 9 pins) in raspberry pi 3b+ is connected. The loopback test will send a string from MOSI pins and MISO will echo the same data sent by MOSI pin.

  1. In the first command, the MOSI and MISO pins were not interconnected, TX sends a string and RX response of spidevtest -v returned all zeroes
  2. In the second command, the MOSI and MISO pins are interconnected, and both the RX and TX response of spidevtest -v matches.

spiloopbacktest

References:

https://www.rpsys.net/yocto-docs/dev-manual/dev-manual-common-tasks.html
https://www.yoctoproject.org/pipermail/yocto/2015-December/027653.html
https://www.sigmdel.ca/michel/ha/rpi/spi_on_pi_en.html