Getting STLink with Versalon firmware working with OpenOCD

So you updated your STM32VLDISCOVER with Versalon firmware as I did here.

But, what next? Now you need get OpenOCD support.

First clone OpenOCD:

$ git clone

Then go back OpenOCD tree to 6 Jun 2011:

$ cd openocd
$ git checkout e899fcaca0d207eadea569b9dd9b2d54afafcfd4

Apply this patch (openocd_stlink.patch.tar.gz) to add support the Versalon-STLink on OpenOCD:

$ patch -p1 < ../patch/openocd.patch

Execute bootstrap to create the configure:

$ ./bootstrap

Setup configure parameters:

$ ./configure --enable-maintainer-mode --enable-vsllink --enable-usbprog --enable-jlink --enable-ft2232_libftdi

Compile it:

$ make

Install it:

$ sudo make install

Use this stlink-versaloon config:

# OpenOCD configuration file for in-circuit debugging the stm32vldiscovery
# loaded with the versaloon firmware.
# To start debugging issue those commands:
#    arm-miosix-eabi-gdb main.elf
#    target remote :3333
#    monitor soft_reset_halt
#    monitor target_request debugmsgs enable
#    monitor trace point 1
# The last two commands are required to redirect printf inside the MCU
# through SWD, and make the output appear inside gdb

# Daemon configuration
telnet_port 4444
gdb_port 3333

# Interface (using versaloon)
interface vsllink
transport select swd
swd_mode 2
swd_delay 2

# This is a board with an STM32F100RBT6
# Use 2 kB instead of the default 16 kB
source [find target/stm32.cfg]

Then start OpenOCD with this command:

# openocd -f stlinkversa.cfg
Open On-Chip Debugger 0.5.0-dev-00906-ge899fca-dirty (2012-02-21-17:04)
Licensed under GNU GPL v2
For bug reports, read
Warn : must select a transport.
Info : OpenOCD runs in SWD mode
1000 kHz
adapter_nsrst_delay: 100
jtag_ntrst_delay: 100
cortex_m3 reset_config sysresetreq
Info : Versaloon(0x33)by Simon(compiled on Oct 25 2011)
Info : USB_TO_XXX abilities: 0x00000008:0x00000040:0xC0000006
Info : clock speed 1000 kHz
Info : stm32.cpu: hardware has 6 breakpoints, 4 watchpoints

Now open a new terminal e connect to openocd server by telnet:

$ telnet 4444

Execute these commands to erase stm32f100 internal flash:

> reset halt
target state: halted
target halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x08000b4c msp: 0x20000400
> stm32x unlock 0
stm32x unlocked.
INFO: a reset or power cycle is required for the new settings to take effect.
> flash probe 0
device id = 0x10016420
flash size = 128kbytes
flash 'stm32x' found at 0x08000000
> stm32x mass_erase 0
stm32x mass erase complete

To flash your binary (i.e. blinky.bin) copy your .bin to directory where you ran openocd command and from telnet execute:

> flash write_bank 0 blinky.bin 0
wrote 132 bytes from file blinky.bin to flash bank 0 at offset 0x00000000 in 0.154993s (0.832 KiB/s)
> reset run

P.S.: If you receive the error message “`pkglibdir’ is not a legitimate directory for `DATA'” then read it:

2 thoughts on “Getting STLink with Versalon firmware working with OpenOCD

  1. Is ST-Link not implemented in OpenOCD? You should submit your patch rather than cloning and patching old versions.

  2. Hi Jake,

    There are many people working for add support to ST-Link v1 on OpenOCD. I’m not using default ST-Link, but a modified version with Versalon Firmware.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s