Skip to content

ST LINK tool

Peter Kietzmann edited this page Mar 19, 2015 · 2 revisions


Many STM-boards include an on-board ST-LINK programmer. To program the board you just need to connect a micro-USB cable to the USB port that is centered on the top of the board. To write software into the mircrocontrollers flash memory we recommend to use OpenOCD. However, some time ago we used the ST-LINK tool for this. This is a quick guide about installing and using the ST-LINK tool.

Installing the 'stlink' tool under Linux/OSX

  1. First of all you have to download the st-flash tool from texane's github repository:

# git clone stlink

  1. Change into the new directory:

# cd stlink

  1. Build the st-flash tool
# ./autogen
# ./configure 
# make

For this step you have to have a working build-environment installed, for debian/ubuntu you can do this by installing the build-essential package.

  1. Add the st-flash and st-util tools to your bin-path

Flashing a new firmware to the device

Now you have to connect the device to your computer via USB-microUSB to write your program on it. Use the CN1 connector on the STM32F4discovery board for this. Normally, the device should be flashed automatically by typing:

make flash

which should run the st-flash tool. However, this did not work at my setup so I flashed the board manually using the st-flash tool:

sudo st-flash write bin/stm32f4discovery/hello-world.hex 0x8000000

(For other boards you type the respective board name). The .hex file should be written to the devices program-storage with start address 0x8000000

Debugging a program

After you have compiled a program, you can start the st-util tool from the projects repository with:

sudo st-util

This should automatically connect to your device and start a GDB-Server listening at port :4242. In another terminal you start the GDB with:

arm-none-eabi-gdb -tui *your_project*/bin/stm32f4discovery/hello-wolrd.elf

The declaration of the .elf file is important because otherwise there wouldn't be meta-information like code line numbers. The option -tui (Text User Interface) runs a terminal interface which shows the source file, assembly output, program registers etc. and makes it more comfortable to debug. The last step to debug your program is to connect the GDB to the GDB-server (which runs in the other terminal and waits for connection). After the GDB started just type:

target extended-remote :4242

Congratulations! You should now be able to debug your program using the GDB-commands.

Clone this wiki locally
You can’t perform that action at this time.