I recently ordered a LaunchPad Development Board from Texas Instruments and needed to program it using my Fedora 16 linux machine. I've had an Arduino for a couple months now, but I'm really a beginner when it comes to programming for microprocessors. I really wanted someone to walk me through the setup process and give me the tools I needed to get started. Sadly, that sort of help was unavailable. I hope this blog post fills part of that void.
I'll assume you know the basics of what the LaunchPad is. If not, please check out TI's LaunchPad website.
When working with the LaunchPad (or similar devices like an Arduino), you write code for the device, compile that code, and load it onto the device's microcontroller. Then, with the right lights and sensors and buzzers and toys attached to the device, you run the program. If you programmed and attached everything correctly, the device does whatever you want it to do.
As of this writing, the LaunchPad comes with 2 microcontrollers that you can swap in and out as desired. Many places around the web (including parts of the TI website) talk about the LaunchPad shipping with the MSP430g2211 and MPS430g2231 microcontrollers. Mine actually came with the MSP430g2553 and MSP430g2452 microcontrollers. I don't imagine that would normally be a big deal, but my microcontrollers are newer devices than the previously provided microcontrollers, so configuring software was a bit of a challenge.
The LaunchPad serves to make the microcontroller's pins more accessible for attaching and reattaching things without damaging the chip. Most of the images I saw around the internet showed that the LaunchPad came with pins that could be soldered onto the the LaunchPad in predetermined places if desired. My LaunchPad came with the pins already soldered on. Lucky me. I don't have a soldering iron.
Up and Running
The TI website explains how to download and install some software to get up and running with the LaunchPad fairly quickly. That software is for Windows, and I needed to work with Linux. Though Linux is not officially supported, TI was nice enough to provide some links to places where people were able to make it possible.
After some reading and googling I found this blog post about working with an MSP430 microcontroller in Fedora [note (for those just skimming): The instructions in that blog post don't work]. It has a list of packages that needed to be installed, some sample code that could be compiled, and line-by-line instructions for how to load it on to the microcontroller. I followed the instructions and everything went smoothly until it was time to compile the sample code:
Device MSP430G2553 is not supported
I learned a lot while trying to solve this one little problem (because it's actually fairly complicated)
Using the Right Compiler
At this point in time, the only compiler you need to work with when programming for an MSP430 microcontroller is GCC; however, you don't just use regular old GCC. You need to use a variant call MSPGCC.
When I followed the simple instructions in the blog post I had found earlier, I installed the msp430-gcc package and was using the right compiler. But the package in the Fedora repository is (as of this writing) too out of date to be of any use. The list of microcontrollers is supported (called the toolchain) needed to be updated to accomodate the many new MSP430 microcontrollers that have been introduced. I couldn't find any way to update the toolchain manually.
I uninstalled all the msp430 packages listed on that blog post and turned to the MSPGCC Wiki. That page proved to be my most valuable resource.
The Road Home
When it comes to MSPGCC and Linux, it looks like Ubuntu has its act together. If using Fedora, however, it looks like you have to have to install MSPGCC from source and skip the package manager. Here's a link to the MSPGCC Wiki instruction on installing from source. If it's changed since I posted it (as Wiki's tend to do), I hope you can hunt around and find it still. I've outlined the steps I took (which are based on the MSPGCC Wiki). If you're lucky you can just follow my steps. If not, I hope you'll at least be able to get the idea of what you'll need to do.
Before we start, in order to perform this installation, some system packages are required. Luckily, these can be installed from the package manager. I don't have an exhaustive list of all the package dependancies that are required, but I'll highlight a few key ones here.
yum install gcc gmp gmp-devel mpfr mpfr-devel mpc libmpc-devel ncurses-devel zlib zlib-devel texinfo patch
If you run into an error while executing one of the commands below, Google the error and you probably need to install a package I forgot to list here.
Getting the Necessary Files
First create a temporary build directory.
Now you need to download MSPGCC to that temporary directory. Visit this link and download the latest version (mine is mspgcc-20120125):
Extract the contents for the downloaded file:
tar xvfj mspgcc-20120125.tar.bz2
Look around the extracted directory. You should see a collection of patch files and version files. Mine looks like this:
drwxr-xr-x. 2 user user 4096 Jan 25 13:27 docs drwxr-xr-x. 4 user user 4096 Jan 25 13:27 htdocs -rw-r--r--. 1 user user 253803 Jan 25 13:27 msp430-binutils-2.21.1a-20120125.patch -rw-r--r--. 1 user user 376678 Jan 25 13:27 msp430-gcc-4.6.1-20120125.patch -rw-r--r--. 1 user user 382048 Jan 25 13:27 msp430-gdb-7.2a-20111205.patch -rw-r--r--. 1 user user 9 Jan 25 13:27 msp430-libc.version -rw-r--r--. 1 user user 9 Jan 25 13:27 msp430mcu.version -rw-r--r--. 1 user user 3021 Jan 25 13:27 README -rw-r--r--. 1 user user 3401 Jan 25 13:27 RELEASES.TXT
MSPGCC depends on other programs and libraries to do its job. The patch files listed here with modify those programs and libraries to work with the MSPGCC variant of GCC. In order for those patches to apply properly, you'll need to download the specific versions listed in the file names. If you open the version files you'll find the version number of that package you'll need to download
Now that we have the version requirements, we'll download the programs and libraries MSPGCC depends on.
Download the correct toolchain (mcu package) to the temporary build directory:
- Open msp430mcu.version to find the version number (mine is 20111224)
- Visit the download page: http://sourceforge.net/projects/mspgcc/files/msp430mcu/
- Download the correct package version (mine is msp430mcu-20111224)
Download the correct C library (libc package) to the temporary build directory
- Open msp430-libc.version to find the version number (mine is 20120125)
- Visit the download page: http://sourceforge.net/projects/mspgcc/files/msp430-libc/
- Download the correct package version (mine is msp430-libc-20120125)
Download the correct binutils package to the temporary build directory
- Get version from patch filename (mine is 2.21.1a)
- Visit the download page: http://mirror.yongbok.net/gnu/binutils/
- Download the correct package version (mine is binutils-2.21.1a)
Download the correct gcc core package to the temporary build directory
- Get version from patch filename (mine is 4.6.1)
- Visit the download page: http://ftp.wayne.edu/pub/gnu/gcc/
- Click the folder for the right version (mine is gcc-4.6.1/)
- Download the correct package version (mine is gcc-core-4.6.1). Don't download a diff file. Download either tar.bz2 or tar.gz
Download the correct gdb package to the temporary build directory
- Get version from patch filename (mine is 7.2a)
- Visit the download page: http://mirror.anl.gov/pub/gnu/gdb/
- Download the correct package version (mine is gdb-7.2a). Download either tar.bz2 or tar.gz
Patching for MSPGCC
After all downloads are complete it's time to extract the packages.
tar xvfj binutils-2.21.1a.tar.bz2 tar xvfj gcc-core-4.6.1.tar.bz2 tar xvfj gdb-7.2a.tar.bz2 tar xvfj msp430mcu-20111224.tar.bz2 tar xvfj msp430-libc-20120125.tar.bz2
Now we need to apply those patches we downloaded. We do that by going into each exatracted package for which there is a patch then applying the patch. This is what it looked like for me:
cd binutils-2.21.1 patch -p1 < ../mspgcc-20120125/msp430-binutils-2.21.1a-20120125.patch cd .. cd gcc-4.6.1 patch -p1 < ../mspgcc-20120125/msp430-gcc-4.6.1-20120125.patch cd .. cd gdb-7.2 patch -p1 < ../mspgcc-20120125/msp430-gdb-7.2a-20111205.patch cd ..
Prep work should be done now.
Installing at Last
Now that everything is patched we can finally start installing some of these packages. Installing each package happens in 2 or 3 steps:
- Configure (sometimes)
For the packages that need to do configuration, we're going to create more temporary build subdirectories:
mkdir ~/msp430_build_tmp/binutils-2.21.1-msp430 mkdir ~/msp430_build_tmp/gcc-4.6.1-msp430 mkdir ~/msp430_build_tmp/gdb-7.2-msp430
Now let's start installing. This process is going install MSPGCC related files in the /usr/local/msp430 directory. The MSPGCC variant of GCC will be accessed via the msp430-gcc command.
We'll start with binutils:
cd binutils-2.21.1-msp430 ../binutils-2.21.1/configure --target=msp430 --program-prefix="msp430-" make . . . and if everything went well . . . sudo make install
Now we'll install MSPGCC:
cd gcc-4.6.1-msp430 ../gcc-4.6.1/configure --target=msp430 --enable-languages=c --program-prefix="msp430-" make . . . and if everything went well . . . sudo make install
Now we'll install GDB:
cd gdb-7.2-msp430 ../gdb-7.2/configure --target=msp430 --program-prefix="msp430-" make . . . and if everything went well . . . sudo make install
Now we'll install the toolchain (in all its up-to-date glory)
cd msp430mcu-20111224 sudo MSP430MCU_ROOT=`pwd` ./scripts/install.sh /usr/local/
Now we'll install the C library
cd msp430-libc-20120125/src make sudo Path=$PATH make PREFIX=/usr/local install
And the installation is complete
That was a long process, and we haven't even tested it by compiling any code. That's a blog post for another time my friends.