Sunday, 19 September 2010

A better program for the bootloader

As mentioned in the last post, I found an alternative program for the Python script for the bootloader written by geoff at  This seems to be much better (it can handle .hex files for example) and also more reliable. However, it is Linux only (at the moment), so anyone doing this on Windows will have to persevere with the Python script.

(It's possible the reason it's more reliable is I have rebuilt the MAX3232 serial interface to use shorter leads and be nearer the STM32VLDiscovery)

The web page is at

To build it, find a working directory and type :

svn checkout stm32flash-read-only
cd stm32-flash-read-only
sudo make install

You will need subversion and build-essential installed for this to work in Ubuntu - these commands install the stm32flash program in /usr/local/bin

You can then run the program (as before) by pressing reset and entering

stm32flash /dev/ttyS0

which port you use depends on the way your system is set up, ttyS0 is the normal main serial port and will be the most common one. Hopefully this will display

stm32flash -

Serial Config: 57600 8E1
Version      : 0x22
Option 1     : 0x00
Option 2     : 0x00
Device ID    : 0x0420 (Medium-density VL)
RAM          : 8KiB  (512b reserved by bootloader)
Flash        : 128KiB (sector size: 4x1024)
Option RAM   : 15b
System RAM   : 2KiB

Resetting device... done.

You may get :

stm32flash -

Serial Config: 57600 8E1
Failed to get init ACK from device

in which case press the STM32 reset switch and try again - if that doesn't work check the loop back tests.


  1. Hi, Paul! I will purchase a STM32 discovery development board. Very useful your blog about it. Did you try to program this development board using USB under linux? Do you know if OpenOCD can do it?

    My regards,


  2. I'm on Ubuntu 10.04 - hence the need to use the Bootloader :)

    I did spend some time looking at USB traffic on the STM8S Discovery (similar gadget) but I don't understand it well enough. Someone who posts on the ST Forum is going to have a crack at it (apparently) so may get somewhere.

    I noticed OpenOCD - they apparently have the specs from ST under a no-distribution policy but so far it hasn't got as far as code. I suppose the problem they have is that they can't release the code as source, because it would be easy to figure out how ST do it from that source. That leaves a binary module (like Nvidia) or possibly obfuscated C code ?

    I think ST are barking mad. This is a brilliant board in many ways - much quicker than AVR/PIC and much more powerful hardware, and ridiculously cheap. Only the LPCXPresso is competition for it. But they seem to make it as difficult as possible for people to use it.

  3. I am the author of this flash tool... if the reset does not work, try the -c option, it will resume the connection without sending the initial auto-baud configuration bytes.

  4. Thanks to a kind user we now have windows support in stm32flash, you may want to update your article.

  5. very nice !!!
    I used under Linux,
    but this one is much better :-)


  6. This compiled and ran great on my mac under snow leopard. I'm building the development environment now using the *summon-arm-toolchain* tool from github.

  7. Hello,

    I would like to use these stm32flash program on windows, but I don't found the code anywhere...
    neither on the link up, does anyone still know where I could download it?
    Did you know if it work with the stm32f2xx series?
    Thanks a lot for your help.
    Best regards.



  8. @antoine.odonne - The windows support is built in, compile it using CYGWIN

  9. Could you please tell me why I am getting the bellow error
    ~/stm32flash-read-only$ stm32flash /dev/ttyS0
    stm32flash -

    Serial Config: 57600 8E1
    read_byte: Success
    stm32flash: stm32.c:94: stm32_read_byte: Assertion `0' failed.

    I am using stm32f2xx board and set the jumper setting for embedded boot mode loader.