You are on page 1of 22

A Simple And Complete USB Interface

Package
For Test Bench Development
D.Breton, C.Cheikali, J.Maalmi (LAL Orsay)

Jihane Maalmi Journes VLSI IN2P3 2010

Introduction
USB 1.1 (~ 1 MBytes/s) Interface based on the FT245B circuit from
FTDI.
A specific frame protocol has been defined to cover all usual
acquisition modes.
Data acquisition can be driven either by the program or by the peripheral.
Interruptions are provided.

The package comprises hardware description, firmware and software:

Requires just a few components on the board and little firmware in users
FPGA.
Software offers a complete library for Windows and Linux.
C and LabView kits are available
A configuration and test program is also provided

NEW! USB 2.0 (5 to 25 MBytes/s )Interface based on the FT2232H


circuit from FTDI.
NEW! It is possible now to program Altera FPGAs in Active Serial
mode through the USB2.0 interface!
Jihane Maalmi Journes VLSI IN2P3 2010

Overview of the USB Interface


Only with dual ports FTDI chips
FT245B,
FT245R,
FT2232C,
FT2232H

Library +
Test Software

Altera Config
EEPROM
n_config

nsco,
dclk,asdi,
epc_data

conf_done
data

FTDI chip

OSC

RD
WR
RXF
TXE

USB
Interface
Block

FTDI config
EEPROM

Are present inside FT245R

Jihane Maalmi Journes VLSI IN2P3 2010

FPGA

FT245B Block Diagram


The entire USB Protocol is handled inside the chip
The FPGA interface is very simple, limited to an 8-bit data bus and 4 control lines
FPGA interface

USB connector
USB
Interface
Block

PC

FPGA

FT245
Config
EEPROM

OSC

Jihane Maalmi Journes VLSI IN2P3 2010

User Interface
The USB Interface Block is entirely written in Verilog and can be implemented
on any type of FPGA (Altera, Xilinx, Actel )
subadd
7

F
T
D
I
chip

data

usb_data
RD
WR
RXF
TXE

- An element can be:


register, FIFO,
RAM, a command

User Interface
element 1

8
n_read

8
USB
Interface
Block

n_write
busy
n_sync
interrupt
read_req
n_wait

User Interface
element N

single_data_bus

FPGA

Jihane Maalmi Journes VLSI IN2P3 2010

The frame protocol: Writing


USB is actually only a byte pipe : the bytes sent from the computer are just presented
to the user side without any dedicated meaning.
Thus a simple and effective encapsulation frame protocol has been developed in order to
distinguish between the different bytes. This protocol permits sending data frames and
interrupts. It has been chosen to be the simplest possible in order to generate the minimum
dead-time. The main principles are the following:
A fixed header byte.
A control byte with the number of bytes to transfer (minus 1 in order to permit all the
values up to 256).
A control byte to indicate the transfer direction and give the sub-address.
N data bytes.
A fixed trailer byte.

Octet\bit
b7
b6 b5 b4 b3 b2 b1 b0
Header
1
0 1 0 1 0 1 0
Control 1
Nb of words 1 (N 1)
Control 2 R/W*
Subadd
Data x N**
Data byte x N**
Trailer
0
1 0 1 0 1 0 1
* 0 for the writing, ** N < 256
Tab 1: format of a write data frame.

Jihane Maalmi Journes VLSI IN2P3 2010

The frame protocol: Reading


The frame format is the same for the write and read transfers, which simplifies data
identification.
For the write accesses, the number of bytes is limited to 256. For the read demands, the
data field will be used to encode the MSB of the number of bytes to transfer, which is then
able to reach 65536 (16 bits).
Octet\bit
b7
b6 b5 b4 b3 b2 b1 b0
Header
1
0 1 0 1 0 1 0
Control 1
Nb of words 1 (N 1) => LSB
Control 2 R/W*
Subadd
Data
Nb of words 1 (N 1) => MSB
Trailer
0
1 0 1 0 1 0 1
* 1 for the reading
Tab 2: format of a read demand data frame.

