Userland SPI on the BeagleBone with Ubuntu
March 26, 2012
For a project I’m working on I want to get a BeagleBone talking to a nRF24L01+ module. The first step is to get userland SPI access working on the BeagleBone, and last week I spent some time getting this going. The good news is that Robert C Nelson has merged my patch into his github repo linux-dev and a prebuilt image is available to download. Read on to learn how to build from source and get details of the patch.
Standard Ubuntu running on the BeagleBone
Reading this post on the BeagleBoard Google Group, led me to Brian Hensley’s blog post SPI working on the Beagleboard XM rev C. With some minor modifications I got Ubuntu installed onto an SD card and running on my BeagleBone; first off download a stable release of Ubuntu for ARM:
And then extract and change directory:
Then run the script to install the files on the SD card (replace ‘/dev/sdd’ with the drive name for your SD card):
Once completed (approx 10 minutes), insert the SD card into your BeagleBone, and all being well, Ubuntu will be up running on your BeagleBone. Verify by running:
which should give:
and
should give:
Setup to enable rebuilding the Linux kernel
In order to enable userland SPI we need to be able to rebuild the kernel, so grab the Linux source:
Install the required tools and libs by running:
Note that I am running on Debian 6.04 in a VirtualBox VM and had to add the following sources to /etc/apt/sources.list:
As per these instructions, clone Roberts git repo with:
switch to the am33x-v3.2 branch with:
Now copy system.sh.sample to system.sh and update system.sh with the settings for your setup:
For my setup I had to make the following changes to system.sh:
uncomment line 14, change from:
to:
at line 60 update the path to your linux source, change from:
to:
uncomment line 70 to set the kernel entry point, change from:
to:
uncomment line 80 to set the BUILD_UIMAGE flag, change from:
to:
and finally at line 89 uncomment and set the path to the SD card, change from:
to:
Build the Linux kernel
We can now run the buid_kernel.sh script which will clone the Linux source from our linux-stable directory, update to the latest version in git and apply the patches for running on the BeagleBone (this includes the userland SPI support patch :-) ).
Whilst the script is running the Kernel Configuration screen will be shown, to enable SPI scroll down to the ‘Device Drivers’ option, hit enter and scroll down to ‘SPI Support’ and hit enter again, now make sure the following are selected:
Test userland SPI
Once the build had completed, takes a few hours on my setup, there will be a uImage file in ~/linux-dev/deploy, install this to your SD card with:
Install the SD card into the BeagleBone, and check that SPI is available by running :
on the bone, which should give:
We can also run a further test by cross compiling spidev_test.c in the VM:
Remove the SD card from the BeagleBone and transfer spitest to the SD card:
reinsert the SD card into the BeagleBone, connect pins 29 and 30 together on header P9, boot and run:
All being well you should see:
Next step is to connect the SPI to an nRF24L01+ module and get them talking!
Many thanks to Robert C Nelson, Branden Hall and Craig Berscheidt.
Userland SPI support patch details
FYI: the userland SPI support patch is based on the patch from Craig Berscheidt and makes the following changes to ~/linux-dev/KERNEL/arch/arm/mach-omap2/board-am335xevm.c:
Adds the bone_am335x_slave_info struct:
adds an init function:
and adds the following line to beaglebone_dev_cfg by: