Announcements‎ > ‎

Playing with GDB on the new panStamp NRG

posted Mar 14, 2014, 12:16 PM by Daniel Berenguer   [ updated Mar 20, 2014, 2:33 PM ]
The new NRG board is finally being beta-tested. This means that we should be able to launch a commercial version in less than three months. In the meantime, we have created a special forum section where to discuss about our beta tests and the ongoing developments related to panStamp NRG.

This article shows an introspective view about GDB_bootloader, the compact bootloader included in our modules. This reduced version of GDB server lets us program the boards serially from msp430-gdb by means of a standard USB-UART (3.3V) gateway connected to the target board. On the other hand, NRG boards can also be programmed and debugged via JTAG SBW as well, in the same way we program launchpads. In summary, we provide two different programming methods depending on your needs and personal preferences.

Besides the firm-loading capability, the serial bootloader also implements a set of GDB instructions so that we can navigate into the internal memory of the CC430F5137 MCU and read/write values from it. This guide shows how to exploit this feature.

First of all, we need to put the board in programming mode, according to this guide. Once your serial converted is connected to the target board and Pin 12 tied to ground, restart the board. At this moment panStamp NRG will enter in programming mode. We can then open a terminal and run msp430-gdb. If you didn't install msp430-gdb previosly in your computer you can run it from Energia/hardware/tools/msp430/bin/.

msp430-gdb -b 38400 -ex 'set debug remote 0' -ex 'target remote your_serial_port'

Once GDB starts you will see something like this:

GNU gdb (GDB) 7.2
Copyright (C) 2010 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=x86_64-unknown-linux-gnu --target=msp430".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Remote debugging using /dev/ttyUSB0
0x00008000 in ?? ()
(gdb)

OK you are now "into" the MCU so you can query the value contained at any address with "x":

(gdb) x 0x1800
0x1800:    0xffffffff

Here we queried about the contents of address 0x1800, which is the start of the Info D region, one of four "pseudo EEPROM" spaces provided by the CC430 MCU. This page shows how the memory of the CC430F5137 MCU is organized.

On the other hand, we can also list the contents of a group of addresses. Below /10h means that we want 10 values, starting from 0x1800 to be displayed in 16-bit format:

(gdb) x /10h 0x1800
0x1800:    0xffff    0xffff    0xffff    0xffff    0xffff    0xffff    0xffff    0xffff
0x1810:    0xffff    0xffff

All the above 0xffff's mean that those memory locations remain erased. since we are working with Flash and not with EEPROM, before writing a single byte we need to erase the whole section. Don't worry too much about this since the panStamp library already does this for you.

OK now let's say that we want to write 0x1234 into a specific location with address 0x1885 (Info C memory space) which has previously been erased so that the current value is 0xFFFF:

(gdb) set {short}0x1885 = 0x1234

In summary, Rick Kimball did a great job and maybe in the future his compact GDB server might support new commands. Why not dreaming about debugging code on the CC430 with GDB some day?
Comments