Using the STM32F4DISCOVERY on the Mac OS X 10.8.4 Command Line

6299osx-mountain-lion-iconThis will be effectively a copy of my previous post, but targeted at OS X. The gist is, get a toolchain, debug connector, and open-source firmware library set up to use the STM32F4DISCOVERY dev board from ST as quickly as possible on OS X. Unfortunately, it’s not QUITE as easy as on Ubuntu. Fortunately, it’s not a lot worse.

Prerequisites

The first thing to take care of is getting the necessary OS X tools to get going. These include Homebrew and the Command Line Tools for Xcode. We’ll start with the latter.

  1. Head to https://developer.apple.com/downloads/index.action. You’ll need to log in with an Apple ID.
  2. Do a search on the left for ‘command line tools’ and pick the newest one.
  3. Click the download link on the right. Note, it’s pretty beefy, just over 110MB.
  4. Open the new disk image you’ve got and double-click the .mpkg therein.
  5. Click next a bunch until the tools are installed.

This will take care of installing the appropriate desktop compilers, as well as an appropriately new version of git.

Next up is installing Homebrew. This couldn’t be simpler. Open up a terminal:

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

(Thanks for the update, Graeme!)
Enter your admin password when prompted, and click through until you’re done. Just to be safe:

$ brew doctor
Your system is ready to brew.

 Install the toolchain

Conveniently, the PX4 Autopilot Project has created a Homebrew formula to make installation super easy, not that it really does all that much you couldn’t have done by hand. We’ll use the 4.7 GCC branch:

brew install https://raw.github.com/PX4/homebrew-px4/master/gcc-arm-none-eabi-48.rb

(Thanks for the updated, Graeme!)
Boom. Toolchain ready to go, on your $PATH. Easy as pie.

Install stlink

Again, we’ll use Texane’s stlink to talk to the STLinkV2 debugger on the board.

brew install automake autoconf libusb libusb-compat pkg-config
sudo easy_install pyyaml

cd
mkdir Development && cd Development
mkdir embedded && cd embedded
mkdir tools && cd tools
git clone https://github.com/texane/stlink.git
cd stlink/
./autogen.sh
./configure
make

 Install the firmware lib and examples

(NOTE: The rest of this is basically copied verbatim from the last article.)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 https://github.com/libopencm3/libopencm3-examples.git
cd libopencm3-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.

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:

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:

arm-none-eabi-gdb

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

 

13 Comments

  1. Spandex
    September 20, 2013

    Great guide, thanks.

    Using an stm32f1 discovery on 10.8.4, st-util didn’t immediately work. I had to compile and run the USB fix as described here:

    http://cu.rious.org/make/getting-stlink-to-work-on-mac-os-x-with-macports/#comment-330
    (basically following the instructions in the README in the stlinkv1_macosx_driver folder under stlink).

    Once I did this and then re-connected the board, everything worked fine.

  2. […] and st-link, and how to integrate it with eclipse. Setting up the compiler was found on another blog. This tutorial is for the first part pretty much the same as his, later I will show you how to […]

  3. Clif
    December 27, 2013

    Bro, this is awesome! Got my board up and running in no time! Thanks again! Look forward to new updates/articles 😀 Keep up the great work!

  4. IndianaJoshnat
    January 20, 2014

    Hi,
    Could you also please post instructions on how to integrate eclipse into the environment? An IDE is more user friendly for those of us who can’t deal with command lines

  5. Graeme
    February 10, 2014

    Thanks for posting this! I just followed the steps and everything worked perfectly except for two little changes I had to make:
    – Trying to install homebrew was giving me a 404 error. This worked though:
    ruby -e “$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)”
    – Also got a 404 error installing the toolchain because they’ve since updated it. Had to use:
    brew install https://raw.github.com/PX4/homebrew-px4/master/gcc-arm-none-eabi-48.rb

    Thanks again!

  6. February 11, 2014

    Thanks for the updates! I just changed those in the post.

  7. Michal Schulz
    April 8, 2014

    Very nice tutorial. However, for me the st-link failed to build due to missing pkg-config tool. So, I would suggest extending the list of installed packages from

    brew install automake autoconf libusb libusb-compat

    to

    brew install automake autoconf libusb libusb-compat pkg-config

  8. April 10, 2014

    Hmm, I wonder if pkg-config used to come with Xcode but doesn’t anymore or something. Anyway, thanks for the tip! Updated.

  9. Jimmy Devarie
    June 13, 2014

    Thanks for the instructions. Mine worked at first try without any issues.

  10. Louis
    October 27, 2017

    hey thank you very much for this tutorial. But I am not able to run ./autogen.sh
    ./configure
    because I can’t find them in the folder. Do you have an idea what the problem is. Everything else worked fine. Sorry for my English. I am not a native speaker.

Leave a Reply

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