I have an STM32 discovery board and would like to be able to program it on Linux.
What is the easiest way to do this?
Electrical Engineering Stack Exchange is a question and answer site for electronics and electrical engineering professionals, students, and enthusiasts. It only takes a minute to sign up.Sign up to join this community
An easy way to program and debug the STM32 Discovery board (or any STM32 using an ST-Link programmer) is to use the 'stlink' project https://github.com/texane/stlink (however OpenOCD seems popular too)
ST Nucleo boards also appear as a USB flash device, so don't even need
stlink - just copy the file over to them.
There are some good pages on how to develop for STM32 discovery on Linux, such as http://gpio.kaltpost.de/?page_id=131 and http://torrentula.to.funpic.de/2012/03/22/setting-up-the-stm32f4-arm-development-toolchain/ and http://jethomson.wordpress.com/2011/11/17/getting-started-with-the-stm32f4discovery-in-linux/
However I found the last link the most useful. It shows how to build ST's STM32 projects as-is - The only change is to add his Makefile, which seems like a perfect solution.
On recent versions of Ubuntu, there is a package you can install which contains an ARM compiler:
sudo apt-get install gcc-arm-none-eabi
Note that the processors are all a bit different. STM32F0..4 will all need different compiler flags, and the linker script will be slightly different for each (although only really because of the changed RAM and Flash sizes).
If You are more into text editors and Makefiles instead of using a GUI, you could do:
Get your project to the board. Either use
Code in a text editor and use command line tools. This tutorial will provide lots of tips.
And for help with compiling the STM32 examples in Linux go here. That link points to a makefile for the examples which can be invoked with
git clone git://github.com/snowcap-electronics/stm32-examples.git cd stm32-examples wget http://www.st.com/internet/com/SOFTWARE_RESOURCES/SW_COMPONENT/FIRMWARE/stm32_f105-07_f2xx_usb-host-device_lib.zip unzip stm32_f105-07_f2xx_usb-host-device_lib.zip
A couple minor code fixes are also documented, but most of the project should work with
I have had success with https://github.com/JorgeAparicio/bareCortexM (see also the linked blog posts). I'm floored that I can simply single-step through the code or browse the device memory instead of inserting debugging statements in my code or guessing what is going on inside the chip.
The bareCortexM project is an Eclipse template for developing with the Cortex M series, especially STM32, in C++ without an OS. It is configured to use openocd, gcc, and has scripts to flash and debug to several targets including some of the discovery boards. By following the instructions and installing the recommended Eclipse plugins I was able to use my STM32VLDISCOVERY on Ubuntu.
As recommended I've combined the eclipse template with the same author's libstm32pp C++ template library for STM32 hardware. libstm32pp provides a surprisingly complete replacement for CMSIS and the often criticized STM32 drivers with a programming model that lets you say things like
PINB::setHigh() all mostly compiled inline due to the C++ templates. The setup is very nice.
Here is a small but innovative template project for the quick start using STM32F0 Discovery board under Linux or any other OS:
Note that the project uses ChibiOS - a free and open source real time operating system so it's not exactly a bare bone implementation from scratch.
Consider platformio. If you're at all comfortable with the command-line, you'll find that platformio eases the development process considerably.
pio init can be used to set up a project.
pio run leverages the toolchain to compile.
pio run --target upload sends the code to the device. Platformio takes care of downloading the toolchain components, libraries, etc. as needed.