/lambdaUSB

A configurable USB 2.0 device core

Primary LanguagePythonBSD 2-Clause "Simplified" LicenseBSD-2-Clause

lambdaUSB

A configurable USB 2.0 device core using nMigen

lambdaUSB is still in an experimental stage and is therefore incomplete. The user-facing API may change before reaching stability.

lambdaUSB Diagram Image

Features

  • High Speed USB
  • up to 32 endpoints (16 inputs, 16 outputs)
  • double buffering, per endpoint

Installation

Download and install lambdaUSB:

git clone https://github.com/lambdaconcept/lambdaUSB
cd lambdaUSB
python3 setup.py develop --user

Usage

  1. Instantiate the USB device:
m.submodules.ulpi_phy = ulpi_phy = ulpi.PHY(pins=platform.request("ulpi", 0))
m.submodules.usb_dev  = usb_dev  = usb.Device()
m.d.comb += [
    ulpi_phy.rx.connect(usb_dev.rx),
    usb_dev.tx.connect(ulpi_phy.tx),
]

For the moment, only ULPI transceivers such as the USB3300 are supported.

  1. Instantiate endpoint interfaces:
ep1_in  = usb.InputEndpoint(xfer=usb.Transfer.BULK, max_size=512)
ep1_out = usb.OutputEndpoint(xfer=usb.Transfer.BULK, max_size=512)
  1. Add endpoint interfaces to the USB device:
usb_dev.add_endpoint(ep1_in,  addr=1)
usb_dev.add_endpoint(ep1_out, addr=1)

For a full example, have a look at examples/blinker.

Device configuration

For convenience, we provide a ConfigurationFSM to manage EP0 in lambdausb.usb.config. It stores the configuration descriptors in a ROM, and responds to host requests.

To use it, you must first generate a config file:

cd tools/genconfig
make

You will be presented a menuconfig interface from which you can setup your USB device:

menuconfig interface

The output config.py file can be imported and used like so:

from lambdausb.usb.config import ConfigurationFSM
from config import descriptor_map, rom_init

m.submodules.cfg_fsm = cfg_fsm = ConfigurationFSM(descriptor_map, rom_init)
usb_dev.add_endpoint(cfg_fsm.ep_in,  addr=0)
usb_dev.add_endpoint(cfg_fsm.ep_out, addr=0)
m.d.comb += usb_dev.addr.eq(cfg_fsm.dev_addr)

License

lambdaUSB is released under the two-clause BSD license.