What is MSPGCC?
MSPGCC is a completely free and unlimited C compiler for TI's MSP430 series of microcontrollers. There are NO limitations. The MSP430 port was done by Chris Liechti and Dmitry Diky.
Documentation
Examples
You can find examples and adaptations of all the TI appnotes for mspgcc here:
Download
The windows version can be downloaded directly from here (extract to c:\msp430):
Installation on Unix/Linux/Cygwin
# become root; you actually only need this for "make install" and when # you copy files to the target directory (/usr/local/msp430) su mkdir /tmp/mspgcc cd /tmp/mspgcc #binutils wget ftp://sources.redhat.com/pub/binutils/releases/binutils-2.14.tar.bz2 tar xjvf binutils-2.14.tar.bz2 cd binutils-2.14 ./configure --prefix=/usr/local/msp430 --target=msp430 make make install cd .. export PATH=/usr/local/msp430/bin:$PATH #gcc wget ftp://gcc.gnu.org/pub/gcc/releases/gcc-3.2.3/gcc-core-3.2.3.tar.bz2 tar xjvf gcc-core-3.2.3.tar.bz2 cvs -z3 -d:pserver:anonymous@cvs.sourceforge.net:/cvsroot/mspgcc co gcc/gcc-3.3 cp -r gcc/gcc-3.3/* gcc-3.2.3/ cd gcc-3.2.3 ./configure --prefix=/usr/local/msp430 --target=msp430 make make install cd .. #msp430-libc cvs -z3 -d:pserver:anonymous@cvs.sourceforge.net:/cvsroot/mspgcc co msp430-libc cd msp430-libc/src make make install cd ../.. #gdb wget gdb-6.0.tar.bz2 tar xjvf gdb-6.0.tar.bz2 cvs -z3 -d:pserver:anonymous@cvs.sourceforge.net:/cvsroot/mspgcc co gdb/gdb-current cp -r gdb/gdb-current/* gdb-6.0/ cd gdb-6.0 ./configure --prefix=/usr/local/msp430 --target=msp430 make make install cd .. #JTAG hardware access library cvs -z3 -d:pserver:anonymous@cvs.sourceforge.net:/cvsroot/mspgcc co jtag cd jtag/hardware_access make mv libHIL.so /usr/local/lib ldconfig cd ../.. #gdbproxy wget http://twtelecom.dl.sourceforge.net/sourceforge/mspgcc/msp430-gdbproxy chmod +x msp430-gdbproxy mv msp430-gdbproxy /usr/local/msp430/bin/ #pyJTAG cvs -z3 -d:pserver:anonymous@cvs.sourceforge.net:/cvsroot/mspgcc co python cd ../python python setup.py install # You can use "python2.3", etc. instead. cd ../.. cd python # Note that this is a different "python" directory. python setup.py install # Use the exact same "python" command as before chmod 755 msp430-jtag.py # If you are using anything other than "python" (e.g. "python2.3") you will # need to edit "msp430-jtag.py" to change "python" in the top line # (e.g to "python2.3"). cp msp430-jtag.py /usr/local/msp430/bin
Simple example program
Download test1.c#include <io.h>
void wait(void); //prototype for wait()
int main(void)
{
P1DIR=0xFF; //port 1 = output
P1OUT=0x01; //set bit 0 in port 1
for(;;) { //infinite loop
P1OUT=~P1OUT; //invert port 1
wait(); //call delay function
}
}
void wait(void) //delay function
{
volatile int i; //declare i as volatile int
for(i=0;i<32000;i++); //repeat 32000 times
}
The program has to be compiled with the following commands:
Compile sourcecode for msp430x1121: msp430-gcc -Os -mmcu=msp430x1121 -o test1.elf test1.c Generate assembler listing (optional): msp430-objdump -DS test1.elf > test1.lst Generate hex file: msp430-objcopy -O ihex test1.elf test1.hexYou can now program the hex file over the JTAG interface to the controller using C-Spy (contained in the Kickstart package. After a click on "Go" the program starts running. If you have connected 2 LEDs to P1.0 and P1.1 you should see them flashing.
In-System-Debugging with GDB/Insight and the Flash Emulation Tool (FET)
It is possible to debug mspgcc programs directly in system; all you need is the most recent windows package of mspgcc and the parallel port FET.
Compiling
In order to debug a program with GDB/Insight, you have to add the switch "-g" to the mspgcc command line:
msp430-gcc -mmcu=msp430x123 -g -Os -o test.elf test.c
You will get a file called "test.elf".
Starting gdbproxy
The next step is starting gdbproxy, which is responsible for the communication between GDB and the FET:
msp430-gdbproxy --port=2000 msp430
If your FET is properly connected to the parallel port, you should see a message like the following:
info: msp430: Target device is a 'MSP430F12x' (type 11) notice: msp430-gdbproxy: waiting on TCP port 2000
Using Insight (Windows)
After you have started Insight (c:\msp430\bin\msp430-gdb.exe), click on "File->Open" and select the elf-file (e.g. "test.elf") you want to debug.
Now click on "Run->Connect to target" and enter the following settings:
Target: "Remote/TCP" Hostname: "localhost" Port: "2000" Set breakpoint at 'main': yes Set breakpoint at 'exit': yes Attach to target: yes Download Program: yes Command after attaching: "monitor erase all" Run Method: Continue from last Stop
When you click on "Ok" Insight should tell you that the connection was successful, and gdbproxy should say "notice: msp430-gdbproxy: connected".
To start the debugging click on "Run" or simply press "r". If everything worked correctly you should now see the sourcecode of your program with the first line of main() marked green. The red point is the breakpoint that has been set by Insight automatically. You can set or remove breakpoints by clicking on the '-' in front of the line.
Now you can 'c'ontinue the execution to the next breakpoint, 's'tep through the code, or step a single assembler instruction... but be careful with "finish": Insight sometimes seems to lock up with this command. So if you want to finish a function, I recommend setting a breakpoint to the end of the function and using "continue".
Using DDD (Unix/Linux)
Unfortunately Insight is a bit complicated to handle and quite unstable. If you are using Unix or Linux it is therefore better to try DDD (http://www.gnu.org/software/ddd/).
First you have to start gdbproxy to connect to the JTAG programmer (like in windows). If it works you can start DDD. The debugger and the ELF file that is to be loaded are passed as parameters:
ddd --debugger msp430-gdb test.elf
Now you should create a few buttons by adding the following lines to the text field in "Commands / Edit Buttons (Console Buttons)":
target remote localhost:2000 // Connect monitor erase all // Erase load // Load monitor reset // Reset
If you want to make the connection to gdbproxy now you only have to click on "Connect", then "Erase" to erase the flash ROM, and finally "Load" to load the program into the controller.
Found a bug? Questions? Want to help with development?
Please subscribe to the mspgcc mailing list.