STM32F0 discovery + GCC + Eclipse + OpenOCD + Ubuntu – Part II

  As promissed in last post, I’ll show you how to setup eclipse to work with the our STM32F0 discovery board + open source toolchain.
1) Open eclipse. First of all we need to install (if not already installed) two new software. So go to menu Help/Install New Software. In work with, type “” and in the list below choose CDT Optional Features/ C/C++ GDB Hardware Debugging”. Next in, select “GNU ARM C/C++ Development Support”.
  2) Create a new C Project. Go to menu File/New Project and select C/C++ – C Project. Click next.
  3) In next window Choose under ARM Cross Target Application – Empty project. Select your toolchain (Sourcery G++ Lite) or (GNUARM).
  4) Go to menu Project/Properties. In C/C++ Build / Settings select Tool settings. In Target Processor change “Processor” to cortex-m0.
  5) Now in the same Tool Settings tab go to ARM Sourcery Linux GCC C Compiler / Preprocessor and add the following values:
  6) Still in Tool Settings tab go to ARM Sourcery Linux GCC C Linker / General and  uncheck “Do not use standard start file (-nostartfiles) and check “Remove unused sections (-Xlinker –gc-sections). In Script file (-T) set path: /home/stm32/workspace/Template/src/stm32f0.ld
  7) In C/C++ General, select Path and Symbols and add the following paths (in both Assembly and GNU C):
  8) Configure GDB by clicking in the small arrow in the right of the bug. Select “Debug Configurations… “. Select “GDB Hardware Debugging” right click and select new. Change name to GDB-OpenOCD and in the bottom of the window click in “Select other…” and select “GDB (DSF) Hardware Debugging Launcher”.
 9) Under tab Debugger, uncheck everything and set the path of your gdb from your toolchain:  /home/user/stm32/gcc-arm-none-eabi/bin/arm-none-eabi-gdb
  10) Under tab Start Up, uncheck everything and in “Run commands” add:
target remote localhost:3333
monitor reset init
monitor stm_flash /home/user/stm32/workspace/Template/Debug/Template.elf
load /home/user/stm32/workspace/Template/Debug/Template.elf
symbol-file /home/user/stm32/workspace/Template/Debug/Template.elf
  11) Now configure OpenOCD by clicking in the small arrow in the right of the play with toolbox (external tools). Select “External Tool Configurations… “. Select “Program” right click and select new. Change name to OpenOCD. Set openocd path: /usr/bin/openocd and working directory: /home/user/stm32/openocd-0.6.0-rc1/tcl
  In “Arguments” write: -f /home/user/stm32/workspace/Template/extra/stm32f0discovery.cfg -f /home/user/stm32/workspace/Template/extra/stm32f0-openocd.cfg
  If everything is OK, compile your hello world program. Go to “External Tools” and select “OpenOCD”. It should show de following message in Console:
Open On-Chip Debugger 0.6.0-rc1 (2012-09-03-20:37)
Licensed under GNU GPL v2
  Now, the great moment, put a breakpoint in your main and select the bug icon “GDB – OpenOCD”. It should stop your code like this:
  That’s all for today!


Marcelo Jo

Marcelo Jo is an electronics engineer with 10+ years of experience in embedded system, postgraduate in computer networks and masters student in computer vision at Université Laval in Canada. He shares his knowledge in this blog when he is not enjoying his wonderful family – wife and 3 kids. Live couldn’t be better.


9 Responses to 'STM32F0 discovery + GCC + Eclipse + OpenOCD + Ubuntu – Part II'

  1. Roney Monte says:

    Hi, I’m used to PIC and AVR platforms (8 bits), and would like to try an know new ones, like the ARM MCUs and other. I would like to ask for some tricks, and if you can guide me in which platform is better to continue (or changing some paradigm)…

    If possible, contact me!
    Best Regards

  2. Marcin says:

    I’m sorry for delay, I had hardware problems and I couldn’t reply.
    In eclipse under tab Start Up, uncheck everything I have no in “Run commands”.
    Here I included screen:
    I think I should have something like this:

    I have no clue why it’s missing.
    Could You help me solove this problem?



    • marcelojo says:

      I sent you an email but didn’t receive any answer… Try use the eclipse version of the post and tell me which eclipse are you using.

  3. HanShane says:

    Hi, i have a stm32f10e-Eval board.. where do i get the ldscripts as mentioned in step 6.

  4. Alan – Thats the output of the compilation. Go through your build log, if the compilation actually succeeded you should have the elf file. (or just search for *.elf)

    I think the instruction, while detailed, missed the part where we add source files to the project. (I am new to Eclipse.. struggling to understand).

    Marcelo, great set of instructions. Now if only I could get the debugging to work..
    When I click the GDB button, I get a 'Launching GDB-OpenOCD' has encountered a problem. Program file does not exist'

    Maybe we could tempt you to create a video walk-through? 🙂

    • Marcelo Jo says:

      Yes, you're right! I should explain how to add add source files to the project!
      This error is because you configured not correctly the path to your gdb (from your toolchain). Check if your arm-none-eabi-gdb is in this path:

      or try to find where you have installed it!


  5. Great work. I have got the build to work but debugging fails. Template.elf is missing. How is Template.elf generated?

Leave a Reply to Ashish Uthama Cancel reply

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