A series of stale wikis and forum posts complicate the setup for cross-compiling code on OSX Yosemite 10.10.4 and running it on a MSP430G2231 microcontroller. It’s not hard if you know what to do.
Today, the fastest way to get code running on an MSP430 is Energia, an Arduino-like environment with a specialty language and purpose-built IDE. It’s actively maintained and seems to just work which is more than can be said for anything else in this ecosystem.
If you want to write vanilla C with no magic you need to set up the toolchain and debugger yourself.
1. Install mspdebug with homebrew.
`brew install mspdebug`
If you launch mspdebug you won’t find any devices because you’re missing the usb driver.
2. Install the MSP430LPCDC-1.0.3b-Signed driver from the Energia site.
A restart is required. Afterward, try `sudo mspdebug rf2500` and you should be able to get a shell and see output like this:
Trying to open interface 1 on 006 Initializing FET... FET protocol version is 30066536 Set Vcc: 3000 mV Configured for Spy-Bi-Wire Device ID: 0xf201 Code start address: 0xf800 Code size : 2048 byte = 2 kb RAM start address: 0x200 RAM end address: 0x27f RAM size : 128 byte = 0 kb Device: F20x2_G2x2x_G2x3x Number of breakpoints: 2 fet: FET returned NAK warning: device does not support power profiling Chip ID data: f2 01 02
3. Install the pre-built open source gcc compiler from TI.
Download the msp430-gcc-opensource compiler for OSX.
You’ll have to create an account and swear you’re not Libyan, among other things. Install the compiler using the wizard and remember the destination path.
4. Create a project folder with some source code. There are some examples in <GCC_INSTALL_DIR>/examples/osx.
I tweaked one of the examples to work specifically for the MSP430G2231. Put them in the same folder.
5. Build the project with `make`. This should run some commands like this:
~/ti/gcc/bin/msp430-elf-gcc -I ~/ti/gcc/include -mmcu=msp430g2231 -O2 -g -c -o blink.o blink.c
~/ti/gcc/bin/msp430-elf-gcc -I ~/ti/gcc/include -mmcu=msp430g2231 -O2 -g -L ~/ti/gcc/include blink.o -o msp430g2231.out
6. Copy the compiled program to the board.
`sudo mspdebug rf2500`
7. Run the program with `run`. The red and green LEDs should alternate blinking.
Bonus fact: since the MSP430 has memory-mapped I/O, you can turn on the LEDs from the debugger with the `mw` command. Consult the appropriate header file in `<GCC_INSTALL_DIR>/include` to find the address of P1. For me, it’s 0x0021.