stm32f4 discovery hello word

I got a stm32f4 discovery development board recently.  It has a ST Micro stm32f4 ARM Cortex M4 SoC running at 168MHz and had a bunch of goodies including an st-link/v2 in-circuit programmer/debugger, break out of all the stm32f4 IO, a 3-axis accelerometer and more, all for less than $15!  Crazy!  Check it out if you’re getting bored with your Arduino.  However, the discovery isn’t quite as user friendly as the Arduino.  This post goes through getting the dev board “hello world” (blinking LEDs) up on the discovery from Mac OS X.

The target for the discovery is arm-none-eabi.  The first step is to get the toolchain up: binutils and gcc.  I used binutils-2.23 configured with –target=arm-none-eabi.  GCC depends on GMPMPFR, and MPC; install them if needed (in that order).  I used gcc-4.7.3 configured with –target=arm-none-eabi –enable-languages=’c’ –disable-libssp.  libssp is a stack protection library; it depends on libc, which we aren’t building.

The next step is build the IO_Toggle example from the discovery board firmware package. I used v1.1.0.  The firmware package has project files for various embedded development environments, but no Makefiles for gcc.  Here is the Makefile and linker script stm32f4xx_flash.ld.  These are based on the files posted at STM32F4 Notes, although his setup involved modifying the IO_Toggle source files and did not work out of the box for me.  Drop them both into the Project/Peripheral_Examples/IO_Toggle subdirectory of the firmware package and run “make”.  This should build IO_Toggle.elf.

Finally, we need a programmer to load the image onto the board.  I used openocd, which depends on libusb.  I used libusb-1.0.9 and openocd-0.7.0.  (libusb-1.0.16 was literally released while writing this.  I haven’t tried it yet.)  openocd was configured with –enable-stlink.

Finally, we can program the board!  In IO_Toggle, run “openocd -f board/stm32f4discovery.cfg -c ‘program IO_Toggle.elf verify reset'”.  The example should be up and running!

I don’t think any of this was specific to Mac OS X and the same story should work under, say, Linux.

This isn’t so exciting.  Baby steps.  Next up: Get gdb working with openocd.  How does IO_Toggle work?  What about the other peripherals?  More to come!

About these ads

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s