Compiling OpenOCD for Windows 7 (FTD2XX) - Pre June 2011
This guide is out of date. Because of the recent addition of a cross-compiler to Cygwin, these instructions apply only to a user with Cygwin already installed, and last updated before June 2, 2011. An up-to-date guide will be available soon. For an up-to-date guide to an alternative libFTDI build, see Compiling OpenOCD for Windows 7 (LibFTDI).
This guide will compile OpenOCD 0.4.0 for Windows 7 with the FTD2XX driver library, for use with the TinCanTools Flyswatter. The process is identical on 32 and 64 bit versions of Windows.
Configuring Windows 7
OpenOCD uses a command line interface and accepts commands from a telnet client. To use OpenOCD in Windows 7 you will need to enable the 'Run' command and telnet client. See Configuring Windows 7 for OpenOCD.
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 update 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.
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-126.96.36.199 from http://sourceforge.net/projects/libusb-win32/files/libusb-win32-releases/188.8.131.52/libusb-win32-bin-184.108.40.206.zip/download. Open the zip archive and extract the contents to C:\cygwin\home.
Navigate to the folder \libusb-win32-bin-220.127.116.11\lib\gcc. Copy the file libusb.a to C:\cygwin\lib and C:\cygwin\lib\mingw.
Navigate to \libusb-win32-bin-18.104.22.168\include. Copy the file usb.h to C:\cygwin\usr\include and C:\cygwin\usr\include\mingw.
Download version 2.08.14 of the D2XX Windows drivers from http://www.ftdichip.com/Drivers/D2XX.htm. Direct link is here: http://www.ftdichip.com/Drivers/CDM/CDM20814_WHQL_Certified.zip. Extract the contents to C:\cygwin\home\ftd2xx.
In Windows Explorer, open the ftd2xx folder and find the file ftd2xx.h. Copy this file to C:\cygwin\usr\include and C:\cygwin\usr\include\mingw.
Navigate to C:\cygwin\home\ftd2xx\i386 and find the file ftd2xx.lib. Copy it, rename the copy ftd2xx.a and move the new file to C:\cygwin\usr\local\lib.
Plug the Flyswatter into your computer's USB port. Install FTD2XX as follows:
- Open the Control Panel.
- If the View By dropdown menu in the upper right shows Category, change it to Large Icons or Small Icons.
- Click System.
- Click Device Manager on the left.
- Find the Flyswatter devices. There should be two of them.
- Right click the first Flyswatter device and select Update Driver Software.
- Choose Browse my computer for driver software.
- Click Browse.
- Navigate to C:/cygwin/home/ftd2xx.
- Click OK. The panel should now look like the screenshot to the right.
- Click Next and wait for the install to complete.
- Repeat the process for the other Flyswatter device.
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_ftd2xx --with-ftd2xx-win32-zipdir=../ftd2xx 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 one one line. Note that "../ftd2xx" is the path to your ftd2xx directory. You may need to change this argument if you extracted ftd2xx to a different location. You may use either a relative path, as above, or an absolute path, such as C:\cygwin\home\ftd2xx. The argument --with-ftd2xx-win32-zipdir should be used even on 64 bit Windows 7.
Finish compiling as follows:
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.