Using the STM32F4DISCOVERY on the Ubuntu 13.04 Command Line

6299imgresThis tutorial follows the same basic outline as this post on but some things have changed since that was written such that it no longer works unmodified, and the various similar tutorials leave some bits out. My goal here is to get some custom code on the STM32F4DISCOVERY board as quickly as possible, hopefully paving the way in the near future for a full eclipse-based IDE setup.

Install the toolchain

We’ll be using the GNU Tools for ARM Embedded Processors as the toolchain of choice. Conveniently, they offer a repo-based package, all the info is in the readme. In a terminal:

sudo add-apt-repository ppa:terry.guo/gcc-arm-embedded
sudo apt-get update
sudo apt-get install gcc-arm-none-eabi

Verify that arm-none-eabi-gcc works:

arm-none-eabi-gcc -v

you should get a slew of configuration parameters and something like gcc version 4.7.4 20130613 (release)... in the last line.

Well, now you’ve got a toolchain! Wasn’t that easy!

Install stlink

Now we need a utility to actually talk to the discovery board. I intend to look into OpenOCD as well, but for now the ticket is Texane’s stlink. First, we need to install some prerequisites. Some of these are actually for the next step.

sudo apt-get install libusb-1.0-0-dev autoconf git python-yaml
mkdir Development && cd Development
mkdir embedded && cd embedded
mkdir tools && cd tools
git clone
cd stlink

# Make the stlinkv2 load when you plug it in.
sudo cp 49-stlinkv2.rules /etc/udev/rules.d
sudo udevadm control --reload-rules

 Install the firmware lib and examples

This isn’t strictly within the scope of setting up a dev environment, although I guess one could make the argument. The main point of including it is to get you (me) up and running with some example code to play with ASAP. ST distributes the STM32F4DISCOVERY with a firmware library that’s pretty useful and complete, but I haven’t really looked much into the licensing, and anyway it’s very much oriented towards the commercial toolchains and really development environments ST supports out of the box (Keil MDK-ARM, IAR EWARM, Atollic TrueStudio, and Altium TASKING VX). I found it was quicker simply to use libopencm3, the new kid free-as-in-speech-and-beer ARM firmware library. Conveniently, it includes a bunch of good examples too.

cd ~/Development/embedded/
git clone
cd libopencm3-examples
git submodule init
git submodule update

Testing everything

We should now have all the examples, as well as libopencm3 itself in a subdirectory, so let’s go try to build one and load it to our dev board.

cd examples/stm32/f4/stm32f4-discovery/miniblink/

Everything went alright? Great! OK actually I lied, when we ran make before that actually built all the examples as well. Anyway, it was required to compile the library componets before making the examples, so now if you modify miniblink.c you can easily remake it. Anyway, we’ve now got a .elf to load. You should plug in your dev board now. In a new terminal, start stlink:

cd ~/Development/embedded/tools/stlink/

It ought to connect to the on-board ST-LinkV2, listening for a debug connection on local port 4242. In the previous terminal where you made the miniblink example:


from the (gdb) prompt:

(gdb) target extended-remote :4242
(gdb) load miniblink.elf
(gdb) continue

This should start blinking the green LED on the dev board. Now, edit miniblink.c, remake, and get going on more fun stuff! (HINT: The green LED corresponds to GPIO12. The orange, red, and blue LEDs are GPIO13, GPIO14, and GPIO15, respectively. They all happen to be on port GPIOD).

Coming soon! Using the STM32F4DISCOVERY on Mac OSX. Effectively the exact same tutorial, but targeting OSX 10.8.4 Mountain Lion.


  1. January 2, 2014

    Very nice. Simple and straight to the point.

  2. st
    August 22, 2014

    I just wanted to say thank you! James has said everything else of importance already 😉

  3. Martin Round
    August 30, 2014

    When I tried it (Ubuntu 64) I initially got a message about arm-none-eabi-gdb not being installed. When I tried to install it (sudo apt-get-install gdb-arm-none-eabi) it I got error messages about a conflict – but I was able to override those and force the install with:

    sudo apt-get -o Dpkg::Options::=”–force-overwrite” install gdb-arm-none-eabi

    Thanks for a very helpful and easy-to-follow tutorial.

  4. Jithin
    November 6, 2014

    Thanks. Worked right away. 🙂

  5. daicav
    January 23, 2015

    The package pkg-config was necesary for me (lubuntu 14.10).

    Thanks a lot.

Leave a Reply

Your email address will not be published.