This article will go through the required steps to setup an environment for writing, programming, and debugging code for ARM Cortex-M processor. As I am predominately a OS X user (sometimes Linux depending on my mood) the information provided is tailored towards OS X users, however, as all of the tools used in the setup are open-source, the information should be transferable to other platforms.
ST STM32VL-DISCOVERY board- or any other ARM Cortex-M Processor, however most of the examples shown will be for the STM32VL
ST-Link/v2 (or other compatible ICD/Programmer, for STM32)
- NOTE: If you have the STM32VL-Discovery board, there is an ST-Link built-in, and it is not required to get an external ST-Link, however if you plan on developing custom projects built around the ST range of microcontrollers it may be worth to get one.
You will also need:
- Wires, LED and other components you may want to play around with, note that for each example I will list the parts used with links to where you can get them.
- A computer, but given you are reading this I am going to assume you have one.
To manage packages on my mac (OS X 10.9), I use homebrew, so I will show you how to set that up, however if you are on Linux, or prefer a different package manager (i.e. macports), most of these packages should be available. You can also alternatively install all of these packages manually, though I would advise against it, as in my experience it can be a road riddled with bugs.
$ ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)" $ brew doctor
You are going to need a compiler to generate your object code that will be loaded onto your microcontroller. To do this you are going to need a toolchain. The GNU toolchain for ARM Cortex-M and Cortex-R processors is really great, and can be easily installed using homebrew.
(Note: you can use an IDE for ARM development, however the examples and instructions here are built around the GNU ARM toolchain. Further, if you are developing on OS X or Linux IDE support for ARM development is limited with most being built specifically for Windows)
Installing the GNU Toolchain with Homebrew
$ brew install https://raw.github.com/PX4/homebrew-px4/master/gcc-arm-none-eabi-47.rb
The ST-Link (or compatible ICD/Programmer) is essential for ARM microcontroller development. It is an in-circuit debugger and programmer for the STM8 and STM32 microntroller families.
Installing ST-Link Utils using Homebrew
$ brew install automake autoconf libusb libusb-compat $ sudo easy_install pyyaml $ mkdir ~/Development $ cd ~/Development $ mkdir ~/Development/embedded $ cd ~/Development/embedded $ mkdir ~/Development/embedded/tools $ cd ~/Development/embedded/tools $ git clone https://github.com/texane/stlink.git #ST-LINK command line utility #Source: https://github.com/texane/stlink $ cd ~/Development/embedded/tools/stlink/ $ ./autogen.sh $ ./configure $ make
Extra Configurations for ST-Link/v1
The ST-Link/v1’s SCSI emulation is very broken, You will need to tell your operating system to ignore the ST-Link/v1, as the SCSI emulation on it doesn’t play nice with UNIX systems.
Do one of the following before using your ST-Link
$ modprobe -r usb-storage $ modprobe usb-storage quirks=483:3744:i
#add "options usb-storage quirks=483:3744:i" to /etc/modprobe.conf #then $ modprobe -r usb-storage $ modprobe usb-storage
$ cp stlink_v1.modprobe.conf /etc/modprobe.d #then $ modprobe -r usb-storage $ modprobe usb-storage
The ST-Link/v2 should work right away, nevertheless, doing the above fix for STLINKv1 won’t hurt anything and will prevent you from having to do the work later if you are using an ST-Link/v1.
- You must launch st-util with “-1” flag (source)
$ /path_to_stlink/st-utils -1 #or if you have added the stlink folder to your path $ st-utils -1
Setting up a Development Environment for STM32 Projects
Option 1, Firmware Lib => Simple
The libopencm3 project is a good place to start with ST programming. Featuring a large free/libre/open-source (LGPL v3, or later) firmware library for various ARM Cortex-M3 microcontrollers, including the ST STM32 range, libopencm3 offers examples, community and documentation to help for a smooth transition from Arduino to ARM.
To get more familiar with libopencm3 go to there main wiki @ http://libopencm3.org/wiki/Main_Page
libopencm3 quick start
The code below will help you to setup a workflow to develop for ARM Cortex-M microcontrollers using the resources available from libopencm3.
$ cd ~/Development/embedded/ $ git clone https://github.com/libopencm3/libopencm3-examples.git $ cd libopencm3-examples $ git submodule init $ git submodule update $ make
Test to see everything works
(Note: The Example below is for the ST STM32VL-DISCOVERY board)
$ cd examples/stm32/f1/stm32vl-discovery/miniblink/ $ make $ cd ~/Development/embedded/tools/stlink/ $ ./st-util #Short way $ arm-none-eabi-gdb miniblink.elf -ex "tar ext :4242" (gdb) load (gdb) continue
Option 2, Bare Metal => Fiddly
- (Coming Soonish)
Here is a list of helpful links to tutorials and information to get you started on the path to development using ARM microcontrollers
STM32 Open Source Course