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?
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?
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).
Edit: if you want to get started really quickly you could also look at http://www.espruino.com. It's a JavaScript interpreter that runs on the STM32 itself, so once you've got 'stlink' installed so you can flash to the board you can just download an image from that site, flash it on, and then connect with a terminal application and start programming.
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.
Enjoy
Eclipse, GCC, and OpenOCD is one toolchain. It's recommended by EMCU-IT and there's additional information here. Those pages also recommend using an RTOS like FreeRTOS.org, but that's up to you.
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
make CROSS_COMPILE=/path/to/arm-2011.03/bin/arm-none-eabi-
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 PB10::setMode(gpio::cr::GP_OPEN_DRAIN_2MHZ)
and PINB::setLow()
or PINB::setHigh()
all mostly compiled inline due to the C++ templates. The setup is very nice.
Maybe it would be useful for someone: my short article (on russian) and simple project. All in linux and without unnecessary things like eclipse.
Libraries was taken from ST website, makefile — from one of many GPL examples in internet.
Here is a small but innovative template project for the quick start using STM32F0 Discovery board under Linux or any other OS:
https://github.com/dobromyslov/stm32f0-chibios-template
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.
I use vim and arm-none-eabi-gcc along with all the usual linux dev tools. Linux is in my opinion superior dev environment for embedded work by far. For debugging I use stlink and arm-none-eabi-gdb.
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.