Atomic Object’s blog on everything we find fascinating.

I've been a developing software at Atomic Object since 2012, working at all levels of programming, from firmware all the way to web development. My background in computer engineering helps me to think about and understand systems from top to bottom.

STM32F4 Discovery Toolchain for Mac OS X

Update – I’ve since discovered an easier way to get a fully-functional bare-metal toolchain. See my updated post here.

I recently picked up a STM32F4 Discovery board to play around with, and have been having a bunch of fun with it.

While there are a fewgoodarticles already out there about building toolchains targeting bare-metal Cortex processors, many are already out of date, and I struggled to find anything that really went through the whole process of setting up a full development chain for the STM32F4 Discovery board.

Building

Since we’ll be compiling GCC, you’ll need some compiler already installed on your system, so grab XCode, the XCode Command Line Tools, or use something like the osx-gcc-installer. You’ll also require a few miscellaneous dependencies, so grab them from Homebrew.

brew install mpfr gmp libmpc texinfo libusb-compat libftdi wget

Next, you’ll need to actually install a compiler and related utilities. There are a few good scripts already out there, but they didn’t quite suit my purposes. The CodeSourcery Lite toolchain installed by jsnyder’s arm-eabi-toolchain script doesn’t have hardware float support for the Cortex M4F in the STM32F4 microcontrollers. The summon-arm-toolchain uses Linaro’s gcc, which has hardware floating point but also has some microcontroller support libraries I’d rather keep with my projects. As such, I modified the summon-arm-toolchain script and also enabled st-link support. You can clone my fork here: https://github.com/ehntoo/summon-arm-toolchain.

After cloning the repository, all you need to do is run ./summon-arm-toolchain, and it will fetch, compile, and install GCC, GDB, newlib, binutils, and OpenOCD. All tools are installed into ~/sat/ by default so as to not interfere with anything you’ve already got on your system.

Connecting

To actually get started developing on the hardware, you’ll need to fire up OpenOCD.

4 Comments

The GCC sources comes with a script (contrib/download_prerequisites) that downloads the necessary dependencies so that they will be built statically along with the compiler. This is far preferable than building them as separate dynamic libraries.