i make things

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

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.

Shell

1

2

3

4

5

6

7

8

9

10

11

12

13

14

sudo apt-getinstall libusb-1.0-0-dev autoconf git python-yaml

cd

mkdirDevelopment&&cdDevelopment

mkdirembedded&&cdembedded

mkdirtools&&cdtools

git clonehttps://github.com/texane/stlink.git

cdstlink

./autogen.sh

./configure

make

# Make the stlinkv2 load when you plug it in.

sudo cp49-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.

Shell

1

2

3

4

5

6

cd~/Development/embedded/

git clonehttps://github.com/libopencm3/libopencm3-examples.git

cdlibopencm3-examples

git submodule init

git submodule update

make

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.

1

2

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

make

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:

1

2

cd~/Development/embedded/tools/stlink/

./st-util

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:

1

arm-none-eabi-gdb

from the (gdb) prompt:

1

2

3

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

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: