Get started with the STM32F4 on Ubuntu Linux

Updated 2014-04-03

Introduction

This tutorial describes how to set up a complete and free toolchain for STM32F4xx microcontrollers, including how to use hardware floating point support. It is mostly aimed towards beginners with ARM microcontrollers, however, experienced developers could probably find something useful here as well. It is assumed that the reader is a bit familiar with the C programming language and the Bash terminal.

At the end of this tutorial, the reader should be able to build and upload programs to the STM32F4** using the STLinkV2 interface (such as the one found on the STM32F4 Discovery board). This is done using Ubuntu Linux in this tutorial, however, the instructions should be general enough to make this work on any Debian-based GNU/Linux distribution.

The following hardware/software will be used:

Firstly, a few packages have to be installed. Open a terminal and use the following command:

sudo apt-get install build-essential git flex bison libgmp3-dev libmpfr-dev libncurses5-dev libmpc-dev autoconf texinfo libtool libftdi-dev libusb-1.0-0-dev zlib1g zlib1g-dev python-yaml

Install a toolchain and OpenOcd

Follow the instructions at this location to install the toolchain:

https://launchpad.net/~terry.guo/+archive/gcc-arm-embedded

Build and install OpenOCD

git clone git://openocd.git.sourceforge.net/gitroot/openocd/openocd
cd openocd
./bootstrap
./configure --enable-maintainer-mode --disable-option-checking --disable-werror --prefix=${PREFIX} --enable-dummy --enable-usb_blaster_libftdi --enable-ep93xx --enable-at91rm9200 --enable-presto_libftdi --enable-usbprog --enable-jlink --enable-vsllink --enable-rlink --enable-stlink --enable-arm-jtag-ew
make
sudo make install

Alternative: Download and build GCC, GDB, OpenOCD and newlib

At this point you should be able to build all the required tools, for which the summon-arm script can be used. For me it didn’t work right out of the box, so I modified the script a bit. You can download the modified version here:

summon-arm-toolchain

Unzip the files to some directory and run the script:

cd PATH_TO_DOWNLOADED FILE
unzip summon-arm-toolchain.zip
cd summon-arm-toolchain
chmod +x summon-arm-toolchain
./summon-arm-toolchain

Wait for it to finish building (it will take a while).  While this is building, you can make sure that the tools are in you path by opening another terminal and typing (make sure to replace YOU_USER with your user name):

sudo su
echo 'export PATH=/home/YOUR_USER/sat/bin:$PATH' > /etc/profile.d/arm_tools.sh
exit

This should make sure that you can run the tools from any directory without the need to specify the full path. For the path update to take effect you have to log out and log in again.

I have experienced that the texinfo version included with Ubuntu 13.10 can cause problems when running the build script. In that case, downgrading it could help:

wget http://ftp.gnu.org/gnu/texinfo/texinfo-4.13a.tar.gz
tar -zxvf texinfo-4.13a.tar.gz
cd texinfo-4.13
./configure
make
sudo make install

After the downgrade, try running summon-arm-toolchain again and see if it works.

When the summon-arm script finishes, you should be able to build programs for the STM32F4 (and many other) microcontrollers and use hardware floating point support.

A simple example project

I have created a simple makefile project for the STM32F4 discovery board with a blinking LED, stdout (printf, etc) connected to UART2 and the system timer interrupt. A simple performance test for hardware floating point speed is also included. All of the latest ST standard peripheral libraries are included as well. You can download the project here: STM32F4_Sample

Just unzip the project and run make from the project root directory to build it:

cd PATH_TO_DOWNLOADED FILE
unzip STM32F4_Sample.zip
cd STM32F4_Sample
make

You should now have binary files in the build directory of the project.

If you connect the RX line of a 3.3V Usb-to-UART chip (115K 8n1) to PA2 you should be able to use a serial terminal to see the the stdout output (printf) from the application. This way you can print debug information, which can be very useful when dealing with peripherals.

Important: Do not connect any RS232 cable to these pins, as these voltage levels will damage the stm32f4. Use a 3.3V USB-to-UART converter.

You can also use the micro-usb port on the stm32f4-discovery if you follow the instructions in this post.

If you want to experiment with the hardware floating point support, look at this part in the makefile:

# Check for valid float argument
# NOTE that you have to run make clan after
# changing these as hardfloat and softfloat are not
# binary compatible
ifneq ($(FLOAT_TYPE), hard)
ifneq ($(FLOAT_TYPE), soft)
override FLOAT_TYPE = hard
#override FLOAT_TYPE = soft
endif
endif

Note that you have to run make clean after changing this before you build the project, as the libraries are not binary-compatible between hardfloat and softfloat builds.

Also note that you should use the 32-bit float version of the standard math libraries (sinf, powf, sqrtf etc, they have an f at the end) to take advantage of the hardware floating point unit. 64-bit double is not supported by the hardware.

Important: When using the Linaro-GCC version of the original summon-arm-toolchain script, 64-bit double will not work when using hardfloat (at least it did not for me). So the change to Linaro-GCC 2012-06 was necessary. But remember, as the hardware floating point unit does not support 64-bit double, those operations will be done in software; which is up to 100 times slower than using 32-bit float.

