This guide will compile OpenOCD 0.4.0 on Windows XP 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.
Download and install Cygwin 1.7.8-1 from http://www.cygwin.com. 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 http://cygwin.com/install.html.
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 automake gcc-core gcc-g++ libtool libusb-1.0 libusb-win32 libusb-devel make
Cygwin Changes May 2011
Until June 1, 2011, Cygwin is undergoing changes to improve its support for Windows cross-compilation. If you have downloaded or updated Cygwin since May 1, 2011, you will need to make some changes to make the GCC C compiler support the -mno-cygwin flag. If you last updated Cygwin before May 1, 2011 or after June 1, 2011, you should skip this section.
Open the Cygwin command line interface. The default Cygwin install places a shortcut in Start Menu > All Programs > Cygwin > Cygwin Bash Shell. Navigate to /usr/i686-pc-mingw32/lib.
That directory contains several symbolic links. Redirect them by typing the following. Hit Return after typing each line. The loop will not execute until you type the last line and hit Return. Be sure to include the trailing period at the end of the third line.
for f in *.o ; do rm -f $f ln -fs /usr/lib/mingw/$f . done
If you do not do this, every time you try to compile with the -mno-cygwin flag you will see this error:
configure: error: C compiler cannot create executables
For more information and alternative solutions, see this article: http://cygwin.com/ml/cygwin-announce/2011-04/msg00015.html. Refer to this more in-depth article if you see the above error.
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-18.104.22.168 from http://sourceforge.net/projects/libusb-win32/files/libusb-win32-releases/22.214.171.124/libusb-win32-bin-126.96.36.199.zip/download. Open the zip archive and extract the contents to C:\cygwin\home.
Navigate to the folder \libusb-win32-bin-188.8.131.52\lib\gcc. Copy the file libusb.a to C:\cygwin\lib and C:\cygwin\lib\mingw.
Navigate to \libusb-win32-bin-184.108.40.206\include. Copy the file usb.h to C:\cygwin\usr\include and C:\cygwin\usr\include\mingw.
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-220.127.116.11\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 a .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). If the install is successful, you will see two new devices listed in the Device Manager (Control Panel > System > Hardware tab > Device Manager) under the heading "libusb-win32 devices" labeled Flyswatter (Interface 0) and Flyswatter (Interface 1).
Downloading and Editing libFTDI
libFTDI is an open source FTDI driver you will need to compile OpenOCD. Download libftdi-0.18 from http://www.intra2net.com/en/developer/libftdi/download.php, and extract it to C:\cygwin\home.
Navigate to \libftdi-0.18\src and open the file ftdi.c in a text editor. Find the line reading:
(This line should appear only once in the file.) Delete the two underscores following __WIN32, so that the line reads:
Without this change, libFTDI OpenOCD will compile but will be unable to interact with the Flyswatter.
Compiling and Installing libFTDI
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. In the Cygwin command line navigate to the folder where you extracted the libFTDI source.
Compile with the following commands. Run the first and wait for it to finish, then run the next, and so on:
./configure make make install
In Cygwin or Windows Explorer, navigate to C:\cygwin\home\libftdi-0.18\src\.libs, find the file libftdi.a, and copy it to C:\cygwin\lib.
Now compile libFTDI again, but this time compile it to run without Cygwin.
cd /home/libftdi-0.18 make distclean ./configure CC="gcc-3 -mno-cygwin -L/usr/lib/mingw -L/usr/lib/w32api -I/usr/include/mingw -I/usr/include/w32api" make make install
Go to C:\cygwin\home\libftdi-0.18\src\.libs again, and copy the new libftdi.a to C:\cygwin\lib\mingw. Then go to C:\cygwin\home\libftdi-0.18\src, find the file ftdi.h and copy it to C:\cygwin\usr\include\mingw.
Cygwin Changes May 2011, Part 2
Remember the symbolic links you created before? If your most recent Cygwin update was between May 1 and June 1, 2011, you will need to create an additional symbolic link to libftdi.a. Navigate to /usr/i686-pc-mingw32 and create the link now. (If you most recently updated Cygwin before May 1 or after June 1, 2011, you can skip this step.)
cd /usr/i686-pc-mingw32/lib ln -s /usr/lib/mingw/libftdi.a .
Download the OpenOCD 0.4.0 source from http://prdownload.berlios.de/openocd/openocd-0.4.0.zip and extract it to C:\cygwin\home\openocd-0.4.0. In the Cygwin command line interface, navigate to your openocd-0.4.0 directory.
Compile OpenOCD with the following commands:
./configure --disable-werror --enable-ft2232_libftdi CC="gcc-3 -mno-cygwin -L/usr/lib/mingw -L/usr/lib/w32api -I/usr/include/mingw -I/usr/include/w32api"
(Type the above all in one line.)
make make install
Preparing to Run OpenOCD
Navigate to C:\cygwin\home\openocd-0.4.0\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-0.4.0\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.
In another Windows Explorer window, open C:\cygwin\home\openocd-0.4.0\tcl. Click and drag to select all the contents of the folder. Right-click on any file and select Copy. Open C:\openocd, right-click anywhere, and select Paste.
Now go to C:\cygwin\home\openocd-0.4.0\src and copy openocd.exe to C:\openocd. The folder should now contain the following files and folders:
board chip cpld cpu openocd.exe interface target test bitsbytes.tcl memory.tcl mmr_helpers.tcl readable.tcl
Installing LibUSB Device Filters
If the configure command above halts with an error stating that it is unable to compile and run a test program, or if openocd.exe compiles successfully but cannot open the FTDI device, you may need to install a libusb Device Filter.