Octet\bit
b7
b6 b5 b4 b3 b2 b1 b0
Header
1
0 1 0 1 0 1 0
Control 1
Nb of words 1 (N 1) => LSB
Control 2 R/W*
Subadd
Data x N**
Data byte x N**
Trailer
0
1 0 1 0 1 0 1
* 1 for the reading, ** N < 65536
Tab 3: format of a read frame.
Jihane Maalmi Journes VLSI IN2P3 2010

Use of n_wait
For the slow peripherals, n_write and n_read can be retained as long
as necessary thanks to the n_wait signal.

Jihane Maalmi Journes VLSI IN2P3 2010

Use of busy
The busy signal is used during all types of access. During standard
read or write operations, it just covers the phase where acess is made
to the peripheral.

Jihane Maalmi Journes VLSI IN2P3 2010

Interrupts
There are two types of interrups :
Error Frames Interrupts (Header or Trailer) that are generated by the
USB_Interface_Block
User Interrupts that are generated by the peripheral user.

The interruption format is shown on tab 4.


It is a standard frame but where the R/W byte sent back equals 0, which is
impossible in case of a standard reading (where it is equal to 1).
For a frame error Interrupt, the Subadd value is the one used in the last
reading/writing operation
For a user interrupt, the Subadd value is 0x7F
A special Status Byte is reserved for Header and trailer errors
For user interrupt the Status Byte is determined by the user.

Octet\bit
Header
Control 1
Control 2
Data
Trailer

b7
1
0
0

b6
0
0

Jihane Maalmi Journes VLSI IN2P3 2010

b5 b4 b3
1 0 1
0 0 0
Subadd
Status byte
0 1 0

b2 b1
0 1
0 0

b0
0
0

Extended Read
Tab 5 describes the format of the frame transmitted to the computer
after a read-request triggered by the user.
This type of frame permits a peripheral-driven acquisition mode of
blocks up to 256 bytes.
This mode is supposed to offer the fastest dataflow

Octet\bit b7 b6 b5 b4 b3 b2 b1 b0
Header
1 0 1 0 1 0 1 0
Control 1
Nb of words 1 (N 1)
Control 2 1
Subadd = 0x7F
Data x N*
Data byte x N*
Trailer
0 1 0 1 0 1 0 1
* N < 256
Tab 5: format of read request frame.

Jihane Maalmi Journes VLSI IN2P3 2010

Schematics of the FT245B-based USB Interface

Jihane Maalmi Journes VLSI IN2P3 2010

The Software library


LALUsbv2 Library:
It is a library intended for software applications communicating over
USB bus with boards using FT245xx or FT2232x controllers
manufactured by FTDI Ltd.

It is an extension of FTDI FTD2XX library: It provides a simplified error


handling mechanism, a data encapsulation and an interrupt management
complying with the specifications of the LAL USB Communication protocol.

LALUsb has been designed to free the user from knowing about LAL frames
format, for neither encoding nor decoding.
LALUsb is mainly used as a shared library (DLL) but a static version (.lib
file) is also available.

LabView VIs Library also available

Jihane Maalmi Journes VLSI IN2P3 2010

Examples of functions
Device initialization, open and close

BOOL USB_FindDevices(char *DeviceDescriptionStr);


int USB_GetNumberOfDevs(void);
int OpenUsbDevice(char *sernumstr);
unsigned char USB_GetVersion(int id);
BOOL USB_Init (int id, BOOL verbose) ;
void CloseUsbDevice(int id);
BOOL USB_PurgeBuffers(int id);

Write and Read in LAL format

int UsbWrt (int id, char sub_addr, void *buffer, int count);
int UsbRd (int id, char sub_addr, void *array, int count);

