Cypress EZ-USB FX2 (Interfacing with the BASYS USB)
I’ve taken a break from my Verilog programming to better understand USB. My goal is to create some sort of FPGA data processor running over high-speed USB. The BASYS board includes a Cypress EZ-USB FX2 controller. I think the BASYS also comes with software for communicating with the board, but its windows only and a closed api so I haven’t looked into this at all. I’m trying to replace the Digilent’s firmware for the EZ-USB. This post covers some of what I’ve done so far.
I’m burried under lots of documentation. I’ve only read about 25%.
- – The Cypress EZ-USB FX2 Technical Reference
- – The Intel 8051 uC
- – The USB 2.0 Specification
- – The Small Device C Compiler (sdcc)
The Cypress EZ-USB FX2
This devices has a couple of clever features. First, it includes a microcontroller (an Intel 8051 clone) which handles all the USB houskeeping. The microcontroller can handle the usb configuration, enumeration, and control packets. The CPU isn’t required for the bulk of data transfer. The FPGA directly interfaces with a memory buffer removing any possible bottlenecks.
Second, the device supports a software firmware loader. This is great since it means i can replace the propritary code which normally runs on the chip. Once a new firmware has been loaded, it can cause the device to simulate a disconnect/connect forcing the host to re-enumerate the device capabilities.
Linux Development
This page has a quick overview of using the EZ-USB in linux.
- – fxload, from linux hotplug, is a frimware loader supporting the EZ-USB
- – sdcc, is a c compiler supporting the 8051 uC inside the EZ-USB
Both softwares are apt-get’able on ubuntu.
Theres a simple sample project in SVN.
My Development Progress
I’ve created a very simple firmware;
#include "fx2regs.h"
int main() {
USBCS |= bmDISCON;
USBCS &= ~(bmRENUM);
USBCS &= ~(bmDISCON);
return 0;
}
This is a very short program. It sets the DISCON bit (causing the EZ-UZB to disconnect from the USB bus), then sets the RENUM bit (causing the EZ-USB, instead of firmware, to take over all usb control functions). When it resets DISCON the EZ-USB connects to the PC and enumerates using its default settings.
The default USB descriptors for the EZ-USB are well documents in its technical reference. I hope to reuse one of its default configurations and let the EZ-USB do most of USB management.
I wrote a little libusb program in C to test things out (SVN). Each USB device has a configuration hierarchy. Configuration -> Interface(s) -> AltSettings -> Endpoint(s). The test program sets the configuration, interface, and altsettings. Looking in /sys/bus/usb, I was able to confirm the expected endpoints were showing.
I’m hoping I can use one these endpoints without anymore coding, but I have to finish up my reading on accessing the FIFO externally.

January 8th, 2009 at 5:16 pm
I am trying to integrate the code that will do FX2 Intel Hex Image download with the USB Device Kernel Module I am woking on,
I wonder if you have any experience on this or give me a pointer where I can get some information from.
Currently I can do the downloading by using fxload utility in the user space.
Thanks and Best Regards
Peter
January 10th, 2009 at 11:35 pm
I’m still manually downloading with fxload.
From my understanding its probably easiest to keep fxload and your kernel driver separate.
On ubuntu you can take a look udev; specifically; /etc/udev/rules.d
You can add a rule here which will cause fxload to automatically run when the device is connected.
e.g. create a file with this in all one line
BUS==”usb”, ACTION==”add”, SYSFS{idVendor}==”03fd”, SYSFS{idProduct}==”0015″, RUN+=”/sbin/fxload -v -t fx2 -I /usr/share/xusb_xse.hex -D $TEMPNODE”
Whenever vender=0×03fd, product=0×0015 is attached, it will load xusb_xse firmware.
You may need to use a different product id before and after renumeration so fxload and your driver don’t contend for access of the device when attached.
March 2nd, 2009 at 12:18 pm
Nice starting point for using the USB interface. I took your ideas and added some more code to get transfers going between the FX2 and FPGA. I have a Nexys board, which is probably pretty similar to the Basys. My notes and code are linked from my blog entry at blog.sensicomm.com.
Thanks,
Joe
August 19th, 2009 at 6:56 am
Maybe you are interested in the ZTEX Firmware Kit + Driver
API for EZ-USB based hardware:
http://www.ztex.de/firmware-kit/index.e.html
It is Open Source and runs on Linux and Windows. It is mainly intended for our USB and/or FPGA boards but should run on every EZ-USB based hardware.
The Firmware Kit (for EZ-USB Microcontrollers) is written in C (requires SDCC compiler). The Firmware is assembled using a macro processor which allows to specify all required settings by a few macros. The necessary USB descriptors and the descriptor handling routines are generated automatically.
The driver API is written in Java and allows platform independent device drivers.