Recently I was working on a small project for USB host of FTDI chips. The goal is to create a small application on a ARM Cortex-M microcontroller with USB interface which shall be the master/host of a FTDI chip. Since FTDI only delivers compiled drivers, it was quite hard to find any references this until I found the open source project libFTDI. libFTDI is based on another open source project called libusb and although per default both projects are intended for Linux operating System, there are already some ports for Windows operating system.
One of the libFTDI developer called Xiaofan posted recently his port of libFTDI for Windows. At first I was really confused how to make the libFTDI works since I tried to install libusb manually, and it took me several days to get it running. So for the sake of others, I am posting here what I did to make the libFTDI under windows.
For this project, a USB TTL FTDI cable is used as the USB slave on Windows XP 32 bit machine. If you are interested on the project with embedded microcontroller (I was using LM4F ARM Cortex-M4) as the host, please refer here.
Downloading libFTDI for Win32 and Installing libusbK Driver
Xiaofan posted his port of libFTDI which can be found here with the name of libftdi1-1.0_devkit_mingw32_17Feb2013.zip.
Before the FTDI cable can be used with libFTDI, it is necessary to overwrite the default FTDI driver. When you install the default FTDI driver, usually you can find the device listed as “USB Serial Port” under “Ports (COM & LPT)” under your Windows “Device Manager” as shown follows:
After reading the libFTDI cable, first I came to conclusion that I need to install libusb driver for the FTDI chip so that it can be used together with libFTDI. After trying for about two days, I still failed. But then I got a hint after reading the “Readme.txt” under “Driver” folder of the libFTDI package above which mentions to use Zadig software tool. So you can get the Zadig software from the following link, and I downloaded the latest version – at the moment of writing, it is zadig_v184.108.40.206.7z.
After finished downloading, just unpack the the 7z package with the help of 7zip, and run zadig.exe. Click “Options” -> “List all Devices”, and select “USB Serial Converter” from the drop down list. You shall make sure that the USB ID is 0403 (Vendor ID) and 6001 (Product ID).
Then select “libusbK (v220.127.116.11)” from the drop down list of the driver, and click the big “Replace Driver” button. Once it finished (it might take a while), you can see the change in your “Device Manager” that the FTDI cable is now listed under “libusbK USB Devices” instead of “Ports (COM & LPT)”.
After this, you can try to run the example programs under “bin” folder and should be able to see something as follows:
Developing Application Using libFTDI on Windows
The easiest way to develop application using libFTDI package above is to use the Code::Blocks IDE which can be downloaded together with mingw32 compiler. For this test, I downloaded the “codeblocks-12.11 mingw-setup.exe” from the following link, then the rest is pretty straight forward. There is a nice tutorial for beginners for setting up new project with Code::Blocks which can be found here.
Just include the header files and the pre-compiled library files (.a) into your project which are available in the “include” and “lib” directories:
For example application code, you can find some in the “src” directory which contain the original libFTDI source codes as follows:
This is a small example code which I used for testing different baud rates communication using the FTDI cables: libftdi_uart_baud_rate_test
The example code will basically print out “Hello World!” messages with different baud rates starting from 2400 baud (see baud_tbl content in the code). You can basically attach the FTDI cable to another FTDI cable which is connected to a hyperterminal like program, and change the baud everytime the program tells you to.