Phillip Dixon

Obscure things, but they interest me.

Debugging an STM32 With OpenOCD and GDB

Hooking GDB to OpenOCD

OpenOCD implements the GDB remote protocol. Typically OpenOCD serves up a port on localhost, GDB then connects to this. In this arrangement there are two process involved in the debugging and they need to managed separately. This is a pain and tends led to scripts with pskill in them 1.

It turn out that this isn’t the only way for GDB to communicate with the remote. The remote target can also be run as a child process.

target remote | openocd -p

By doing things this way we now only have one set of processes to manage (no more pskill).


The Cortex M3 has hardware watch points in it’s onboard debugging unit (see Cortex M3 Specifications). OpenOCD and GDB both support watch points. Setting watch points using the watch command in GDB doesn’t seem to work. Setting the watch points in OpenOCD using monitor commands does seem to work.

monitor rwp [address] length

Watchpoints are removed with:

monitor rwp [address]
target remote | openocd -p
set remote hardware-breakpoint-limit 6
set remote hardware-watchpoint-limit 4
monitor reset halt

  1. pskill in scripts always makes me feel a bit uncomfortable.

Tracking RAM Usage

Working on embedded projects sooner or later RAM becomes an issue. Then it’s a matter of going through the heavy RAM consumers and seeing what can be squeezed.

I knocked up the following help today while I was tracking down what was using the RAM on my current project.


arm-none-eabi-nm -S -t d --size-sort $1 | \\
awk '{if ($3 ~ /B|b|D|d/) {print $0; total += $2}} END{print "Total RAM Usage: " total}'

SMB Printers with CUPS on Debian

I just spent a very frustrating couple of hours this afternoon trying to get CUPS to event acknowledge smb printers existed. It would work perfectly on my laptop with Ubuntu 10.04, and but on my Debian Squeeze desktop. In the end I tracked it down to the following:

  1. CUPS relies on smbspool. On Debian and Ubuntu this is provided by the smbclient package.

  2. The permissions on /usr/lib/cups/backend had been change so it’s contents could only be seen be root (this post put me on to this issue). I’m not sure why this being wrong didn’t break everything. There is also a /usr/lib/cups/backend-available but for some reason there isn’t an entry in this for smb.

Installing smbclient and fixing the permissions on /usr/lib/cups/backend bought everything to life.