Automated Deployment of MSP430 Firmware (Part 1)

I now have completed Part 2 of the article where I discuss the ansible playbook to deploy the firmware.

I have recently started looking into all the DevOps tools that have constant articles on Hacker News and reddit lately. I use linux around my apartment for all my machines (mostly debian based) and wanted a better way to control and configure them. As someone that works with python often, Ansible caught my eye. After reading about this cool demo, I wanted to try out Ansible on a Raspberry Pi cluster of my own but also add in some MSP430s getting programmed.

For those that don't know MSP430 is a ultra low-power microcontroller made by Texas Instruments. A great starting point for information is the TI LaunchPad website.

As a side project I sought out an automated way to deploy MSP430 firmware images to MSP430F5529 LaunchPads connected to Raspberry Pis. The master ansible server is responsible for compiling of the MSP430 firmware images and then using ansible pushes the image to the Raspberry Pis which then program the firmware.

Here's a simple organization chart showing how the firmware images flow.

Since the Raspberry Pi will be doing the programming of the MSP430F5529 it will need a tool for downloading firmware images. MSPDebug is a command line tool for downloading to MSP430s and the rest of the blog post will cover compiling it for use on the Raspberry Pi.

All the following compiling steps were run on a Raspberry Pi 2 running Raspbian.

Compiling HIDAPI

The first step will be compiling HIDAPI. From their GitHub page, HIDAPI is described as "A Simple library for communicating with USB and Bluetooth HID devices on Linux, Mac, and Windows." The library is used by that we will be building later on.

There are a few dependencies I found I needed to build the library, so go ahead and install those first.

sudo apt-get update  
sudo apt-get install libusb-1.0-0-dev  
sudo apt-get install libudev-dev  

Now we can download the source code for version 0.7.0 from their GitHub Releases Page. We'll download and build in a "build" directory.

mkdir ~/build  
cd ~/build  

After extracting we can now build the library.

cd hidapi-hidapi-0.7.0/linux  
make -j4 CXXFLAGS="-Wall -g -lpthread -lrt"  

If the make successfully completes you should have a hid-libusb.o file located in your current directory.

Compiling MSPDebugStack

Disclaimer: Texas Instruments does not officially support the MSPDebugStack on Raspbian or the Raspberry Pi. This is meant as a learning exercise rather than a production solution.

Next step will be compiling the MSPDebugStack from Texas Instruments. The source is avaiable from the TI website.

There are a few dependencies we are going to need to install for this as well. Go ahead and run the following:

sudo apt-get install libasio-dev  
sudo apt-get install libboost-all-dev  

Now we are ready to build

cd ~/build  

Now we need to copy the hidapi library we built previously and the hidapi header file.

cd MSPDebugStack_OS_Package/ThirdParty  
mkdir include lib  
cp -p ~/build/hidapi-hidapi-0.7.0/linux/hid-libusb.o lib  
cp -p ~/build/hidapi-hidapi-0.7.0/hidapi/hidapi.h include  

Now that we have the copied dependencies we can build libmsp430 library from the root of the package.

cd ..  
make -j4 STATIC=1  

Go ahead and grab a beer because this will probably take awhile on your Raspberry Pi. Once it's done though you will have a in your current directory, run the following to copy your library to your library path.

sudo make install  

Compiling MSPDebug

The final piece will be compiling MSPDebug itself. This is the tool that will actually program the MSP430F5529 in our automated deployment.

First let's install the dependencies:

sudo apt-get install libusb-dev  
sudo apt-get install libreadline-dev  

Now we can download the source and extract.

cd ~/build  
tar -zxvf mspdebug-0.23.tar.gz  

Now we can compile the source:

cd mspdebug-0.23  
make -j4  

Once the process is complete you will have an executable file mspdebug, go ahead and install the file to your PATH by running

sudo make install  

Testing MSPDebug

Now that everything has been compiled to run on a Raspberry Pi we can finally connect to our device using mspdebug!

Go ahead and plug in your MSP430F5529 LaunchPad and then launch mspdebug with the following commands. The first puts the that we compiled previously in your linker library path and the second launches mspdebug. The arguments for mspdebug tell it to use the TI library (the one that we built) and to allow a firmware update if the debugger firmware is out of date.

export LD_LIBRARY_PATH=/usr/local/lib:${LD_LIBRARY_PATH}  
mspdebug tilib --allow-fw-update  

If all works fine you should see something like this:
MSPDebug Launched

Indicating you are now connected to the MSP430!

Next Steps

Next we will be using Ansible to distribute MSP430F5529 firmware images to a group of Raspberry Pis which will then use the mspdebug tool to download to their connected LaunchPads.

If you had trouble following any of the steps or have suggestions/improvements for the guide please leave a comment below! If you're having trouble getting it to work and just want the binaries they are checked into my GitHub repository.

comments powered by Disqus