Multiple/Second SPI Buses on BeagleBone
How to: Get SPI to work on Beaglebone
If you want just one SPI port running, then most up to date images for beaglebone has enabled them by default.
Location to get pre-compiled images with SPI1 enabled, http://rcn-ee.net/deb/precise-armhf/v3.2.25-psp20/
Enabling SPI0
Step 1
-
In order to enable userland SPI we need to be able to rebuild the kernel, so grab the Linux source:
git clone git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git -
Install the required tools and libs by running:
sudo apt-get install gcc-4.4-arm-linux-gnueabi git ccache libncurses5-dev u-boot-tools lzma
I tend to compile the kernel using hardfloat, so arm-linux-gnueabihf compiler would be the way to go.
-
As per Robert C. Nelson’s repo, get the patches required to enable spidev
git clone git://github.com/RobertCNelson/linux-dev.git cd linux-dev -
switch to the am33x-v3.2 branch with:
git checkout origin/am33x-v3.2 -b am33x-v3.2 -
Now copy system.sh.sample to system.sh and update system.sh with the settings for your setup:
cp system.sh.sample system.sh -
For my setup I had to make the following changes to system.sh:
uncomment line 14, change from: #CC=arm-linux-gnueabi- to: CC=arm-linux-gnueabi- at line 60 update the path to your linux source, change from: #LINUX_GIT=~/linux-stable/ to: LINUX_GIT=~/linux-stable/ uncomment line 70 to set the kernel entry point, change from: #ZRELADDR=0x80008000 to: ZRELADDR=0x80008000 uncomment line 80 to set the BUILD_UIMAGE flag, change from: #BUILD_UIMAGE=1 to: BUILD_UIMAGE=1 and finally at line 89 uncomment and set the path to the SD card, change from: #MMC=/dev/sde to: MMC=/dev/sdd -
Build kernel command
./build_kernel.sh
Step 2
Note: This step will discuss how to enable SPI0 (SPI1 is enabled by default with latest kernels, or the one you download from above URL which contains precompiled images).
-
Goto “/KERNEL/arch/arm/mach-omap2” directory in kernel source which is in the clone you got from “git://github.com/RobertCNelson/linux-dev.git” in above steps.
-
Make the following modification after you get to Kernel configuration menu.
-
Note: if you make the change before you get to config menu, the git update process will overwrite it again with the files from repository.
*** /home/purinda/Software/Linux/linux-dev/KERNEL/arch/arm/mach-omap2/board-am335xevm.c 2012-08-10 00:12:53.937992451 +1000 --- board-am335xevm.c 2012-08-09 23:36:24.774040301 +1000 *************** *** 2275,2280 **** --- 2275,2289 ---- }; static struct spi_board_info bone_spidev2_info[] = { + /* [PG] I added the following struct call in order to get SPI0 working + */ + { + .modalias = "spidev", + .irq = -1, + .max_speed_hz = 12000000, + .bus_num = 1, + .chip_select = 0, + }, { .modalias = "spidev", .irq = -1, *************** *** 3189,3195 **** if(beaglebone_spi1_free == 1) { beaglebone_spi1_free = 0; pr_info("BeagleBone cape: exporting SPI pins as spidev\n"); ! setup_pin_mux(spi1_pin_mux); spi_register_board_info(bone_spidev2_info, ARRAY_SIZE(bone_spidev2_info)); } if(beaglebone_w1gpio_free == 1) { --- 3198,3207 ---- if(beaglebone_spi1_free == 1) { beaglebone_spi1_free = 0; pr_info("BeagleBone cape: exporting SPI pins as spidev\n"); ! /* [PG] I made the following pin_mux call in order to get SPI0 working ! */ ! setup_pin_mux(spi0_pin_mux); ! setup_pin_mux(spi1_pin_mux); spi_register_board_info(bone_spidev2_info, ARRAY_SIZE(bone_spidev2_info)); } if(beaglebone_w1gpio_free == 1) {
-
Step 3
- Call ./build_kernel.sh (inside linux-dev directory).
Step 4
- Call ./tools/install_image.sh
- you may need to modify system.sh file according to the changes displayed on above.
- if you have set the correct memory card device in system.sh it will load the compiled driver correctly into the boot partition. In my case the mmc dev was /dev/sdb
How to test
-
Once you boot the new Kernel you should see two devices in /dev/ directory as follows when you run the following command
ls /dev/spidev* -lah Output should be crw------- 1 root root 153, 0 Aug 9 23:58 /dev/spidev1.0 crw------- 1 root root 153, 1 Aug 9 23:58 /dev/spidev2.0 -
spidev1.0 is spi0 in beaglebone board and spidev2.0 is the spi1(the default spi master active on precompiled kernel images) in beaglebone.
-
once you can see these two devices you are ready to test.
-
connect pin 18 and 21 in header P9 with a cable, compile and run spidev_test.c in documentation/spi folder in Kernel source (refer to 1st site in references section) to test “spidev1.0”.
-
connect pin 28 and 30 in header P9 with a cable, compile and run spidev_test.c in documentation/spi folder in Kernel source (refer to 1st site in references section) to test “spidev2.0”.
-
When you do so make sure you change make sure you change the following line (in spidev_test.c) to spidev1.0 or spidev2.0, depending on what you need to test.
static const char *device = "/dev/spidev1.1";
Example SPI driver with modifications
Modified am335_omap_spi.c file from kernel source
References: