By now, almost everyone’s managed to acquire a bajillion cheap ARM dev boards, and there are always more coming.  As these chips get cheaper, and available in more hacker-friendly packages, they’re going to overtake chips and boards like the AVR and the Arduino, it’s just a matter of time.  Unfortunately, the ARM ecosystem isn’t as simple to work with as the AVR or PIC ecosystem.  With both of these 8-bitters, you’re working in the manufacturer’s walled garden.  ARM manufacturers, on the other hand, are free to glue whatever crazy stuff they want onto the ARM core.  As a result, peripheral sets and their use vary widely, even within the same manufacturer.  Efforts like the CMSIS ameliorate this effect to some degree, but this isn’t a cake-walk.  Add on to that the difficulties in simply getting a toolchain up and running, and anyone with mere Arduino experience is lost (even more experienced 8-bit devs are going to have some tough going).

So, here’s a short guide to getting a toolchain for the STM32 series up and running quickly.  These instructions will be specific to Linux, but should translate to OSX or Windows fairly easily.

First, I downloaded the Linaro Bare-Metal ARM toolchain (http://www.linaro.org/downloads/).  It’s important to get the Bare-Metal toolchain.  Other toolchains generate binaries that aren’t capable of running sans operating system. The bare-metal toolchain is at the bottom of the page.  This package contains the compiler, linker, debugger, and other tools used to turn source code into machine code.  I used the precompiled package from Linaro because it’s a simple off-the-shelf method to get up and running quickly.  Unlike Codesourcery/Sourcery Tools, the Linaro toolchain supports the Cortex M4 with FPU right out of the box.

In the past, I have attempted to compile their own toolchain (https://github.com/esden/summon-arm-toolchain/), but this is not a simple process.

In Linux, I just extracted the tar.gz file to the folder I wanted it to live, and added that folder to my PATH.

Next comes OpenOCD.  OpenOCD is an open source debugger/flash utility for lots and lots of different chips.  I had to get the latest dev version from the git repo, (http://openocd.sourceforge.net/repos/), as the latest stable release does not include STLink code.  If a version beyond 0.5.0 is released by the time you’re reading this, download that instead.

Installation was pretty easy.  I installed the dependencies using “sudo apt-get build-dep openocd”, then ran “./bootstrap”, followed by “./configure –enable-maintainer-mode –enable-stlink”, followed by “make” and “make install”.

Once I had the toolchain and debugger up and running, I downloaded some software to compile.  This github repository (https://github.com/nabilt/STM32F4-Discovery-Firmware) includes the test firmware provided by ST, with a Makefile capable of building it using GCC. Chibios (http://chibios.org/dokuwiki/doku.php) also includes demo files for all the discovery boards.

The first time I attempted to build the STM32F4 firmware, it didn’t quite work out.  Due to the varied nature of the ecosystem, a separate linker script is needed for each chip.  Furthermore, different compilers need different sections to their linker scripts, so it might not be possible to simply yank one from somewhere else.  The linker script tells the linker where different memory sections map into real, physical memory on the chip.

Here’s the linker script I eventually got working for my STM32F4-Discovery:

Makefiles themselves are beyond the scope of this post (and beyond the scope of my brain, in a lot of ways), but taking a peek at the Makefile used in the STM32F4 Demonstration firmware from above, there are  a boatload of dependencies from outside the project.  These are all CMSIS drivers, or required startup code.  This is a big part of why ARM chips are more difficult to use than ARM or PIC chips.  Fortunately, most manufacturers release some boilerplate startup code for their chips.  As long as it’s included in the makefile, everything will work as it should.

And those are the basics of going from nothing, to compiling demonstration code.  Right now, I’m looking heavily at the ChibiOS platform to develop some projects.  This abstracts a lot of the hardware stuff, although it isn’t nearly as simple as Arduino for getting up and running.  Hopefully with the upcoming release of the Arduino Due, there will be some development in making a really easy-to-use ARM platform.

Comments on this entry (11 comments)

Did you like this post? You can share your opinion with us! Simply click here.

Scott Knight

I don’t know if you’ve ever looked into it, but there’s a set of gcc ARM toolchain pre built out there that the GBA and NDS coders use. http://www.devkitpro.org You’d have to create a custom crt0 script, but might be worth looking into since it comes with nice installers for linux/windows/mac I think.

Reply
DS oberoi

How is the object code, downloaded into the chip.

Circuit and sotware used for the pupose may be indicated.

Reply

That is highly dependent on the chip.

Reply
Lucas Pirolla

Brad, I’m using the LPC1788 chip, and developing with the LPXpresso IDE. Problem is that this IDE limits the size of the file to be flashed in 128Kb. I really need a way to overcome this. Can you help me out?

Reply
DS Oberoi

Pls. do let me the tools/programmer/etc – Open source for LPC1114FN28.
I may get sample by next weekend

Reply
DS Oberoi

Excellent article.

WIll CoIDE from http://www.coocox.org work for LPC1114FN28.

Regards

Reply

There is no official support for the LPC1114FN28 in CoIDE, but it supports other chips in the same range, so you may be able to get it to work. You should contact the folks at coocox for details on that, though.

Reply

This GCC toolchain would work for that, although you’d have to spend the effort to extract libraries and linker scripts from the LPCXpresso IDE. Unfortunately, that’s a lot of work that I’m not sure how to do. If you don’t have a large existing codebase, it might be easier to start fresh with the CMSIS libraries from NXP (or others). Google around (or search github) for CMSIS LPC17xx or GCC LPC17xx, and you’ll find examples that pertain more to what you’re doing.

Reply
DS oberoi

Thanx. How to download object code to MCU LPC1114FN8.

Reply

Add Your Comment