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]

17 thoughts on “STM32 F4 Discovery tutorial using open source tools

    1. 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!

    1. 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.

  1. 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?

      1. Ya I had the STM8S board, so the 32-bit tools ain’t no good. This was a few years ago that I bought the board and ran into this problem, so maybe there are some open tools nowadays.

        My point was that out of the box, the thing was unusable :(

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

    1. The lite version has no limitations, but it’s just the command line tools. The full version includes the IDE (based on eclipse) and some other things you don’t really need.

    1. 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).

  3. 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?

    Thanks

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