So this is for people that are trying to get SPI working on their Beagleboard XM rev C boards. At the time that I began this adventure I had no clue how to get SPI working on my board. So I decided to blog about it while I was learning, and now it works. The setup is for Ubuntu 11.10 and using Kernel v3.1.10 So let me share with you.

Now you must understand I’ve spend much time looking at many different posts on the google group “beagleboard”, many blog sites, elinux pages and such. People are just ripping their hair out as someone put it on how to successfully get SPI working. What I found was skattered knowledge of the topic and I wanted to bring it all together for the novice user.

There is something else you should know about me and that is i’m a novice user in the Linux world. In my search I was really searching for was a straight forward walk though from starting to finish, starting with a blank 4GB microSD card and ending on getting SPI working.

Next you’ll want to download the following stable release of Ubuntu for the Beagleboard Xm with the following command. Also, it’s about 108MB so it might take a little time to download on your virtualbox or ubuntu host, i’m using virtualbox.

Once that has downloaded you want to verify that the download was successful, we do this with whats called a checksum. This is an advance algorithm that spits out a number that can be compared to verify the download was sucessful. To do so type the following by typing:

md5sum ubuntu-11.10-r3-minimal-armel.tar.xz

You must get a result that matches this!

551e66185c5ce3c6270a8e38b8ac6457 ubuntu-11.10-r3-minimal-armel.tar.xz

Since this is a TAR file, similar to a ZIP in windows so we must extract the files and than go to that directory

Now that you’re in the right directory its time to call the script that RCN-EE (Robert Nelson) made what will partition and setup all the files on the micro SD card. Now this part its important to remember the drive name that we did above, “sdb” as this is substituted into the command below.

sudo ./setup_sdcard.sh –mmc /dev/sdb –uboot beagle_xm

Mine is taking about 10 mins to setup, this may vary.

After this is complete go into the disk utility found at System -> Administration ->Disk Utility, and make sure you unmount and Safely Remove the drive (MAKE SURE YOU DO THIS EVERY TIME).

Step Two:

Now that Ubuntu has been installed on your Beagleboard XM you can test it by inserting it into the beagleboard Xm and starting it up.

NOTE: Default username: ubuntu Password: temppwd

To check the kernel version type the following once it’s booted up.

uname -r

At the time of this writing mine is version 3.1.6-x6 (This changes to 3.1.10-x7 by the end of the procedure), now to check the version of Ubuntu type

lsb_release -a

SPI BACKGROUND

Now a little bit of SPI background knowledge is needed in order to get this working. First off Serial Peripheral interface (SPI) is made up of 4 wires normally. It is a standard that was designed by Motorola for use with their micro controllers. If you’re interested in learning more about SPI i’ve added the Wikipedia link in the bibliography below. Here is what a standard SPI setup looks like, multiple slaves is optional.

On the Beagleboard XM there are 4 SPI controllers that come with the processor, but only two of them have been brought out to be used in the hardware, these are McSPI3( I will be using) and McSPI4. I’ve written up a small table in excel to demonstrate this information (details came originally from BB XM manual).

It will be important later when we’re testing the test program that we have the right pins connected. We’ll connect pins 17 and 19 of the output pins MOSI into the MISO

Step Three:

So now we’ve made it to the point of needing to setup the SPI pins in the Kernel. Everything i’ve learned is from a combination of time, searching all over the internet and a couple discussions with Robert Nelson and reading through lots of his scripts.

Now from my reading there are two main parts that have to be changed. The first is the PIN MULTIPLEXER, the second is configuring the SPI_BOARD_INFO. Most of this is skipped and done automatically through scripts we’ll be using but its good to know whats going on. More information can be found at http://elinux.org/BeagleBoard/SPI if you’re interested.

First there are a bunch of tools you need in your Ubuntu environment. These include the ARM compiler and the Git tool, uboot tools and more, you’ll understand as we progress. So lets install these ( virtualbox Ubuntu):

Now before we continue we have to un-comment the following line by removing the “#” symbol. Save the file and we’ll continue to to the building.

gedit build_kernel.sh

Un-comment,

#patch -p1 < ${DIR}/patches/beagle/0001-spi-testing.patch

NOTE: you might have to copy the system.sh.sample file to system.sh like I had too.

cp system.sh.sample system.sh

Now you have to un-comment a line in system.sh by removing the “#” symbol. Save it and continue.We will come back to edit this file more later, so keep note where it is and read through it if you have time. As this file holds the MMC directory for when we’re using the load uImage script.

gedit system.sh

#CC=arm-linux-gnueabi-

