STM32 F4 Discovery tutorial using open source tools

[Pulko Mandy] got his hands on the new STM32 F3 Discovery board. He’s a fan of the open source tools just like we are, so he posted a guide covering the use of an open source toolchain with the F3 hardware.

This board was just announced earlier this month but there is already support for it in OpenOCD. It’s not all that different from the F4 board, which we would think made the process a bit easier. [Pulko] is using the Sourcery CodeBench Lite toolchain, which works for pretty much all of the ARM chips out there. It is GCC based and comes with GDB for debugging (along with all the other tools you would expect). He did created his own Linker script and startup code. These are crucial for ARM so it’s nice that he provided them for us. He finishes up the guide by showing how OpenOCD can be used to flash the code to the chip and how it works with the debugger.

[Photo source]


  1. tophathacker says:

    The title should say F3 not F4

  2. rir says:

    and I almost digged up my F4… oh well…

    • Mac says:

      It took me less than a few hours (mostly due to pebkac) to build a toolchain from scratch to program a chibios demo into my disco F4. Thanks gentoo for crossdev.
      I still have to test debug with texane (I use another tool for flashing, don’t remember name).
      Chibios gives already all linker, rtos files and drivers. Ready to code!

  3. perfectfire says:

    Yay, I have one of these and I really don’t want to use a bunch of proprietary tools to develop on it.

  4. Grawp says:

    Why write your own linker script, when one can use tested linker scripts (and pre-made startup files) from e.g. under permissive license? (not that Attolic crap).

    • pulkomandy says:

      The goal was to understand (and explain) what is going on. I see some people handling linker scripts as ‘black magic’, and relying on toolchain vendor wizards to do it for them. I made a linker script and startup code as simple as possible so everyone can understand what’s going on.

  5. S2H says:

    I picked up an older discovery board thinking it was such a steal at $10, but I wasn’t too impressed that I had to register in order to get the dev tools.

    Eventually I registered for the tools (twice) and never got the software, so this board sits with my other unused dev boards. Maybe they don’t like Canadians?

  6. Justin says:

    I’ve never used this toolchain before, could someone inform me whether this “Lite” edition has limitations such as maximum binary size? Thanks.

  7. 0xfred says:

    Is the F3 discovery board available to purchase yet? I can’t find one in the UK, but doesn’t seem to be available in the US either.

  8. Drone says:

    Is there a tutorial like this for the F4 board?

    • pulkomandy says:

      It shouldn’t be very hard to make it work on the F4, but don’t have the hardware.
      Anyway :
      * STM32F4 Discovery is supported out of the box by OpenOCD git tree (I don’t know about the 0.6.0 release, it might have it as well). So, no need to apply patches and get a config file.
      * The startup should be identical for any Cortex-M device.
      * The linker script needs to be changed. At the top of it you’ll find some lines defining the flash and ram size and address. Just change these to match the memory map of the F4 chip, which you can find in the Reference Manual for it.

      Also remember that this is a very minimal approach to the startup, you’ll need to setup most of the hardware from C code (the most important part being the system clock, which isn’t changed by the startup so is likely to be some slow internal RC oscillator default setting).

    • Andrei says:

      Hi! You can use my setup for F4, which includes Eclipse project with makefiles.
      svn checkout andrei-development-read-only


  9. Nemo says:

    Hi guys,
    I would like to ask you a couple of questions:

    you can simulate a stm32 debug with OpenOCD (without hardware)? if so, how?
    I read somewhere that you can not do, for the simulation using qemu, but only for m3 stellaris, and not to those of the ST.

    with a debug in ram you have the ability to have multiple breakpoints, but have never been able to debug in ram, even changing the ld script. Can you give me a hint?


Leave a Reply

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

You are commenting using your 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


Get every new post delivered to your Inbox.

Join 96,771 other followers