Setting up a Custom MSP430 Development Environment
For an upcoming project I wanted to use my MSP430 Launchpad development board. I haven’t worked with TI’s MSP430 series for a long time, so I needed to set up my environment first.
I didn’t want to go to the trouble of installing another full-blown IDE just for playing around with a microcontroller. I wanted to write code in Vim and use the environment I am used to instead of dealing with yet another IDE.
Fortunately, there is a full GCC-Toolchain for MSP430 available, as well as a command-line flashing tool from TI. Debugging is also possible thanks to the also open-source mspdebug utility.
On my Gentoo GNU/Linux system, I used crossdev to compile cross-toolchain for MSP430, but it is also available as a binary download from TI. mspdebug was available in the package repository, but it could also be downloaded from Github.
Important to know is that before your compiled binary can be uploaded to the microcontroller, it needs to be converted. The MSP430-FLASHER tool accepts images in TI-TXT or Intel HEX format. The file can be converted with objcopy (see Makefile below for details).
With all the tools ready and working separately, the only thing there is left to do is to create a Makefile for a convenient interface.
PATH_SRC = src PATH_BUILD = build/target PATH_OBJS = build/target/objects BUILD_PATHS = $(PATH_TARGET_BUILD) $(PATH_TARGET_OBJECTS) CC = msp430-elf-gcc CFLAGS = -I /usr/msp430-gcc-support-files/include CFLAGS += -I ./driverlib/MSP430FR2xx_4xx CFLAGS += -mmcu=msp430fr4133 CFLAGS += -Og -Wall -Werror -g3 -ggdb CFLAGS += -D__MSP430FR4133__ CFLAGS += -c LD = msp430-elf-gcc LDFLAGS = -L /usr/msp430-gcc-support-files/include LDFLAGS += -L ./driverlib/MSP430FR2xx_4xx LDFLAGS += -T msp430fr4133.ld SRCS = $(wildcard $(PATH_SRC)/*.c) MKDIR = mkdir -p .PHONY: clean .PHONY: test all: target convert target: $(BUILD_PATHS) $(PATH_BUILD)/target.out OBJS = $(patsubst %.c, $(PATH_OBJS)/%.o,$(notdir $(SRCS))) BUILD_PATHS = $(PATH_BUILD) $(PATH_OBJS) $(PATH_BUILD): $(MKDIR) $(PATH_BUILD) $(PATH_OBJS): $(MKDIR) $(PATH_OBJS) $(PATH_BUILD)/target.out: $(OBJS) $(LD) -o $@ $^ $(LDFLAGS) $(PATH_OBJS)/%.o:: $(PATH_SRC)/%.c $(CC) $(CFLAGS) $< -o $@ convert: msp430-elf-objcopy -O ihex $(PATH_BUILD)/target.out $(PATH_BUILD)/target.hex upload: MSP430Flasher -e ERASE_ALL -w $(PATH_BUILD)/target.hex -v -z [VCC] debug: mspdebug tilib gdb: msp430-elf-gdb target.out dis: msp430-elf-objdump -D target.out | less clean: rm -rf $(PATH_OBJS)/*.o rm -rf $(PATH_BUILD)/*.out rm -rf $(PATH_BUILD)/*.hex rm -rfd Log
The above Makefiles assumes the source files to be in a subdirectory
called src
. It is also possible to connect GDB to the
hardware using target remote :2000
in GDB and use
mspdebug’s “gdb” mode on the other side.
As you can see, with this Makefile I get all the functionality you need for proper firmware development: Compiling, uploading, debugging, disassembly view...
Note that you also need the necessary include files. I needed to get them separately from TI.
This is how it looks in action (Editor/Upload/Debug):
Unit testing
Next I wanted to be able to properly unit test my code. For this, I plan to use the Unity Framework. This simple framework is especially well suited for embedded systems.