Using the STM32F4DISCOVERY on the Ubuntu 13.04 Command Line

6299imgresThis tutorial follows the same basic outline as this post on cu.rious.org 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:

Verify that arm-none-eabi-gcc works:

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.

 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.

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.

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:

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:

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.

Also read...

Comments

  1. Pingback: Using the STM32F4DISCOVERY on the Mac OS X 10.8.4 Command Line | alexwhittemore.com

  2. 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.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">