To download and debug using the st-link interface provided on the STM32 Discovery board requires either a PC (or Virtual PC) running a separate gdb server. While the server runs on the PC, download and debugging can be controlled from a separate Unix host. For my experiments, I ran the gdb server under windows XP executing within VMWare Fusion and accessed this server from OS X.

Atollic provides a free STM32 toolchain that includes a gdb server. Unfortunately, I found that this server required an earlier version of GDB (7.0) that I had to compile separately. (See CSTools)

The Atollic gdb server does not work as installed (as discussed here).

  • The server is located in "Program Files/Atollic/TrueSTUDIO STM32 Lite 1.4.0/Servers/ST-Link_gdbserver"
  • ST-Link_gdbserver.bat will start the server using the config.txt file. However, this file is missing one important option: -d

Add the following lines to the end of this file:

##############################################################
# -d enable STD mode
# ############################################################
-d
  • From a DOS box, launch gdbserver (assuming you have the server in your path):

ST-Link_gdbserver.bat

  • Given an "elf" file, demo.elf, to be debugged on your Unix platform type
arm-none-eabi-gdb demo.elf
  • given the ip address (e.g. 1.2.3.4) of the PC running gdbserver type the following gdb commands:
(gdb) target remote 1.2.3.4:61234
(gdb) load
(gdb) break main
(gdb) run
  • debug as normal !

Notes:

  1. 61234 is the port number the atollic gdb server "listens to" by default. This can be changed by editing config.txt in the gdb server directory.
  2. gdb can be used simply to flash elf files by skipping the steps following load above. This can be automated with a gdb command file.

Update

For linux users there is now a much better alternative -- a gdb server that interacts directly with the stlink firmware on the stm32vl discovery board.

  • Download the source code from https://github.com/whitequark/stlink. You'll need "git" as well as sg-utils.
    • sudo apt-get install git
    • git clone git://github.com/whitequark/stlink.git
    • sudo apt-get install libsg2utils-dev
    • cd stlink/Build
    • make
    • copy st-util to an appropriate directory (e.g. /usr/local/bin)
    • install the udev rules (see the README file with the stlink sources)

NOTE: I tried running st-util on RHEL5 without success. Perhaps the kernel 2.6.18 doesn't handle the broken scsi implementation of stlink as well as 2.6.32 (in Ubuntu 10.04).

I recommend that you install the optional udev rules as solves various permission issues as well as keeps the linux kernel from trying to understand the severely broken scsi implementation used in the stlink firmware.

I've been using this gdb server for months and it's very solid.