Difference between revisions of "Compiling OpenOCD for Windows 7 (LibFTDI) - Pre June 2011"

From eLinux.org
Jump to: navigation, search
(Porting TinCanTools wiki content.)
(Adding proper categories)
Line 156: Line 156:
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]].
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]].

Latest revision as of 03:10, 18 April 2012

This guide will compile OpenOCD 0.4.0 for Windows 7 with the libFTDI 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.

Installing Cygwin

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.

Installing Cygwin Packages

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


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.

cd /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 .

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- from http://sourceforge.net/projects/libusb-win32/files/libusb-win32-releases/ 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\lib\mingw.

Navigate to \libusb-win32-bin-\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. 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 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 > View By: Small Icons > System > 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.

Editing ftdi.c

Navigate to \libftdi-0.18\src and open the file ftdi.c in a text editor. Find the line reading:

#ifdef __WIN32__

(This line should appear only once in the file.) Delete the two underscores following __WIN32, so that the line reads:

#ifdef __WIN32

Without this change, 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.

cd /home/libftdi-0.18

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

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

Compiling OpenOCD

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.

cd /home/openocd-0.4.0

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 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:


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

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.