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.

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.

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.

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.

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.

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.

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.

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

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.

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

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.

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

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.

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

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

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.