FX2FPGA

I recently bought a Digilent S3BOARD from eBay for £41. I had never played with FPGAs before, but I learned VHDL some years ago when I worked for a fabless GPU design house. Unfortunately I forgot it all after I left to do other things, so I had to more or less re-learn it from scratch. I was helped along the way by a very good book.

I designed this little PCB in order to talk to the FPGA with a Cypress FX2LP, a little USB microcontroller that can do Hi-Speed transfers.

Download

You can download the project tarball, or clone the git repo here: http://github.com/makestuff/fx2fpga. You will also need fx2tools for loading code into the FX2 chip (the fx2tools package is covered in detail here).

PCB layout

You can find the Eagle schematic and layout in the pcb directory.

For some reason the ground & power fills don't come out when you load the board file. The trick is:

  • Load the PCB
  • Select the move icon ().
  • Drag'n'drop the blue square to the left of the "(C) 2009" into the right-hand half of the board.
  • Click the ratsnest icon () to recreate the power planes.
  • Drag'n'drop the blue square back on to the board so it covers the isolation around the regulator.

The point of the blue square is so the regulator has a thermal connection to the whole ground plane which can act as a heat sink. When you reposition the blue square make sure it does not short the pads.

Note that there are three unrouted nets on the board which I could not get to route without damaging the signal integrity of the USB data path, which you have to be quite careful of, given its 480MHz switching speed. Those unrouted nets I just connected with wires:

Note: The grainy whitish areas are where I over-exposed the board. This was the first PCB I made after I got a double-sided UV box, for which the usual exposure time of three minutes appears to be too long. Luckily the board still functions OK.

The PCB has two jumpers. There is one (near the bottom of the board in the picture above) for selecting the power source:

  • Right: draw power from the S3BOARD
  • Left: draw power from USB (for standalone operation, without an S3BOARD)

The other jumper (near the FX2 chip) is an EEPROM isolation jumper. When in place, the FX2 will boot from EEPROM. When not in place, it will boot from its internal firmware. The isolation jumper is a "get out of jail free card" for those times when you upload dodgy firmware, allowing you to get back to a default state.

VHDL

The VHDL is pretty simple, it just asserts the right signals for the operation of the synchronous endpoint FIFOs of the FX2 and maintains a running 16-bit checksum of the incoming bytes.

The FPGA drives:

  • the SLOE and SLRD signals low (active)
  • the SLWR and PKTEND signals high (inactive)
  • the FIFOADR[0..1] signals to "10" (by SW0 and SW1 on the S3BOARD)

The "10" on FIFOADR[0..1] tells the FX2 that the FPGA wants to access the FIFO attached to EP6.

The FX2 drives:

  • the IFCLK signal at 48MHz
  • the FLAGC (GOTDATA) signal high for the rising edge of IFCLK when there is data available on FD[0..7]
  • the FD[0..7] signals with the current byte

The FPGA maintains a running 16-bit checksum of the incoming bytes and displays it on the S3BOARD's 7-seg display. It also displays the last byte to be clocked on the S3BOARD's LEDs.

Firmware

The firmware is just the default firmware in the fx2tools package. It just copies incoming packets on EP6 to the EP6 FIFO.

Host Software

On the host side I used the bulk utility, also from the fx2tools package:

$ sudo bulk/bulk -c -b -e 6 random.dat
Checksum: 0xB04C
Speed: 24.923361 MB/s

It just measures the time taken to write 1Mbyte from a file to EP6. It uses gettimeofday() on Linux and QueryPerformanceCounter() on Windows.

I get a throughput of about 18Mbyte/s on Windows and about 25Mbyte/s on Linux. I know Dennis Muhlestein managed to get numbers around 40Mbyte/s, so I don't know why my throughput is so much lower. I suspect it's because my host-side code is still using libusb/0.1 for ease of porting. It may be that libusb/1.0 will be faster.


Leave a comment

You can use TWiki syntax in your comment