Using Eclipse for development

NOTE: Feel free to skip this section if you don’t plan to use Eclipse.

While any text editor and a command line is enough to develop for the STM32F4, an IDE is a lot more convenient. I personally like Eclipse as it is really useful with code-completion, source navigation, syntax checking etc.

If you don’t have java installed, install it with:

sudo apt-get install openjdk-7-jdk

Start by downloading Eclipse Classic from here. Unpack the archive and move it to /opt/ by typing the following in a terminal from where you have unpacked eclipse:

sudo mv eclipse /opt/

Now create a symbolic link to eclipse by typing

sudo ln -s /opt/eclipse/eclipse /usr/bin

You should be able to start eclipse from the terminal now by typing eclipse. You can also install alacarte (to add eclipse to the unity launcher, gnome menu etc.) by typing

sudo apt-get install alacarte

The next step is to install the GNU ARM plugin. Open eclipse from a terminal by typing eclipse and go to Help > Install new software. Add the following source

http://gnuarmeclipse.sourceforge.net/updates

and follow the steps to install it.

 Create a project in eclipse

Open eclipse and go to the workbench. Go to Window > Open Perspective > Other… and choose C/C++. Select File > New > C Project. Call the project STM32F4_Sample and choose Makefile project > Empty Project with the ARM Linux GCC (Summon) toolchain and click Finish.

Take the previously downloaded files and paste them into your Eclipse project. You can either paste the files directly into eclipse by right-clicking on the project and selecting paste, or you can paste them into your working directory using the file browser and then right-click on the project in eclipse and choose Refresh.

This project still uses the same makefile as before. The Eclipse ARM and CDT plugins can also handle the build for you, however, I prefer managing the makefile by myself as I know exactly what is going on this way.

You can build the project by right-clicking on it and selecting Build Project (which makes eclipse run make all). You can also clean the project by right-clicking on it and selecting Clean Project (which makes eclipse run make clean).

Upload the program to the STM32F4 discovery

In order to upload the binary files to the STM32F4 Discovery board I have been using a program called QSTLink2. I have modified the program a bit and added a button to upload the last uploaded file (which is pretty convenient) and fixed a few bugs in the cli interface. You can download the modified version here.

You have to build QSTLink2 from source in order to use it. First, install some dependencies:

sudo apt-get install qt4-qmake libqt4-dev libqt4-gui libqt4-xml qt4-designer qtcreator libusb-0.1-4 libusb-1.0-0-dev

Now unzip QSTLink2 to some directory and cd to it from a terminal. Then type:

qmake-qt4
make
sudo make install
sudo reload udev

Plug in your STM32F4 Discovery board. You should now be able to start QSTLink2 (./qstlink2), connect to the STM32F4 Discovery and upload the binary file which is generated in the build directory of the sample project when running make.

NOTE: I had some problems uploading files to other STM discovery boards based on Cortex M3 using QSTLink2. So if you have the same issue, give Texane STLink a try. Detailed instructions on how to use it can be found on the page where you download it.

Alternative: Upload the program using OpenOCD

From the build directory (where the .elf file is located) run:

openocd -f interface/stlink-v2.cfg -c "set WORKAREASIZE 0x2000" -f target/stm32f4x_stlink.cfg -c "program project.elf verify reset"

Replace project.elf with the name of your .elf file.

Debugging

I have written about hardware debugging by using eclipse and OpenOCD/gdb here.