In order to compile the kernel you have to first have all the basic Linux kernel files. To do this we must have the following files. By typing in the following, it should take a while (~500MB):

After you Exit it will ask you to save, do so. Then it will continue to install for about an hour or more depending on your system speed.Once the creation of the Kernel has been complete run the following line to apply this to the microSD card.
Two things have to be done before this can be done. First you have to edit the system.sh file again. Make the following adjustments according to your drive letter like the beginning of this article (/dev/sdb)

cd ~/
cd stable-kernel/
gedit system.sh

CHANGE the MMC and un-comment “#” in front of the ZRELADDR:

MMC=/dev/sdb

and

ZRELADDR=0x80008000

If you desire to go into board-omap3beagle.c located in KERNEL you can change some of the default settings and then apply this patch.

Note: you’ll need to recompile the kernel afterwords I believe. I didn’t have to update, this was advice from Robert.

git diff > ../patches/beagle/0001-spi-testing.patch

Now the last step is to load all the files to the microSD card, make sure you’re in the /stable-kernel/ directory still:

. ./tools/load_uImage.sh

After all the loading is done safely remove the flash card from your computer and load it into the Beagleboard Xm. Once everything is loaded up you should be able to change directories to the /dev/ and see your spidev3.0 and spidev3.1 device names there now.

Step 4

Time to test this code and and see that everything works. To do this i’m going to load my microSD card back into virtualbox and test the ports. To do this we need to reference the table for the pins above and connect pins 17 and 19 which are SPI3.0 MOSI and MISO. They look like the following on the back of the board (MARKED IN RED DOTS).

Once back in virtualbox using the terminal go to the following directory and compile the SPItest example.

Once this is created, move the “spitest” to the main directory of your microSD card where Ubuntu is running, normally found in the /home/ubuntu area.

Now un-mount and safely remove the flash card, hint, like you always should be doing. Insert back into the Beagleboard Xm and bootup. Once you’ve logged in run the following command to check if SPI is now working.

As you can see I’m decoding the channels from the BBXm and i’m getting the correct SPITEST signal. This has been the final verification that i’m seeing both the Clock, MOSI and SS pins working. Sweet!!

If you liked my demonstration please leave feedback and pass this along.

Hi Brian, many thanks – thanks to your instruction Ubuntu is running stable on my BB finally. Could you maybe add hints what you have to do for getting access to gpios, somehow I don't get the instructionhttp://elinux.org/BeagleBoardPinMuxDo I have to change sth. at the Kernel configuration as well?Cheers Johannes

Btw, I'm still not able to have spi working correctly…did you do any progress?

One thing I noticed is the mismatch between sample leading/trailing edge during the test.

If you look at dmesg during the boot, you can see that every spi-related message references to "sample trailing edge" mode, while the dmesg spi messages after the try with spitest talk about "sample leading edge". I don't know of this relevant, what do you think about this?

I finally setup the spidev correctly. Look at the following post where I explain how easy is to setup spidev in an Arch-linux distribution, No need of compiling kernels or u-boot, only passing a paramter.

I wrote this back in Feb of this year. I'm not sure it is fully still working or all the links. My hope is that it helps people at least get started with their projects. I ran into many issues in the beginning and wanted to document it as best as possible. I'm very glad it's helping you. Thanks for your feedback!

I had contact with Mr Nelson R. I did what he wrote me and now i see the SPIDEV files in the /dev library. I wasn't able to test it but for now it looks good.

If you have any more questions i'll try to answer the as best as possible.

This is what he wrote me:

Hi Bart,

Basically the functionality you seek is already enabled by default inthe shipping "demo" images i have posted on elinux.. Just make sureyou edit the "uEnv.txt" boot script: change buddy=${buddy} tobuddy=spidev… From the "stable-kernel" repo standpoint, use eitherthe v3.2.x or v3.6.x branches..

in the meantime I also got it working using Ubuntu 12.10 where you also only need to enable the spi devices via uEnv.txt:buddy=spidev… that's all.This should be mentioned at the beginning of this blog article. There is a lot of old documentation out there and people like you and me wasted a lot of time needlessly…

I did write this post quite some time ago and i'm sure things have changed. I'll look into testing 12.10 and editing the uEnv.txt file and i'll update the beginning of this post to save others time. Thanks for the feedback and for helping each other out.

Hi – I am trying to interface beagle board with another slave SPI chip. Using the SPI 3_0 channel. I can see MOSI activity and CLOCK. However, MISO is always returning 0 when in SPI MODE 0. If I use MODE 1 MISO has some weird bit shifting (wrapping) of what was sent out on MOSI.