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]

50 thoughts on “How To Develop For STM32 Discovery Boards Using Linux

    1. Agree with Alex. I am using an ST processor in a project at work, the ST supplied library is terrible, so many bugs it is unbelievable. the support is also beyond a joke.

      I will definitely steer away from ST in future.

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

    http://www.st.com/internet/evalboard/product/252419.jsp

    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 https://github.com/texane/stlink 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.

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

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

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

      1. I probably could. I want to use PWM to controle at least 6 fans and a few A2Ds to measure temperature. I would have to take a hard look to see if there is enough IO to do both. Would bet that I could do just the PWM fan control with the launchpad and one of the two supplied chips.

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

    1. See my post above with instructions. I used the STM32F4 yesterday and was able to get it to work and connect with GDB. The udev rules are critical to getting the device node to display. Vendor and device IDs appear to match the rules, and gdb appears to connect just fine to the stlink proxy.

  4. 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: http://forums.leaflabs.com/topic.php?id=630

    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.

  5. Hi,

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

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

    1. MrX for clarification’s sake, how many common/popular Linux distributions are there that aren’t GNU based? Would you be able to list some off, I am interested in knowing the answer.

      1. There is Linux/uClibc (with busybox) which pretty much covers all Linux installs in routers and TVs. As anon said very well, there is also Android and WebOS.
        You can also use the BSD userland with Linux (on desktop).

        and these are just from the top of my head..

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

    1. You have the Versaloon code on the ST-Link MCU on the board? Any link to a writeup on that? It sounds like a much better option than dealing with the half-baked stlink firmware.

    1. 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 (https://github.com/jsnyder/stm32ld, https://github.com/jsnyder/stm32loader). 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 autogen.sh 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: http://sourceforge.net/projects/lpc21isp/

      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: https://github.com/jsnyder/arm-eabi-toolchain

  8. I successfully flashed an image onto an STM32F4 Discovery from GNU/Linux last night using http://gitorious.org/~tormod/unofficial-clones/dfuse-dfu-util

    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 stm32f4discovery_fw.zip

  9. 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. :)

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

Leave a Reply to Bob Burns (@BobBurns22)Cancel reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.