MSP430 Development on OS X Yosemite with CMake (The lazy way)

April 9, 2015

The TI MSP430 is a cheap and fun microcontroller for embedded development. It comes with a development suite called Code Composer Studio. However, it does not run on Linux nor OSX. Luckily, GCC has been ported to the MSP430, dubbed mspgcc.

This is quite easy to install on Linux, whether compiling from source or installing straight from the repositories. Sadly, it is not so straightforward on OSX. You could try using homebrew or MacPorts, but neither worked for me. The next step was to try compiling from source. However, compiling from source failed in the same place as the homebrew build. What now??

Finally a Solution

On my last ditch researching I stumbled across this project. Eureka. I'm a little mad I didnt think of this before. Basically, you can use the bundled toolchain binaries that come with Energia without using Energia. While the project above works fine, I wanted to use it with CMake because I hate maintaining makefiles manually.

So I first made this MSP430 toolchain file for CMake. Warning: All of what comes next assumes you are familiar with mspgcc and cmake.

There are a few important things here that are different from the CMake cross compiling example. The compiler name can be set to "Generic". The compiler paths are simply the paths to the compilers that shipped with Energia. They must be forced because they both require additional compiler flags that we will specify later, which are not in this toolchain file. You can, of course, add the msp430 folder to your system path to make this more cross platform. I am simply demonstrating where the binaries are by default.

We are going to set the flags in the main CMakeLists.txt file. To specify the target board, it must be passed as a compiler flag using the -mmcuflag. The board we are targeting is msp430g2553. So the resulting cmake command placed in CMakeLists.txt is below:

But I also want to be able to flash the board using the same Cmake script instead of having to type out the path to the Energia mspdebug. So I made a custom command in CMakeLists.txt to flash the binary.