Compiling OpenOCD Win7

Jump to: navigation, search

This guide will compile OpenOCD 0.5.0 on Windows 7 with the LibFTDI driver library, for use with the TinCanTools Flyswatter. The executable created with this guide is compatible with Windows XP and Windows 7. The process is identical on 32 and 64 bit versions of Windows.

This guide makes use of the GCC cross-compiler added to Cygwin on June 2, 2011. The cross-compiler makes compiling OpenOCD for Windows much easier. Older instructions can be found at Compiling OpenOCD for Windows 7 (LibFTDI) - Pre June 2011.

Configuring Windows 7

OpenOCD uses a command line interface and accepts commands from a telnet client. To compile and use OpenOCD in Windows 7 you will need to enable the 'Run' command and telnet client. See Configuring Windows 7 for OpenOCD.

Installing Cygwin

Download and install Cygwin 1.7.9 from Cygwin provides a GNU development environment for Windows, which will allow you to compile OpenOCD using the GNU Compiler Collection (GCC). You will not need Cygwin to run OpenOCD. The Cygwin installer is available at

Installing Cygwin Packages

If you already have Cygwin installed, this guide recommends that you delete it and reinstall completely. Close all Cygwin windows and services and delete your Cygwin directory (by default, C:\cygwin). Then find any packages downloaded but not installed and delete them as well. You set the location of these files when you installed Cygwin. By default they appear in My Documents/Downloads. If you don't wish to reinstall Cygwin you can find more information at

In the Cygwin installer you will be prompted to select additional packages to install. Install the following optional packages, found under the Devel heading:

  • autoconf (all packages)
  • automake (all packages)
  • binutils
  • gcc
  • gcc-core
  • gcc-g++
  • git
  • libtool
  • libusb-1.0
  • libusb-win32
  • libusb-devel
  • make
  • mingw-binutils
  • mingw-gcc
  • mingw-gcc-core
  • mingw-gcc-g++
  • mingw-pthreads
  • mingw-runtime
  • patch (found under the Utils heading)

Check all of these packages and click Next. Cygwin will inform you that it must install additional packages to satisfy the above packages' dependencies. Allow it to do so. Make sure that the Select Required Packages checkbox is checked before you proceed.

Installing libusb for the Flyswatter

Libusb is a usb driver library you will need to communicate with the Flyswatter. You will need a newer version of libusb than the one distributed through the Cygwin installer, and you will need libusb for Windows as well. Download libusb-win32- from Open the zip archive and extract the contents to C:\cygwin\home.

Navigate to the folder \libusb-win32-bin-\lib\gcc. Copy the file libusb.a to C:\cygwin\lib and C:\cygwin\usr\i686-pc-mingw32\sys-root\mingw\lib.

Navigate to \libusb-win32-bin-\include. Copy the file usb.h to C:\cygwin\usr\include and C:\cygwin\usr\i686-pc-mingw32\sys-root\mingw\include. Plug the Flyswatter into your computer's USB port. The Windows Found New Hardware Wizard will appear twice, once for each interface. Click Cancel both times.

In Windows Explorer or from the command line, navigate to \libusb-win32-bin-\bin and run inf-wizard.exe. Click Next from the first screen. You should see a menu with two devices, Flyswatter (Interface 1) and Flyswatter (Interface 0). Select Flyswatter (Interface 1) and click Next twice. You will be prompted to save an .inf file to your hard drive. Click Save. On the next screen, click Install Now. You may see a warning that the driver has not been digitally signed by Microsoft. Click Yes to install anyway.

Now repeat this process for Flyswatter (Interface 0). To see if the install was successful, open the Device Manager (Start Menu > Control Panel > View By: Category > System and Security > System > Device Manager). If the install is successful, you will see two new devices labeled Flyswatter (Interface 0) and Flyswatter (Interface 1).

You may also need to install a libusb Device Filter to use OpenOCD with the Flyswatter. Follow the instructions on the libusb Device Filter page before proceeding.


LibFTDI is an open source FTDI driver you will need to compile OpenOCD. Download libftdi-0.19.tar.gz from, and save it to C:\cygwin\home.

Open the Cygwin command line interface. The default installation will create a shortcut in your start menu, Start Menu > All Programs > Cygwin > Cygwin Bash Shell. Navigate to \home and extract libftdi using gzip:

cd /home
tar -zxvf libftdi-0.19.tar.gz

In the Cygwin command console navigate to the folder where you extracted the libFTDI source.

cd /home/libftdi-0.19

Compile with the following commands. Run the first and wait for it to finish, then run the next, and so on:

./configure --build=i686-pc-cygwin --host=i686-pc-mingw32

In Cygwin or Windows Explorer, navigate to C:\cygwin\home\libftdi-0.19\src. Find the file ftdi.h and copy it to C:\cygwin\usr\i686-pc-mingw32\sys-root\mingw\include. Then in C:\cygwin\home\libftdi-0.19\src\.libs, find the file libftdi.a, and copy it to C:\cygwin\usr\i686-pc-mingw32\sys-root\mingw\lib.

Downloading OpenOCD

Download the OpenOCD 0.5.0 source from and extract it to /home/openocd-0.5.0.

Patching OpenOCD

The OpenOCD Flyswatter2 beta patch provides support for the Flyswatter2 and updated config files for the original Flyswatter, the TinCanTools Hammer, and the Olimex PIC-P32MX board. Download the file Media:Tincantools-openocd-b0.12.patch. (Right click the link and select Save As.) Save the file to your new openocd-0.5.0 directory.

In the Cygwin console window, navigate to the patch file and patch the source as follows:

cd /home/openocd-0.5.0
patch -p1 -i Tincantools-openocd-b0.12.patch

Even if you do not need Flyswatter2 support, you will need the updated config files in this patch to use the Flyswatter with OpenOCD-0.5.0. If you do not wish to install the patch you can download the config files individually from OpenOCD Config Files.

Compiling OpenOCD

In the Cygwin command window, navigate to the new folder containing the OpenOCD source and compile as follows.

cd /home/openocd-0.5.0
./configure --disable-werror --enable-ft2232_libftdi --build=i686-pc-cygwin --host=i686-pc-mingw32

Preparing to Run OpenOCD

Navigate to C:\cygwin\home\openocd\src to find openocd.exe. The executable can be run from the Windows command line and does not require Cygwin.

You can run openocd from C:\cygwin\home\openocd\src, but you may encounter problems with configuration files. For a more in-depth discussion of these issues, see OpenOCD Config File Paths. This guide recommends that you create a new folder containing OpenOCD and its config files. Go to Start Menu > My Computer and open your C: drive. Right-click anywhere in the C: drive window and select New > Folder. Rename the new folder openocd-bin.

In another Windows Explorer window, open C:\cygwin\home\openocd\tcl. Click and drag to select all the contents of the folder. Right-click on any file and select Copy. Open C:\openocd-bin, right-click anywhere, and select Paste.

Now go to C:\cygwin\home\openocd\src and copy openocd.exe to C:\openocd-bin. The folder should now contain the following files and folders:


You can now run OpenOCD from C:\openocd-bin. To get started running OpenOCD, see Running OpenOCD on Windows.