FTDI FT2232 MPSSE Basics

I started a project working on interfacing with the Future Technology Devices International Ltd. (FTDI) USB FT2232H Mini Module via their D2XX device driver.  This device hooks up to a computer through a standard USB port and has a series of pins that can be used to interface with JTAG, I2C, and whatever serial like protocol you want.  I had been using the Application Note AN_135 FTDI MPSSE Basics provided by the manufacturer and noticed that their Example Program (Chapter 5), which is very good, was not available for download, but only printed in pieces in their Application Note.  As I went through the Application Note, I was writing out the example along with their comments and had a few minor corrections to get it working in a Linux environment.

I am making my transcription of the Example Program and corrections available on GitHub below.

I made the following edits to package up their example for a C environment on Linux - specifically Ubuntu 12.04.3 64 bit:

  • Rename the "Sleep()" function call to "sleep()"
  • Created a Makefile
  • Package up the required header files for compilation
  • #include the required headers in the source to use the libraries used in the example

Running the Code

To get it running on Linux use the following commands after you have installed the required drivers following the manufacturer Installation Guide for the D2XX Drivers.

Linux commands to run once you download the source from GitHub.

> sudo rmmod ftdi_sio
> sudo rmmod usbserial
> make clean
> make all
> sudo ./example

You will need to have a loopback between:

  • ADBUS1 - CN2-10 - TDI output
  • ADBUS2 - CN2-9 - TDO input

for it to pass along with the required power connections.  The connections for power need to be made before the PC will even see the module.  See FT2232H Mini Module Chapter 3 - USB Bus-powered.

  • VBUS to VCC - CN3-1 to CN3-3
  • V3V3 to VIO - CN2-1 to CN2-11 and CN2-3 to CN3-12

The remaining JTAG signals will be

  • ADBUS0- CN2-7 - TCK output
  • ADBUS3- CN2-12 - TMS output

Successful Run Transcript

> sudo ./example
StartChecking for FTDI devices...
2 FTDI devices found - the count includes\
individual ports on a single chip

Assume first device has the MPSSE and open it...

Configuring port for MPSSE use...
sleep(1)
sleep(1)
Press <Enter> to continue

sleep(2)
The correct number of bytes have been recieved
DEBUG BYTE NUMBER 0 INPUT: a5 OUTPUT: a5
DEBUG BYTE NUMBER 1 INPUT: 0f OUTPUT: 0f
The input data matches the output data
Press <Enter> to continue

Wired Circuit Picture

Picture of FT2232H Mini Module with Required Power and Loopback (Yellow) Connections

Known Problem with Example Code

There is an intermittent problem with the Example Code (Known Problem Transcript) that you might see.  It happens during a check in the code after it tries to load up the MPSSE configuration.

Sadly, I just have to keep running the executable until it doesn't have this error.  It could be a number of things such as I changed the sleep(50) to sleep(1) but going back to 50 seconds of waiting didn't seem to decrease the number of errors. It could also be that I am running Ubuntu within the Parallels Virtual Machine on Apple OSX.  The translation of an active usb device to a virtual machine might be causing problems.

If I find the source, I'll revise this post with the solution.

Known Problem Transcript

> sudo ./example
StartChecking for FTDI devices...
2 FTDI devices found - the count includes individual ports on a single chip

Assume first device has the MPSSE and open it...

Configuring port for MPSSE use...
sleep(1)
sleep(1)
Error - MPSSE receive buffer should be empty