75 thoughts on “Get started with the STM32F4 on Ubuntu Linux

  1. Thanks for your article to guide me
    this is a message from China, amazing internet
    I use keil for stm32, work in Ubuntu with it seems a bit hard to me
    hope more, and thank you again

  2. Upgraded from 11.10 to Ubuntu 12.04. Having some challenges. I ran the summon-arm-toolchain_modified and the following error appeared … need to get 0 B/2019 kb of Archives. Ubuntu 12.04 appears to be running fine and the error occurs while accessing the summon-arm-toolchain_modified script. ??

    • Sounds like something is wrong with your software repositories, but what you describe does not give enough information to determine exactly what the problem is. It could very well be related to the upgrade as they tend to mess with the software sources. I have tested this on Ubuntu 11.10, 12.04 and 12.10 recently and it seems to work fine every time.

    • I went out and purchased some new drives.Loaded Win 7 Home Premium Home Edition from scatch and dedicated my computer to Ubuntu 12.04. Now able to communicate to the kit successfully and flashed the demo program that you created. Have yet to get Eclipse to create the .bin in the build directory. Able to generate the binaries in the terminal using the make command. Would like to import the source code from the STM32F4 Discovery Demo Kit and run them. Tried importing the src code into the same format as your STM32F4_Sample program while utilizing the various directories (i.e build, inc, lib, src) and dumping the source code from the STM32F4 Discovery Demo Kit code into src. Not sure of what the necessary changes would be at this end to achieve this objective. I would really like to automate this process and start writing code can Eclipse do this or more scripts invovled ? I am learning as I go and I do not have a solid understanding on much of anything quite yet. I really appreciate the effort that you have put into this tutorial it has been helpful.

    • Maybe this wasn’t obvious, but what you have to to is to make sure that all your .c source files are listed at the beginning of the makefile. So what you have to do to add new files to the example project is:

      1. Add the .c files to the src directory and the .h files to the inc directory,

      2. Open the makefile and add the .c files to the SRCS variable in the beginning.

      Now you just have to run make to build the program. You can also have a look at my other posts with the usb cdc project and the mp3 player which have a bit different library structure, but steps 1 and 2 still apply. You could also just skip creating libraries of stdperiph and simply add all files to the same project, but I think doing it this way looks cleaner.

      Regarding running make from eclipse, if you have created the project as a makefile project, all you have to do is to right-click on it and select “Build Project” to run make or “Clean project” to run make clean.

      I hope this helps.

  3. In the code samples that you provided there are a lot of directories and subdirectories. As I understand it these structures are critcal to successfully loading and flashing a program. In putting together my first program I am unclear about how to go about this ? I surmise that you begin with creating a C program first, followed by generating .bin and .h files. Later using the command structure set of linux you then dump them into the appropiate directories and subdirectories while including the library files and some other files that I am not sure of ? At my end I am just starting out and I have a lot to learn. I am not even clear even about how to create .bin and .h files and know even less when it comes to the others. I believe that I need to become versed in the command structure of Linux to achieve my objective. Other news I have heard that GNU Arm Toolchain is the way to go and the summon_arm_toolchain needs to be tailoried to ones machine and can be really challenging if you are new at this. Although I have programmed using Microchip’s Assemblers this open source community is completely foriegn to me. Any insights that you can offer would be helpful including some other sites that you could direct me to.

    • The point of this tutorial is to set up the toolchain, and not the example project. My examples are just examples on how to use the toolchain and there are many other ways to set up a project. For a minimalistic example that works with this toolchain as well, see

      The Minimalistic Hello-World Program
      at http://www.triplespark.net/elec/pdev/arm/stm32.html

      However, if you want to use libraries for the peripheral units etc. you have have to include them in the build somehow, and my example project is one way to do it (and there are many other ways).

      If you want to learn about how my example project works, you can start with reading about makefiles. The makefiles are what manage the build process. When you run make, the makefile will be executed by the make program (and the main makefile will run the other makefiles). I have made a structure that builds the peripheral libraries from st from a separate makefile and includes them as libraries in the main makefile, but you could also, for instance, skip the whole directory structure and put the library .c and .h files together with your .c and .h files in one single directory and build that directly from the command line or with a single makefile (but this would look like a mess of files and possibly be more difficult to maintain).

      However, as I mentioned before, if you are happy with my directory structure: simply put your .c-files in the src directory of the project and the .h-files in the inc directory and add your .c-files to the beginning of the makefile (the SRCS variable) the same way as the other files are added. Then run make from the terminal (or from eclipse) to generate the .bin-file.

      By the way, if what you mean by “GNU Arm Toolchain” is this:
      http://www.gnuarm.com/
      then I suggest that you don’t use it. The GCC version is very old and lacks many features, such as floating point support for cortex m4. Linaro-GCC is the way to go, and the summon-arm script is one convenient way to set it up.

      I hope this helps.

      Edit: Just to make it clear, the .c and .h files are not enough to build a program, the linker script and the assembler startup code is also required. For smaller 8-bit and 16-bit microcontrollers (such as AVR) this is usually hidden behind the toolchain.

    • Thanks again for all your efforts they have meant a lot to me. The GNU arm toolchain comment was from a colleague at work whose boss has been doing some heavy development and encountered a number of problems using the summon arm toolchain. He was able to fix them from one computer to the next yet in the end he decided to enlist GNU. As I am not knowlegable in the subject I do not know the details. I only mention it in passing in case it crops up. Thanks again for you efforts. I did try earlier to transplant some code and I had a number of errors some of which were because of some ibraries that were missing others not sure of. Will try again with this new information.

    • Another thing I wanted to mention is that the summon_arm script is a way to download and build the latest versions of the GNU tools from source code, so it is still the GNU toolchain.

  4. Thank you very much for the excellent tutorial! I tried several other approaches to getting a toolchain and stlink set up, and yours is by far the best 😉

    Just a minor note on your modified summon-arm script – I found that it failed on libopencm3, since the sourceforge git repo is now empty. I fixed this by changing line 374 of the script to use the github repo:

    clone libopencm3 ${LIBOPENCM3_GIT} https://github.com/libopencm3/libopencm3.git

    This gave me an error about missing yaml, so I installed it:

    sudo apt-get install python-yaml

    After this, summon-arm completed and toolchain worked perfectly on your blinky example, as did sending an image with QSTLink2.

    I did wonder, would it be worth sending a patch to QSTLink2 to add your extra stuff?

    I really wish STM would link to some linux examples – until I found your tutorial I was starting to think that linux STM32 development would be painful, actually it seems pretty straightforward 😉 Maybe even a wiki somewhere with information like this would be a good start…

    • I’m glad the tutorial was useful for you :). Thank you for providing the fixes, I have added them to the script and updated the apt-get command in the tutorial.

      Maybe I should send to updates to the qstlink2 developers. Actually, I have already sent them code before which they added to the git repo right away (some GUI fixed), but I haven’t told them about these changes yet. The only difference between my version and the git version is the “send last file”-button which I think is really useful.

  5. Hi, thanks for the tutorial.
    I was having some issues with Fedora 17 for building the Qt GUI.
    You just to have make sure that you don’t have qt3-devel installed.
    yum erase qt3-devel
    Also you have to run a different command.
    qmake-qt4
    make

    One last thing, I am trying to automate the write process by using cli mode on your application. I had been using texane/ST-Link previously, but I had been getting freezing errors(usb locks up and doesn’t respond). Your app seems to be fairing a bit better, but this command doesn’t seem to work for me, but the gui will flash no problem.

    qstlink2 -cwV stm32f4_sample.bin
    or
    qstlink2 –cli –write –verify stm32f4_sample.bin
    In any case it erases the flash and then disconnects.
    Verbose level: 2
    Info: Could not open the devices.xml file. Using internal file.
    Info: Devices list loaded.
    Info: Found an ST Link V2.
    Info: Opening device…
    Info: Device Open.
    Info: ChipID: “413”
    Info: Device type: “STM32F4**”
    Info: Erasing flash… This might take some time.
    Info: Disconnected.

    • Hi,

      Just to make it clear, qstlink2 is not my application, I just updated it a bit.

      Regarding the problem with the cli interface, you are right about, there are a few bugs. The problem with your example is that you specify stm32f4_sample.bin and not ./stm32f4_sample.bin, which is not parsed the right way because of the missing /.

      I have fixed this bug (and many other cli bugs) and uploaded the program again. I will paste the link here for convenience:

      http://vedder.se/wp-content/uploads/2012/07/qstlink2.zip

      I have created a patch with all my updates to qstlink2 and will send them to the developer right now. Last time I sent him a fix he was very positive and added it right away, so I think he will apply this patch as well.

  6. Hi, I’m getting this error:

    gzip: stdin: decompression OK, trailing garbage ignored
    newlib-1.20.0/MAINTAINERS
    tar: Child returned status 2
    tar: Error is not recoverable: exiting now

    Any ideas?

    • Alright, so I just deleted everything, rebooted, started over and then it worked…

      A tiny remark, however: The file is not called “summon-arm-toolchain_modified.zip” but instead “summon-arm-toolchain-master.zip”

      Great tutorial, keep it up!

  7. Hi!
    I am getting following error:
    fatal: unable to connect to openocd.git.sourceforge.net:
    openocd.git.sourceforge.net[0: 216.34.181.91]: errno=Connection timed out

    ******************************************************************
    * Cloning oocd-master …
    ******************************************************************
    Cloning into ‘oocd-master’…
    fatal: unable to connect to openocd.git.sourceforge.net:
    openocd.git.sourceforge.net[0: 216.34.181.91]: errno=Connection timed out

    My internet connection is fine and I was able to go to openocd.git.sourceforge.net.

    Any help is appreciated.

    Thanks

  8. Hi! Just bought the stm32f4 discovery and found your site.

    I have a problem with the summon-arm-toolchain. AM_CONFIG_HEADER is depracated and AC_CONFIG_HEADERS should be used is the output I’m getting.

  9. It just worked! I was not expecting that to be nearly as easy as it was, thank you very much, brilliant tutorial

  10. Great tutorial,
    I just have few problems. Since I found some esden summon arm tool chain first I had installed it. I have installed eclipse and I can use the summon arm tool chain. The program builds and everything is fine but when I try to debug. It does not go to the correct line on start. Also If I single step it, the variable values are not what are expected and the sequence in the code is not followed. Can you help.
    I have used the o0 flag as suggested on some sites but it doesnt help.
    Can it be a problem with toolchain. I am a newbee to arm as well as linux.
    Regards,
    nd

  11. Hello,
    nice tutorial. I ‘m a little confused about eclipse. It build all files correctly and runs on STM32F4.

    But there a 2 Errors when building.
    Description Resource Path Location Type
    make: *** [src/main.o] Error 127 C/C++ Problem
    Program “arm-none-eabi-gcc” not found in PATH STM32F4_Sample [Discovery Options] page in project properties C/C++ Problem
    Description Resource Path Location Type
    make: *** [src/main.o] Error 127 C/C++ Problem
    Program “arm-none-eabi-gcc” not found in PATH STM32F4_Sample [Discovery Options] page in project properties C/C++ Problem

    Joerg

    • hi Joerg
      I had the same problem as you. for me the reason was that i forgot to change YOUR_USER to what my username actually was when adding the tools to the PATH

      you can easily check if this is the case by opening a terminal and write:
      printenv PATH

      this will probably show something like
      /home/YOUR_USER/sat/bin:/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games

      what you can do to easily fix this is write:
      gedit /etc/profile.d/arm_tools.sh

      as gedit opens, edit the content just by changing “YOUR_USER” to what your username actually is. (if you don’t know, open another terminal and write: whoami)

      as you corrected the misstake, save and close.
      now logg off and log on again. this should have solved your problem, it did for me

      /Mikael

  12. Benjamin,

    Thanks for all the great information you’ve shared. (I’m getting started with the STM32F4 Discovery and you’ve helped me a lot already). Now that the Summon-ARM-toolchain is no longer maintained, do you still prefer using it or have you moved to gcc-arm-embedded? What do you suggest for a beginner like me? 🙂

    Thanks,
    Philip

  13. Your tutorial is great 🙂 I tested it on Lubuntu 13.10 (64b), it works without problem.
    Thanks a lot.

    Jozef from Slovakia

  14. Hi,

    Thank you for this tutorial,great one! I almost lost faith in getting this thing working without having to work on Windows OS until I found your tutorial.
    Everything went ok until I wanted to compile directly using eclipse, the make command works fine using the Terminal, but once I compile the same project using eclipse it gives me this errors ( I suspect that eclipse is not using your Makefile, but I don’t know how to make eclipse use the this Makefile)
    **** Build of configuration Debug for project STM32F_sample ****

    make all
    Building file: ../src/main.c
    Invoking: ARM Linux GCC C Compiler (Summon)
    arm-none-eabi-gcc -O0 -ffunction-sections -fdata-sections -Wall -Wa,-adhlns=”src/main.o.lst” -c -fmessage-length=0 -MMD -MP -MF”src/main.d” -MT”src/main.d” -mcpu=cortex-m3 -mthumb -g3 -o “src/main.o” “../src/main.c”
    ../src/main.c:5:28: fatal error: stm32f4xx_conf.h: No such file or directory
    #include “stm32f4xx_conf.h”
    ^
    compilation terminated.
    make: *** [src/main.o] Error 1

    **** Build Finished ****

    Thanks in advance for your answer!!
    Bregards,
    Amjad

    • Hi Amjad,
      It seems like you didn’t create the eclipse project as a makefile project. Try to create a new project again and make sure that you choose a makefile project.

  15. Followed directions, but can’t install eclipse plugin (even reinstalled eclipse). Getting dependency error:
    Missing requirement: ilg.gnuarmeclipse.templates.core 1.1.0.201311101919 requires ‘bundle org.eclipse.cdt.managedbuilder.core 8.2.0’ but it could not be found

    • It actually also works without the plugin if you just make a makefile project. I will update the instructions some time soon.

    • Thanks. I”ll play around a bit more, maybe one of the C dev versions of Eclipse has this cdt better supported

  16. As maintainer of the GNU ARM Eclipse Plug-in, I’d like to inform you that since end of October 2013 there is a new version of the plug-in (v1.x), with many additional features (like multiple toolchains management, ARM Cortex-M project template, STM32F[134]x project templates and soon debugging support for SEGGER J-Link).

    Unfortunately this version requires some of the CDT features available only in CDT 8.2, packed with Eclipse 4.3 Kepler.

    More info on plug-in features an installation details are available from http://gnuarmeclipse.livius.net/blog/.

  17. Great tutorial. Thank you very much for that. I think i did every thing right but in eclipse, when i build the project i get this error.
    Description Resource Path Location Type
    Program “arm-none-eabi-gcc” not found in PATH STM32F4_Sample [Discovery Options] page in project properties C/C++ Problem

    http://img850.imageshack.us/img850/953/0wc2.png

    How can i get rid of this error?

    Burak

  18. Great tutorial.
    It worked flawlessly on Ubuntu 12.04, the only exception being the newlib2.0 download via the WGET command.
    That command failed consistently on the PORT command, so I downloaded the file using Firefox; after all the remaining build was successfull without human intervention.
    Same applies for the qstlink2 build: all in all, I was able to compile, load and run your test program.

  19. Pingback: A custom BLDC motor controller | Benjamin's robotics

  20. Thanks for all your work putting up this information. I’m still struggling a bit with qstlink2 on my 12.04 machine; see:

    administrator@vm-precise:~/STM32F4_Sample/build$ qstlink2 -ecwV ./stm32f4_sample.bin
    Verbose level: 2
    Info: Devices list loaded.
    Info: File Path: “./stm32f4_sample.bin”
    Info: Erasing: true
    Info: Writing: true
    Info: Found an ST Link V2.
    Info: Opening device…
    Info: Device Open.
    Info: ChipID: “423”
    Error: Device not found!

    Using texane/stlink allows a download, but then the code doesn’t appear to actually be executing. Anyhow, once I get this resolved, I’ll post back with more info. Thanks again for providing these examples and guides—it’s been extremely helpful.

    • Seems like the microcontroller is not connected. Make sure that you haven’t removed the swd jumpers from the discovery board. Also, the verify function of qstink2 does not work, so don’t use that flag.

      /Benjamin

  21. Thanks for a super useful tutorial and for all of the work to get this going. Saved me a lot of time. I have setup a gcc based arm tool chain a couple of years ago to use with the LPC3250. I was not happy with my result. Eventually I hired someone to clean up after me. I am a hardware guy with quite a bit of software experience, but not at all familiar with the ins and outs of a linux toolchain.

    I am not a bash expert, however I do think there is an error in one short bash command in which the /etc/profile.d/arm_tools.sh is created. The “>” shown in that script should actually be “>”. There is an posting on bitbucket that might be related to this:
    https://bitbucket.org/alexg/syntaxhighlighter/issue/25/bash-shell-script-double-escapes
    I gather it is a bug in some code somewhere and not something you did wrong.

    BTW it is not clear to me when and why the arm_tools.sh is executed.

    Thanks again.
    – Bill Den Beste

  22. Just posted about the arm_tools.sh creation. Note how I didn’t escape the ampersand g t semicolon in my email, which caused it to show up as a less-than symbol when my email was converted to text on your website! A similar but inverse conversion caused the error in your bash script perhaps.

    What a world we live in when clear communication requires mastery of html!

    – Bill

    • Thanks for pointing this out, I just fixed it. When I use the “text” editor in WP it usually turns out correctly in the post, but when I edit the post with the visual editor, some symbols will become corrupt. I hope they fix this issue soon.

    • By the way, that command is executed so that the arm-none-eabi-* tools are in the path so you can use them from the command line or from scripts without specifying their location on the file system. This is a bit more convenient.

  23. Hi. I have a question. I have a preety stable computer with an unsupported version of ubuntu (12.10). Will it work if I put the ubuntu 12.04 in a VirtualBox VM running inside ubuntu 12.10?

    Thanks for the help

    • Hi,
      It will work if you use the alternative method. If you just add the ppa for another version of Ubuntu, e.g. 12.04, it will also probably work.
      /Benjamin

  24. Thank you for your great tutorial! I’ve set up it on Ubuntu 12.04 LTS and on a Ubuntu 13.1 – both works!
    But I’ve got a problem – with eclipse i tried to create a c++ project using the template:

    -> NEW C++ Project – “STM32F4xx StdPeriph C/C++ Project” – …. it compiles without a problem but if i upload it to my STM32F4 Discovery it just do… nothing. With the C Template its working… even if i use the same sourcecode just compile it with the c++ tool it does NOTHING…
    http://nopaste.info/9acf27ad8c.html

    • Hi Wolfgang,

      The problem you noticed with the STM32F4 template was fixed in the latest release. Please upgrade and if you have further problems, please enter tickets in the SourceForge tracking system.

      Regards,

      Liviu

  25. Pingback: ChibiOS on my cc2520+stm32f4 boards | Benjamin's robotics

  26. I’ve had a problem with cd PATH_TO_DOWNLOADED FILE…. (step 2). My terminal said bash: cd: PATH_TO_DOWNLOADED: No such file or directory. How can i fix this.

  27. Hey, I have a problem
    I did everythink from your tutorial. Finally compilling correctly. But I have problem with QSTLink.
    When I’m opening it and click “Connect”, I get this message:
    Searching Device…
    ST Link V2 not found or unable to access it.
    Did you install the udev rules ?
    USB error: -2
    Can you help me?

    • I have the same problem… installed all as descibed above except Eclipse Plugin and except OpenOCD (still compiling an hour later). I am also running on a VirtualBox to make it simpler. I installed the vedder-modified version of qstlink2

      It seems from your messge below that the “Not found” problem is solved by calling qstlink2 with sudo… that do not help for me.

  28. WHen I’m running as sudo, I have following error:
    Searching Device…
    ST Link V2 found!
    Fetching version…
    Changing mode to SWD…
    Fetching mode…
    Mode: Debug
    Fetching status…
    Status: Core Running
    Fetching MCU Info…
    Device not found in database!

  29. summon-arm-toolchain can take a while :more than 4 hours on a few years old decent PC through a VirtualBox

    New issue when building oocd:
    {{{
    configure: error: The ft2232 driver is deprecated, use –enable-ftdi to build its replacement, or force the old driver with –enable-legacy-ft2232_libftdi
    }}}

    This can be fixed by editing the occd configure option within summon-arm-toolchain script and call that one again (it won’t redo everything that succeeded earlier)

    • It doesn’t work… I tried adding –enable-ftdi and later the legacy one in the script but the output doesnt change.

  30. Pingback: Getting Started with the STM32F4 and GCC

  31. Pingback: Found another great tutorial for STM32 | Adi's Blog

  32. Hi,

    Everytime I try to flash my stm32f3 discovery from eclipse using the external tools, I keep getting this error:

    Verbose level: 2
    Error: Failed to lock flash!
    Info: Devices list loaded.
    Info: File Path: “/home/adi/workspace/test_lagi/Release/test_lagi.bin”
    Info: Erasing: false
    Info: Writing: true
    Info: Found an ST Link V2.
    Info: Opening device…
    Info: Device Open.
    Info: ChipID: “422”
    Info: Device type: “STM32F30*”
    Info: Verify not yet implemented.
    Info: Writing from “8000000” to “8001c50”
    Info: Progress: “1%”
    Info: Progress: “3%”
    Info: Progress: “5%”
    Info: Progress: “7%”
    Info: Progress: “8%”
    Info: Progress: “10%”
    Info: Progress: “12%”
    Info: Progress: “14%”
    Info: Progress: “15%”
    Info: Progress: “17%”
    Info: Progress: “19%”
    Info: Progress: “21%”
    Info: Progress: “22%”
    Info: Progress: “24%”
    Info: Progress: “26%”
    Info: Progress: “28%”
    Info: Progress: “30%”
    Info: Progress: “31%”
    Info: Progress: “33%”
    Info: Progress: “35%”
    Info: Progress: “37%”
    Info: Progress: “38%”
    Info: Progress: “40%”
    Info: Progress: “42%”
    Info: Progress: “44%”
    Info: Progress: “45%”
    Info: Progress: “47%”
    Info: Progress: “49%”
    Info: Progress: “51%”
    Info: Progress: “52%”
    Info: Progress: “54%”
    Info: Progress: “56%”
    Info: Progress: “58%”
    Info: Progress: “60%”
    Info: Progress: “61%”
    Info: Progress: “63%”
    Info: Progress: “65%”
    Info: Progress: “67%”
    Info: Progress: “68%”
    Info: Progress: “70%”
    Info: Progress: “72%”
    Info: Progress: “74%”
    Info: Progress: “75%”
    Info: Progress: “77%”
    Info: Progress: “79%”
    Info: Progress: “81%”
    Info: Progress: “83%”
    Info: Progress: “84%”
    Info: Progress: “86%”
    Info: Progress: “88%”
    Info: Progress: “90%”
    Info: Progress: “91%”
    Info: Progress: “93%”
    Info: Progress: “95%”
    Info: Progress: “97%”
    Info: Progress: “98%”
    Info: Transfer done
    Info: Disconnected.

    my external tool configuration is (test_lagi is my project name):
    Location: /usr/bin/qstlink2
    Working directory: ${workspace_loc:/test_lagi/Release}
    Arguments: -cwV ${workspace_loc:/test_lagi/Release}/test_lagi.bin

    I tried to change the arguments into following:
    -cwV ./test_lagi.bin (did’nt work)
    –cli –write –verify ./test_lagi.bin (also did’nt work)

    Do you know what goes wrong?

    • Hi,
      Recently I haven’t used qstlink anymore, I have used openOCD with the command that I listed at the end (with an upload rule in the makefile). You can give that a try.

  33. Pingback: USB host and MP3 player on STM32F4 Discovery board | STM32Geek

  34. Benjamin,

    I have been using GNU gdb (GDB) 7.6.1-ubuntu, gcc-arm-none-eabi 4-8-2014q1-0saucy8 and st-link v2 for the STM32F2 development for about te months. This week it is my 1st time of using qstlin2. Thanks for your qstlink2 tutorial! It is more useful than the st-link v2 command lines.

    With my STM32F0discovery board USB-connected to my Ubunt-14.04 Laptop, the qstlink2->Connect action cannot find the board. You probably know the reason for the STM32F0discovery board detection failure. I replaced the board with my production STM32F2 board. The same action detects the STM32F2 board with no problems.

    The other issue is the logging capability. It seems to me there are no such capability in the Linux environment but the Windows one.

    • I have actually been using openocd for uploading the code and debugging recently. It supports swd and works well with stlink v2. I have only tried qstlink with the stm32f4, so I don’t know how it works with other STMs.

  35. Pingback: ARM assembly IDE for Linux (compiler, debugger, assembly view …) - DL-UAT

  36. Hi Benjamin,

    I’m just starting to get into stm32f4 development on Kubuntu 14.04. Working through your tutorial, I completed the first step (downloading various packages) without any problem. However, when I tried to get openocd from git, the system displayed the following.

    kub@kub-PM800-8237:~$ git clone git://openocd.git.sourceforge.net/gitroot/openocd/openocd
    Cloning into ‘openocd’…
    fatal: unable to connect to openocd.git.sourceforge.net:
    openocd.git.sourceforge.net[0: 216.34.181.91]: errno=Connection refused

    Could you please explain why this may have happened and suggest a possible way forward.

    Thanks in advance for any help that you may be able to give with this.

    Best regards,

    Stuart

    • Hi Benjamin,

      I was unaware that I had to set up an account with GitHub in order to clone the OpenOCD git tree. Setting up a free account with GitHub allowed OpenOCD to be successfully cloned from GitHub.

      Stuart

  37. Hi Benjamin,

    I’ve made a second attempt to get this toolchain installed. I’ve gotten half a step further. This time I’m getting errors at the OpenOCD set up step. On issuing the command ./bootstrap in the openocd directory, the system displays the following.

    kub@kub-PM800-8237:~/openocd$ ./bootstrap
    + aclocal
    + libtoolize –automake –copy
    + autoconf
    configure.ac:12: error: possibly undefined macro: AC_MSG_WARN
    If this token and others are legitimate, please use m4_pattern_allow.
    See the Autoconf documentation.
    configure.ac:240: error: possibly undefined macro: AC_MSG_NOTICE
    configure.ac:342: error: possibly undefined macro: AC_DEFINE

    Can you please suggest why this has happened and possibly suggest a remedy ?

    Thanks in advance,

    Stuart

    • Hi Stuart,

      Sorry for not replying earlier. For ubuntu 14.04, openocd from the repositories works fine. Just run:

      sudo apt-get install openocd

    • Hi Benjamin,

      Further investigation showed that the system was missing the pkg-config package. With this installed, OpenOCD was successfully built and installed.

      Stuart

  38. cd build
    log “Configuring openocd-${OOCD}”
    CFLAGS=”${CFLAGS} ${OOCD_CFLAGS}” \
    LDFLAGS=”${LDFLAGS} ${OOCD_LDFLAGS}” \
    ../${OOCD}/configure –enable-maintainer-mode \
    –disable-option-checking \
    –disable-werror \
    –prefix=${PREFIX} \
    –enable-dummy \

    –enable-ft2232_libftdi \

    # –enable-legacy-ft2232_libftdi\
    # –enable-ftdi \
    what i have to change in this summon tool chain script
    i have chage it but the error not cleard

  39. Hi Benjamin,

    Your code worked like charm for me. Great tutorial (only one that worked for me) .

    I am trying to put uClinux on my sstm32f429I-discovery board now but unable to build it. I tried lots of different ways but couldn’t. I hope you can suggest some efficient way of doing it. I am using arm-linuxgnueabi toolchain.

    Thanks.

  40. Thanks for this. I was struggling with programming my Discovery STM32F on my Linux system until I read this page. I compiled and installed your version of QSTLink2. Thanks again!!

  41. Thanks for such a good support, but i am a new linux user as i want to debug STM32 via USB-MP3. i tried on windows but couldn’t get the result.
    i found your tutorial and now facing some problems.
    as mentioned above , i have tried the same procedure till the installation of summon_arm_toolchain. when i run the
    ” ./configure –enable-maintainer-mode –disable-option-checking –disable-werror –prefix=${PREFIX} –enable-dummy –enable-usb_blaster_libftdi –enable-ep93xx –enable-at91rm9200 –enable-presto_libftdi –enable-usbprog –enable-jlink –enable-vsllink –enable-rlink –enable-stlink –enable-arm-jtag-ew ” command
    prior to the installation of toolchain and after that procedure when i run ./summon-arm-toolchain it gives the error:
    ” configure: error: The ft2232 driver is deprecated, use –enable-ftdi to build its replacement, or force the old driver with –enable-legacy-ft2232-ftdi “.
    please help me in sorting out that problem.
    thanks in advance

  42. hi benjamin
    thank you for your tutorial about this but ı tried almost everything. still having this error
    user@instant-contiki:~/Desktop/STM32F4_Sample$ make
    make -C lib FLOAT_TYPE=hard
    make[1]: Entering directory `/home/user/Desktop/STM32F4_Sample/lib’
    ~/sat/bin/arm-none-eabi-gcc -g -O2 -Wall -mlittle-endian -mthumb -mthumb-interwork -mcpu=cortex-m4 -fsingle-precision-constant -Wdouble-promotion -mfpu=fpv4-sp-d16 -mfloat-abi=hard -ffreestanding -nostdlib -Iinc -Iinc/core -Iinc/peripherals -c -o misc.o src/peripherals/misc.c
    /bin/sh: 1: /home/user/sat/bin/arm-none-eabi-gcc: not found
    make[1]: *** [misc.o] Error 127
    make[1]: Leaving directory `/home/user/Desktop/STM32F4_Sample/lib’
    make: *** [lib] Error 2

  43. You should check out this project, it’s a simple command-line tool that automates the creation of STM32 projects. You just need to fire up a terminal and write a command to have a new STM32 project up and running with CMSIS, linker scripts, startup files and HAL libraries already configured and included. Then you can use your favourite editor/IDE to edit your code and this tool again to flash it on the board
    https://github.com/gdelazzari/STM32Tool

  44. Hi. I have problem about OpenOCD.
    making .bin file is finished, but I cannot download program by OpenOCD.

    =====================This is Command====================
    ——–@ubuntu:~/Downloads/bldc-master/build$ openocd -f interface/stlink-v2.cfg -c “set WORKAREASIZE 0x2000” -f target/stm32f4x_stlink.cfg -c “program BLDC_4_ChibiOS.elf verify reset”

    ===============this is Error Message ==================
    Open On-Chip Debugger 0.10.0-dev-00329-gf19ac83-dirty (2016-07-24-21:17)
    Licensed under GNU GPL v2
    For bug reports, read
    http://openocd.org/doc/doxygen/bugs.html
    0x2000
    WARNING: target/stm32f4x_stlink.cfg is deprecated, please switch to target/stm32f4x.cfg
    Info : auto-selecting first available session transport “hla_swd”. To override use ‘transport select ‘.
    Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
    adapter speed: 2000 kHz
    adapter_nsrst_delay: 100
    none separate
    Info : Unable to match requested speed 2000 kHz, using 1800 kHz
    Info : Unable to match requested speed 2000 kHz, using 1800 kHz
    Info : clock speed 1800 kHz
    Error: open failed
    in procedure ‘program’
    in procedure ‘init’ called at file “embedded:startup.tcl”, line 473
    in procedure ‘ocd_bouncer’
    ** OpenOCD init failed **
    shutdown command invoked

    ==============================================

    How I can solve this problem??
    Thank you!!

Leave a Reply

Your email address will not be published. Required fields are marked *

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