Setup Build and Debug environment for MSP430 MCUs using mspgcc and mspdebug in Ubuntu Linux
MSPGCC is a GCC toolchain for the Texas Instruments MSP430 family of ultra low power MCUs, This includes the GNU C compiler (GCC), the assembler and linker (binutils), the debugger (GDB), and some other tools needed to make a complete development environment for the MSP430.
MSPDebug is a free debugger for use with MSP430 MCUs. It supports FET430UIF, eZ430, RF2500 and Olimex MSP-JTAG-TINY programmers. It can be used as a proxy for gdb or as an independent debugger with support for programming, disassembly and reverse engineering.
Important Update on 18 Mar 2014: The following write-up is outdated. When this original post was written the binary packages were not available for Ubuntu. Now it is available. So the commands are straight forward apt-get. In case your distro is outdated, you may not have these packages in repositories. If available, go ahead with following command.
sudo apt-get install msp430mcu msp430-libc mspdebug gcc-msp430 gdb-msp430
Otherwise follow the rest of the installation steps. Don’t forget to refer the test program, build and debug session examples too.
MSPGCC Tool chain (compiler environment) installation
The following command will get mspgcc installed in Ubuntu 10.10 host machine. The first command installs dependencies, second command check out the source code of mspgcc from svn repository and third one builds the source and install it in default /opt/msp430-gcc-4.4.3 directory.
sudo apt-get install subversion gcc-4.4 texinfo patch libncurses5-dev zlibc zlib1g-dev libx11-dev libusb-dev libreadline6-dev
svn checkout https://mspgcc4.svn.sourceforge.net/svnroot/mspgcc4
MSPDebug debugger installation
Here is my console session to explain how I extracted, compiled and installed in Ubuntu Linux 10.10.
$ tar zxvf mspdebug-0.11.tar.g
$ cd mspdebug-0.11
$ make clean
$ make WITHOUT_READLINE=1$ sudo make install
Compiling a application with msp430-gcc
Let us take a sample application source file called led.c. The purpose of this application is to toggle P1.0 port (it is connected to a LED in MSP430-F2013 dev kit).
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
P1DIR |= 0x01; // Set P1.0 to output direction
volatile unsigned long i;
P1OUT ^= 0x01; // Toggle P1.0 using exclusive-OR
i = 99999; // Delay
while (i != 0);
Compile this file with msp430-gcc compiler installed by mspgcc package.
$ msp430-gcc -g -o led.elf led.c
In the above command, -g is for debug symbols. For production release version, this option is not needed. This command will create output file called led.elf .
/usr/lib/gcc/msp430/4.6.3/../../../../msp430/bin/ld: cannot open linker script file memory.x: No such file or directorycollect2: ld returned 1 exit status
To fix this, you need to include the right header in source code (in my case msp430f2013.h) and pass the right micro controller as argument while building as shown below.
$ msp430-gcc -mmcu=msp430f2013 -g -o led.elf led.c
Connecting to target (MSP430 development kit)
Debugging with msp430-gdb using mspdebug as gdb proxy
$ mspdebug rf2500 “gdb”
$ mspdebug -d /dev/ttyUSB0 uif “gdb”
$ mspdebug -d /dev/ttyUSB0 uif “gdb”Trying to open UIF on /dev/ttyUSB0…Initializing FET…FET protocol version is 10002000Configured for Spy-Bi-WireSending initial reset…Set Vcc: 3000 mVDevice: MSP430F20x3Code memory starts at 0xf800Number of breakpoints: 2Bound to port 2000. Now waiting for connection…
$ msp430-gdbGNU gdb (GDB) 7.0.1Copyright (C) 2009 Free Software Foundation, Inc.License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>This is free software: you are free to change and redistribute it.There is NO WARRANTY, to the extent permitted by law. Type “show copying”and “show warranty” for details.This GDB was configured as “–host=i686-pc-linux-gnu –target=msp430”.For bug reporting instructions, please see:<http://www.gnu.org/software/gdb/bugs/>.(gdb) target remote localhost:2000Remote debugging using localhost:20000x0000fc00 in ?? ()(gdb) file led.elfA program is being debugged already.Are you sure you want to change the file? (y or n) yReading symbols from /home/blackgod/test1/led.elf…done.(gdb) load led.elfLoading section .text, size 0x82 lma 0xfc00Loading section .vectors, size 0x20 lma 0xffe0Start address 0xfc00, load size 162Transfer rate: 810 bytes/sec, 81 bytes/write.(gdb) continueContinuing.^CProgram received signal SIGTRAP, Trace/breakpoint trap.0x0000fc64 in main () at led.c:3535 do (i–);(gdb) break main.c:32Breakpoint 2 at 0xfc4a: file led.c, line 32.(gdb) continueContinuing.Breakpoint 2, main () at led.c:3232 P1OUT ^= 0x01; // Toggle P1.0 using exclusive-OR(gdb) continueContinuing.Breakpoint 2, main () at led.c:3232 P1OUT ^= 0x01; // Toggle P1.0 using exclusive-OR(gdb) continueContinuing.