# How do I develop for STM32 discovery on Linux?

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 installed Codesourcery on LinuxhUbuntu and little bit stacked: PATH is ok but the program does not appear on dasboard or software centre. Maybe it is the Ubuntu I would change somehow but do not know how. If you have an idea, please write. Thank you. Tom – Tom Rert Mar 22 at 8:14 @TomRitzmann Comments like this that don't answer the question should be posted as a comment, or think about starting your own new question with details of the problem you're having. – PeterJ Mar 22 at 8:59 @TomRitzmann PeterJ is right, please don't use answers to ask questions. Moreover, software problems are off-topic here, SuperUser is the right place. – clabacchio♦ Mar 22 at 11:28

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 more popular)

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 newer versions of Ubuntu, there is a package you can install which contains an ARM compiler:

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


This will install the GCC compiler as 'arm-linux-gnueabi-gcc'

However if you do this you'll need to add the line '*(.note.gnu.build-id)' at the bottom of the '/DISCARD/' section of stm32_flash.ld (the linker script supplied with ST's examples) in order for the Ubuntu-packaged compiler to produce code that can be flashed and that works.

Also bear in mind that I have had no luck using the C/GCC standard libraries (which includes floating point routines). However installing the package is an awful lot easier than building GCC from source.

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

-

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-

-
Thanks! I hadn't seen those links before. I'm amazed there isn't a more definitive guide somewhere though as different discovery boards have subtly different build flags. – Gordon Williams May 31 '12 at 14:52
Yeah, ST made a very cheap board and gave them away, thousands of them, and the STM32 itself is an awesome chip, all the way up to F4, but programming them is a huge pain in the butt. Their drivers are incredibly poorly documented, and not named well, and finding a IDE and tool chain that play well together for free is not too easy. – hak8or May 31 '12 at 15:23

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.

-