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.


# the name of the target operating system

# specify the cross compiler

# here is the target environment located

# adjust the default behavior of the FIND_XXX() commands:
# search headers and libraries in the target environment, search 
# programs in the host environment

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:

# Set the compiler flags
set(CPU_FLAG "-mmcu=msp430g2553")

All Set. Now we just have to set the target to output an elf binary

# Create the executable
add_executable(hello_msp.elf ${SOURCES})

Now it should compile..

cd build/
cmake .. -DCMAKE_TOOLCHAIN_FILE=../cmake/msp430.cmake

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.

# Set the mspdebug path
# OSX using Energia.. For some reason the if statement wont work cross compiling
set(MSPDEBUG_PATH /Applications/

    COMMAND ${MSPDEBUG_PATH} rf2500 'prog hello_msp.elf'
    DEPENDS hello_msp.elf

So now, the command make flash will flash the compiled binary to the board. Voila, we can develop for the MSP430 on OSX 10.10! You can see the full code for this project on GitHub. Happy hacking!

comments powered by Disqus
  • Copyright 2013, Matthew Iannucci
  • Site created with, version 0.3
  • Updated January 2015