STM32F3Discovery on Mac OS X using Eclipse, GCC ARM and OpenOCD

A few months ago I received an STM32F3DISCOVERY evaluation board, similar to the STM32F4DISCOVERY that I’ve used for prototyping at work, but for the new STM32 F3 series Cortex-M4. Since ST doesn’t provide a development environment like TI and NXP do, and the commercial packages available are expensive and windows only, I’ve decided to put up a step-by-step tutorial on how to setup an opensource environment for Mac OS X based on eclipse, GCC ARM and openOCD.

All the packages are multi-platform, so it should be easy to configure a similar environment for Linux or Windows.

Download and Install the GCC ARM toolchain, Eclipse IDE + plugins and OpenOCD

GNU Tools for ARM Embedded Processors

The first thing you need is a toolchain. The GCC ARM is maintained by ARM employees, and is the best open source compiler you can find. It includes the debugger GDB. Download the mac installation tarball of the 4.7 series release and uncompress it in your home folder, no installation needed.

Eclipse IDE

A lot of the closed source IDE used in ARM development are heavily based on the Eclipse IDE. Download the last version (currently Kepler) of the Eclipse IDE for C/C++ Developers package, selecting the Mac OS X 64 Bit version, and uncompress it in your home or applications folder.

Now open Eclipse and install the plugins needed: Eclipse CDT, GNU ARM and Zylin embedded CDT.

Go to Help > Install New Software. Click on the “Available software sites”, select the CDT checkbox and click OK.


Select CDT from the Work with: dropdown and the packages will appear below. Click all the CDT Main Features and from the CDT Optional Features the ones that are selected in the following image.


Click Finish and the plugins will download and install.

Next we will install the GNU ARM plugin. Click again on Help > Install New Software and now click on the Add… button next to the top dropdown, to add a new repository. Insert the location and click OK. The component “CDT GNU Cross Development Tools” will appear below. Select and install it.


Finally, repeat the process to install the Zylin Embedded CDT plugin, necessary to debug and flash. Add the repository with the location and install the component “Zylin Embedded CDT”.


OpenOCD is an open on-chip debugger and progamming tool. It will communicate with gdb to debug and flash the board by using the stlinkv2 debugger. The easiest way to install it is using Homebrew, a pacakage manager for OS X similar to MacPorts or Fink. If you don’t use Homebrew already, follow the one-step installation instructions on its website. After that, open a Terminal and paste the following line:

brew install openocd --enable_ft2232_libftdi --enable_stlink
Once installed, you have to create an empty file called stm32f3discovery.cfg in your home folder, and paste the following lines:
# Script for connecting with the STM32F3DISCOVERY board 
source [find interface/stlink-v2.cfg] 
source [find target/stm32f3x_stlink.cfg] 
reset_config srst_only srst_nogate
 To be able to run OpenOCD inside Eclipse, you have to add it clicking in the menu Run > External Tools > External Tools Configuration…. Create a new item clicking in the New launch configurationicon and fill in the location, working directory and arguments as in the following image and clickApply. The working directory will be where you created the stm32f3discovery.cfg file.


Now connect your STM32F3DISCOVERY board to the computer and click the Run button. If everything is correct, you will see in the console something similar to this:

Info : This adapter doesnt support configurable speed
Info : STLINK v2 JTAG v16 API v2 SWIM v0 VID 0x0483 PID 0x3748
Info : Target voltage: 2.892453
Info : stm32f3x.cpu: hardware has 6 breakpoints, 4 watchpoints
Every time you start Eclipse, you will need to start OpenOCD with Run > External Tools > OpenOCD. When you exit Eclipse, it will kill the OpenOCD daemon. If for some reason it is still running, paste in a Terminal the command killall openocd.

Creating a new project

After installing all the packages, we are going to create a blinking led example project.

First, click on File > New > C Project and select Executable > STM32F3xx StdPeriph Lib v1.0 C Projectand Cross ARM GCC. Give it a name, for example Bliking_STM32F3.


Click Next several times, leaving the default options, until you reach the last step, where you select the toolchain name and path, as you can see in the image. You will have to browse for the path of thebin folder where you installed the GCC ARM Toolchain.


Click Finish and the project will be created.


For now, you can leave the example code as is, but you need to comment the printf lines, since OpenOCD doesn’t seem to support retargeting for this board at the moment.

Another thing we should do is enable the FPU unit, that is disabled by default. Go to Project > Properties and select C/C++ > Settings on the left tree. In the Tool Settings, click on the Target Processor item. On the right dropdowns, select the “FP instructions (hard)” option of the Float ABImenu, and “fpv4-sp-d16″ of the FPU Type and click OK.

After that, click on Project > Build Project. Now that the program is compiled, the only thing left is to add a debug configuration. Click on Run > Debug Configurations… and double-click on Zylin Embedded debug (Native). On the “Debugger” tab, click on the GDB debugger field and browse to select the gdb executable of the GCC ARM toolchain. It will be something likePATH_TO_GCC/bin/arm-none-eabi-gdb.


Finally, go to the “Commands” tab and paste this in the ‘Initialize’ commands box:

target extended-remote localhost:3333
monitor reset init
monitor reset halt


Click Apply and then Debug. The debugging session will start, Eclipse will switch to the Debug perspective and the program will be downloaded to flash. Then, when you click on the Resume (F8)icon, the program will start executing, stopping at main. Clicking again on Resume will continue the execution. If everything is configured correctly, you will see the green led flashing on your board. You can pause/stop the execution, set breakpoints and watch variables and registers.





  1. Hi, thank you for the write up….After successful installs, I am getting following error when I run openOCD external tool.
    I am using STM32F4Discovery board.

    Thanks in advance.

    Open On-Chip Debugger 0.8.0 (2015-04-17-13:03)
    Licensed under GNU GPL v2
    For bug reports, read
    srst_only separate srst_nogate srst_open_drain connect_deassert_srst
    Info : This adapter doesn’t support configurable speed
    Error: open failed
    in procedure ‘transport’
    in procedure ‘init’


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s