Saturday, September 8, 2012

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!



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

    1. Hello! Template.elf is generate by your compiler. Try to compile your code!

  2. 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? :)

    1. 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!


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

    1. Hello, sorry for the delay. I think your email went to spam!
      Please go to first post ( at step 6.

  4. Hello,
    I use Eclipse Indigo. I followed by yours tutorial, everything works, except step 10. I don't have any runtime options. Do you know what is wrong and how to fix it? I can not find any solution.

    Thank you in advance,

    1. Hello, which runtime options? In step 10 you should only configure to start GDB. Could you tell me what is the error?

  5. This comment has been removed by the author.

  6. This comment has been removed by the author.

    1. This comment has been removed by the author.