Jihane Maalmi Journes VLSI IN2P3 2010

TEST 245 : Utility for Configuration and Test


Test245 :

(Windows 2000
SP2, XP and Vista, MacOS X,
Linux)

Test245 is a little utility


intended for testing and
debugging freshly
designed boards or
devices based on FTDI
FT245xx (and now also
FT2232xx) family of USB
controllers and complying
with LAL USB
Communication protocol
It is also used to
configure new devices.
It relies on LALUsbv2
library functions to
perform various inputoutput tests

Jihane Maalmi Journes VLSI IN2P3 2010

Device Configuration Wizard

Jihane Maalmi Journes VLSI IN2P3 2010

Board Examples
The FT245B-based interface has been used in IN2P3 and IRFU for different boards:

The ASPIC Back End


Board ( for LSST)

The MATACQ14
14-bit/2GS/s
digitizer board

The Lumi_PM
test board
for ATLAS
luminometer

The MAROC2_USB
test board
for ATLAS Luminometer

Jihane Maalmi Journes VLSI IN2P3 2010

The USB WaveCatcher


Board

Software Examples

WaveCatcher SiPM Charge Histo

AlfaPMF application at CERN

The C program for ATLAS Lumi-PM acquisition


The LabView program for MATACQ board acquisition

Jihane Maalmi Journes VLSI IN2P3 2010

What is new with the USB 2.0 Interface?


FT245, and FT2232D are limited to 1MByte/s
FT2232H offers the same asynchronous interface as the FT245 but
with the ability to reach 5MBytes/s.
no change for the user interface in the FPGA (except the clock frequency)
no change for the software

FT2232H also offers a synchronous interface that adds only two wires
to the FPGA interface but is supposed to reach 25 MBytes/s. (to be
tested soon)
Possible changes for the user interface
no change for the software

FT2232H offers a second port that can be dedicated to FPGA


EEPROM configuration. (also true with FT2232D)

Jihane Maalmi Journes VLSI IN2P3 2010

Schematics of the FT2232H-based USB Interface

Jihane Maalmi Journes VLSI IN2P3 2010

Documentation
Documentation of the LAL USB
Interface based on the FT245 chip

A normalized USB interface


based on the FT245B chip from FTDI.

Documentation the software library


D.BRETON, LAL ORSAY
With the valuable help of C.CHEIKALI and B.LAVIGNE

SERVICE ELECTRONIQUE

The current document seeks to describe a USB interface implementation proposal based
on the FTDI FT245B circuit. The latter in fact being only a byte pipe, a framing protocol for
distinguishing bytes is also proposed. The objective is to obtain a plug and play
combination comprising the interface part of the board, the decoding block to integrate in a
FPGA on the user side and the graphic interface software running on PC and MacIntosh.
Furthermore, the user side FPGA interface seeks to be the simplest possible, while offering all
of the different current modes of functioning in data acquisition systems. To this end, three
types of interfaces are offered.

LALUsbV2
Readme Windows 2000/XP
V1.2.0.0
C.CHEIKALI LAL Orsay
29/09/07
- DRAFT -

This document describes LALUsb library and includes a user manual (description, installation) and a programmers guide
holding all the functions reference. Its been written on a temporary basis before the real version coming soon.

Coming soon : Documentation of the Interface based on the FT2232H


chip

Jihane Maalmi Journes VLSI IN2P3 2010

Conclusion
We have designed a very simple to use USB package

It is Plug&Play
It includes hardware, firmware and software
It is available with different FTDI chips, depending on the application ()
A specific protocol has been developped, permitting all types of data
transfer

1MByte/s versions have been used for 3 years for different labs and
boards
5 to 25 (?) MBytes/S version is being developped
Hardware is already available for board design

All information on the web site:


http://electronique.lal.in2p3.fr/echanges/LALUsb/index.htm
Jihane Maalmi Journes VLSI IN2P3 2010

You might also like