How to develop for STM32 discovery boards using Linux

Some hard work has gone into making it possible to develop for the STM32 Discovery board using a Linux system. The board boasts an ARM Cortex-M3 processor, which can be programmed via the mini-USB port on the side. But the company only supports development through their IDE’s which don’t run natively on Linux. The stlink project aims to solve this, providing a toolchain, and making it possible to flash the microcontroller via the USB connection.

The github project linked above also includes a tutorial to get you started (pdf). In addition to a walk through on compiling the software packages, it includes a simple blink program that you can use to test out your hardware. GDB, the familiar open-source debugger, is used to flash the chip. This is a bare-bones tutorial so if you end up posting about your experiences using this toolchain with the Discovery boards we’d love to hear about it.

[Thanks Texane]


  1. Alex says:

    Cool. I bought one of these but never did use it much, because it was such a hassle. Also, STM’s hardware driver library is really sloppily written.

  2. z says:

    ST is giving out free samples in the US / Canada of their ARM Cortex F4 part. I’ve never purchased the older Discovery boards since there were so many cheap or free Alternatives that actually work well on Linux. But this might be worth the effort due to the price and flexibility of the ARM GCC toolchain.

    My free board arrived about a week ago.

    I tried this yesterday and had luck. I installed the arm toolchain through Ubuntu 11.10:

    sudo apt-get install gcc-arm-linux-gnueabi

    Then installed a few st-link requirements:

    sudo apt-get install libsgutils2-dev
    sudo apt-get install libusb-1.0-0-dev

    Get the st-link software from Texane:

    git clone stlink.git

    Compile the st-link sofware per the README and useful PDF that is included.

    Copy the udev rules to /etc/udev/rules.d/ and restart the udev service. There will a device node now at /dev/stm32l_stlink2.

    ./st-util port /dev/stm32l_stlink2

    GDB can connect with:

    target remote :4242

    I hope that this helps others. I look forward to seeing your results so that we may be able to get some code up and running on this board. I was able to compile some example code and modify it for the STM32F4DISCOVERY, but it failed to load. I think that it’s a code problem on my part.

    Thanks to Texane and others for the great work on this.

    • macpod says:

      I tried, but couldn’t write to flash. Reading reported all zeros so I’m questioning the validity of that :D

      I did commit code so you can load a program via gdb that blinks the 4 leds on the board.

      • z says:

        You’re at the same point where I was as well. I had trouble writing to the flash. But at the very least, it seems that it at least connects in some respect.

        Are you saying that you didn’t manage to ever get your LED modifications to write to the flash?

        Thanks for the sample code commit, by the way.

    • mangodan2003 says:

      Did you really manage to build code for this with gcc-arm-linux-gnueabi ?

      I tried and get all kinds of errors. Works fine with home built gcc or code sourcery gcc.

      I ask as I wanted to be able get a working dev env on my phone which has gcc-arm-linux-gnueabi available from apt repos whic create linux binaries just fine, but doesnt want to build for stm32fx’s.

      Did you have to provide some special options to make it work?

  3. tayken says:

    I’ve found this website a few months back, followed the steps and I’m pretty happy with the results.

  4. lwatcdr says:

    Funny but I was thinking of geting one of these to make a fan controller for a PC. I was going to add sensors as well as use the OS to read the temps and have this control the fans.

  5. I’m trying to get the same fun started on the new STM32F4 Discovery Board, but it uses a new version of STLink, so the existing tools don’t see it.

    My suspicion is that the new, vendor specific STLink has the same broken mass storage device implementation, so the existing tools could work. But I haven’t figured out how to trick Linux into mounting the device as a USB mass storage device with the sg generic scsi.

    Any one know an easy way to do that?

  6. giorgio130 says:

    Does anyone know if that would work for a STM8s?

  7. poslathian says:

    This comes up on our forums pretty regularly – how to use the Maple IDE and libraries on a discovery board. Turns out its a realtively straightforward procedure to give yourself and Arduino-like experience on this very inexpensive hardware.

    long topic on the subject:

    Also, the new f4 chips are great, I highly recommend trying to get your hands on one of the new discovery boards since ST has been giving them out like candy.

  8. stefan says:


    I am using exactly the tool chain described in the PDF. It works great for me on my Intel based box as well as on my Nvidia Tegra based Arm netbook (both running Ubuntu). I also started documenting some of my experience with the STM32 (including C samples as well) on my webpage (I am about to add some more examples and stuff in the near future).

  9. MrX says:

    Editors: Please fix the article title, Linux is the *kernel*. In this case you are referring to a particular distribution which is GNU based (in particular the toolchain). So, for correctness, refer to it as GNU/Linux.

    Thank you

  10. ColinB says:

    I’m using Versaloon on my STM32VLDISCOVERY boards. It is SOOOOOO MUCH BETTER than the stock ST-Link firmware on the USB microcontroller. I can use OpenOCD with gdb, and the vsprog command-line tool to upload firmware in an instant.

    You need to do some minor work with a soldering iron in order to upload the right boot loader to the “ST-Link” USB MCU, but then it’s smooth sailing and it’s a pleasure to work with.

  11. DMPalmer says:

    Has anybody done this under OSX?

    Are there any cheap ARM boards that are easy to program under OSX?

    • James Snyder says:

      There are a bunch that aren’t too painful. Anything that has a built-in JTAG interface that will work with OpenOCD should be fairly painless to get working. For example, any of the Stellaris eval kits which tend to include an FTDI-based (FT2232) JTAG interface are usable with OpenOCD.

      STM32F boards are pretty easy to work with if you at the very least have a serial interface to them and can control the BOOT0/BOOT1 pins since they all have a serial bootloader. There are various tools out there that should work with these (, Also, for the STM32F4DISCOVERY board, it should be possible to use the branch of dfu-util that Roger mentioned in this thread to program the board when put into DFU mode (which he describes how to do). Compiling dfu-util out of there can be a slight bit of a pain though since not only do you need libusb and pkg-config for the to work, but you also need autotools to pick up on the pkg.m4 file so that they can properly generate the configure script. When having got libusb and pkg-config from homebrew, I did something similar to this

      A number of LPC-based boards can be programmed using lpc21isp which has compiled fine for me on OS X:

      OpenOCD can be a little irritating to get started with, but it does work with a lot of JTAG interfaces (both built-in to eval boards and stand-alone) and getting a working JTAG programmer is probably one of the most universal ways to program a wide range of hardware.

      Toolchains are also fun, but I have a Makefile to help with that on OS X using the G++ Lite sources:

    • Nabil says:
  12. I successfully flashed an image onto an STM32F4 Discovery from GNU/Linux last night using

    You need to jumper BOOT0=VDD, BOOT1=PB2=GND, and reset with the micro-usb connected. You will find a DFU Bootloader active on the micro-usb. And tormod’s dfuse-dfu-util will flash the STM32F4-Discovery_Demonstration_V1.0.0.dfu image from the Project/Demonstration/Binary folder of

  13. Badwolf says:

    I had a project that was supposed to run on this but it was way too complex for my talents,

    mine is up for sale,make a decent offer.

    wannaberockstar at hotmail dot fr

  14. OrangeTide says: has some small instructions, a blog of his experience over the last few months, and a patch to make gdb work better with the STM32.

  15. rik says:

    works! nice ! thanks ;-)

  16. fabien says:

    Hey guys,

    I wrote a GUI for the ST-Link/V2, if you want to check:

    Runs on Linux, OSX and Windows :)

  17. JAB says:

    I’ve been going through the tutorial listed above and everything is working great for me in Arch Linux so far! Well, I did have to modify a couple of things here and there for building examples and libraries, but otherwise, it works. :)

  18. MobileWill says:

    I just got one last Tuesday at one of their free seminars they are doing. They provide breakfast, lunch and a some hands on demos. Oh and don’t forget the sales pitch of some of their products.

  19. YBosco says:

    To fabien: – there is only an amd64 linux version.

    Though there is written “Qstlink2 Ubuntu X86_64 – Revision #67″, really it is only amd64 version.

    What about x86?

  20. Bob says:

    The source is available YBosco

  21. whatever says:

    I could be doing something dumb, but when running summon_arm_toolchain I get errors when trying to DL newlib-1.19.0.tar.gz from redhat. Anyone else get this?

    Here’s a pastebin

  22. ashok gopalakrishnan says:

    Thanks for the post. i could flash the code. missed sudo for some time though due to which usb was not detected.

  23. angus balmer says:

    and the journey begins :D, got this working on CentOS 6.4 x86_64 …
    Lazy level 5/5 doesnt work, reading the instructions a bit closer works easier xD, Texane/stlink pdf TO gcc-arm-embedded@launchpad TO libopencm3 TO blinking lights;<<< i say git the examples pack from there git site only, and then do make and follow the extra instructions on tty. It should say something like need to init and update something.

  24. L. Dighera says:

    Why one would go down the ST road instead of Raspberry PI is beyond me.

  25. zheng says:

    find it thank you

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,357 other followers