-
Notifications
You must be signed in to change notification settings - Fork 19
Enabling SPI on Raspberry Pi Yocto
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.
Please refer Pull Request: here
Following configurations are verified for Raspberry-pi 3b+
- To enable SPI module, add
ENABLE_SPI_BUS = 1
or the local.conf can also be modified - To autoload the SPI module,add
KERNEL_MODULE_AUTOLOAD:rpi += spidev
- To add spi tools support,
IMAGE_INSTALL:append = spi-tools
. - 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
- 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
- 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.
- 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
- After creating the spi package,in the image add,
CORE_IMAGE_EXTRA_INSTALL += spi-config
to include the package. - Now run build.sh tom include the SPI support
After booting, the following commands can verify whether the SPI module is installed properly
-
lsmod | grep spi
- 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
- The /dev/spidev0.0 interface can be queried by the following command
spi-config -d /dev/spidev0.0 -q
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.
- 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
- In the second command, the MOSI and MISO pins are interconnected, and both the RX and TX response of spidevtest -v matches.
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