1024 byte serial msp430 gdb boot loader

I’ve been thinking about making a small msp430fr5739 based breakout board. I was hoping to use the msp430 launchpad to program them. However, I hit a major snag in that the LP version 1.4 doesn’t seem to recognize the msp430fr5739 as a valid device. I could use an FRAM board, at about ~$35, to program them but not the $10 launchpad. As I was pondering all this, there was  a lot of hubbub about the new msp430g2955 chips. Then it struck me, why should Texas Instruments devices be the only ones that can program my chips? I can do this myself.

I first looked at the boot strap loader BSL protocol built into some of the msp430 chips.  I quickly got discouraged trying to find a client that works on windows, linux, and OSX.  I really wanted to avoid writing and supporting any host side programs.  BSL also had other issues.  It isn’t supported on all the chips.  Often the BSL serial pins are different than the normal UART pins.  It takes 4 pins to use BSL so using low cost usb serial dongles would be a problem.  My final conclusion was that using BSL would just end up being a hassle.

These issues lead me to thinking about using gdb and its Remote Serial Protocol (RSP).  GDB is a mature program and binary versions are readily available for all host platforms.  If you use msp430-gdb and mspdebug, you already use RSP.  With mspdebug, it just happens to run over a local TCP/IP socket. However, an often unnoticed feature of the RSP protocol is that it can also be used with a regular serial port.

I have some experience with gdb remote serial protocol from working with the Stellaris Launchpad.  The ICDI interface on that board provides a gdb stub server that uses usb endpoints as the ‘S’erial part of RSP.  Unfortunately, gdb remote can’t use it directly as it doesn’t know anything about low level usb endpoints.

I decided to to take a simpler approach.  I wanted something that is small and can stay resident on the msp430 chip.  I decided it should use standard asynchronous serial so it could interface directly to gdb.  I wanted to use as few pins as possible so it could be used with really dumb usb to uart modules.  The logical choice was to implement a native gdb stub server that installs in high memory of the msp430 chip.  Think of this app as a bootloader that happens to use the gdb’s RSP.

Once the stub is installed on the msp430 chip, new programs are loaded on the chip without the need for a launchpad or an expensive FET430-UIF programmer .  All that is needed is a USB to serial port dongle.  You can find these on ebay for about $2 to $10.  They all go faster than the 9600 baud the virtual serial port the msp430 launchpad provides.  It is likely you probably have one of these already.  The one downside is that this scheme doesn’t allow you to debug using msp430-gdb.  However, it does provide a way to load new code without having to deal with BSL or having to write any host side code.  This scheme is used by the Arduino project quite successfully, in spite of its limitations.

How To
First step is to load the gdb_bootloader on your chip one time.  Once you have done this, you could remove the msp430 chip from your launchpad and throw it on a breadboard.  All it needs is power, decoupling caps and a pull up resistor.  Connect the TX and RX pins of the chip to the serial to USB converter (ftdi, cp2102, pl2303hx, etc..).  For simplicity, we can just test with the launchpad itself and ignore the fact that there is an on-board FET and just use it as a serial device, /dev/ttyACM0 on linux or COM1: on windows.

At reset time, the code looks at the state of the P1.3 button on the msp430g2553.  If you are holding it down, the code starts a gdb bootload/server running on the msp430g2553.  On your linux box, just start up msp430-gdb to connect to the chip over a serial port.  You can’t debug, but what you can do is erase your flash and load a new program.  The gdb server code sits at memory 0xfa00 -> 0xfdff so you do lose some of your flash.

Loadable hex file:
The gdb_bootloader.hex file from the source tree must be loaded on an msp430g2553.  To load the gdb_stub firmware ( do this one time )

OK.  Once you have that installed, you no longer need to use your launchpad.  To load programs on your chip now, just connect a USB to serial dongle up to the msp430g2553 directly and connect to that via msp430-gdb.  Here are the steps to load a blink program using msp430-gdb via the serial port:

Good, now there are two things on your msp430g2553 chip.  At memory address 0xfa00 there is the bootloader, it is run first before your blink.elf code.  At reset, it checks the button to see if you are holding it down.  If not, then it runs the blink.elf code.  If you are holding it down, it runs the gdb server instead and allows you to reload code.  So just press reset to start the blink.  Press and hold the P1.3 switch down and press reset to start the gdb stub server.

Source Code

The code is written in C++ using the fabooh framework.  I’ve been trying to find a good app to use as the fabooh debut project.  I think this will be it. This type of code needs to be small but needs the flexibility to use various UART implementations.  This code personifies what fabooh does well.


In future posts, I’ll use this application to describe the features of the different FabOoh template classes.

Note: The version of the code only works with the msp430g2553.

Pretty simple huh? I think so.

How to Write a GDB Server
GDB Protocol
BSL_(MSP430) Wiki


Comments are closed.