Setting an Ubuntu system up for STM32 Development

Getting the Basics Scraped Together

The first thing you'll need to do is get together the basic packages that you'll require (or at least want) for any sort of development:

sudo apt-get install build-essential gdb manpages-dev

After that, you're going to want a good editor and associated tools. I happen to prefer emacs.

sudo apt-get install emacs

If you plan to use any of the source from this site, you'll need the Mercurial version control system:

sudo apt-get install mercurial

The Cortex-M3 toolchain

The next major category of necessary software is a toolchain capable of compiling for the ARM Cortex-M3 processor core, which is the core used by the STM32 line of processors. I am slowly putting together a PPA (package repository for Ubuntu systems, hosted by Canonical on their Launchpad service) for STM32 development, but it is currently incomplete and out-of-date. Still, I'll document it as the place to start:

sudo add-apt-repository ppa:eblanton/cm3-dev

sudo apt-get update

This will add my PPA to your system's list of known software, and prepare you for installing the software it contains. First, install the binary utilities, compiler, and debugger from the PPA:

sudo apt-get install binutils-cortex-m3 gcc-cortex-m3

JTAG Interface for On-Chip Debugger and Firmware Updates

Another piece of software in the above-mentioned PPA is OpenOCD, a brilliant piece of software capable of communicating with a myriad of JTAG and other processor interfaces, providing a gdb server for in-circuit debugging of your firmware, and a wide variety of functions for manipulating processor configuration and firmware. If you have configured the PPA, you can install it with:

sudo apt-get install openocd

Configuring OpenOCD

Part of the OpenOCD configuration is specific to your JTAG interface, and part is generic to all STM32 devices. The OpenOCD configuration file lives at /usr/share/openocd/site/openocd.cfg. The OpenOCD configuration language is Tcl, and basic configuration is accomplished by sourcing existing configuration files into your local config. For example, if you have a Segger or IAR J-Link JTAG interface, you would put the following in your site's openocd.cfg:

source [find interface/jlink.cfg]

Pre-made configuration files are found in /usr/share/openocd/scripts, with JTAG interfaces under interfaces, CPU configurations under cpu, complex board configurations under board, etc. The find command will locate scripts under this base directory. The above command therefore tells OpenOCD to use the JTAG device interface configuration from /usr/share/openocd/scripts/interface/jlink.cfg. Identify the JTAG hardware you have, and source the appropriate script.

The next bit of configuration is generic to all STM32 processors; you may wish to change it (probably by sourcing something from board/) if you have a commercial STM32 development kit, but if you have a homebrew or application board of some type, you will probably want the following configuration line:

source [find target/stm32.cfg]

This will configure the CPU core (from cpu/arm/cortex_m3.tcl), flash banks, JTAG timings, and other parameters.