Posts

Lightweight USB Host. Part 1 – Motivation.

Lightweight USB Host

Lightweight USB Host


Universal serial bus is quite popular. USB peripherals are aplenty, and they are cheap; therefore,it is tempting to use them in microcontroller projects.

There are two distinctive roles for devices on USB bus. USB host controls the bus and initiates data exchanges. Peripheral device won’t do anything until instructed by host. In other words, to make use of USB peripheral, our little microcontroller has to become a USB host.

Making a USB host is not as difficult and scary as it sounds. We don’t need a functionality of a PC USB host controller. USB specification for embedded host says that such host need only support a certain set of devices or device classes and nothing else. What is in this set (called Target peripheral List, or TPL ) is up to you. You may want your micro to work with a certain web camera or printer, or use memory sticks, which are all “Mass Storage Class Bulk Only Transfer” devices, or Bluetooth radios, or whatever else you may need in your design.

Microchip makes several parts with built-in USB serial-interface engine (SIE). There is USB peripheral part or two in PIC18 family, and USB host, peripheral, and OTG parts in PIC24 and PIC32 families. If you don’t want to build on one these, you need to use some kind of external SIE. There are several available, most of them expensive and proprietary. Except for one.

In 2007, Maxim announced MAX3421E – the next incarnation of their MAX3420 peripheral USB controller. It is USB 2.0 low/full speed host/peripheral controller. Since there are many USB peripheral controllers around in all shapes and sizes, I will not talk about peripheral functionality of this amazing device. The host piece is more interesting.

Even though software development around MAX3421E has been slow – I know about maybe two or three commercial libraries supporting it, the part looks very promising, and may very well one day become a “MAX232 of USB”. It is inexpensive and easy to use.

I made a first attempt to use MAX3421E about a year and a half ago. Since it is packaged in TQFP-32, I routed a simple board of a reference datasheet circuit. While waiting for PCB to go back from the board house, I took a project, then another one, and another one. The PCB ended up in “back burner bin”, and the Eagle files got lost during PC migration.

Three months ago I revived the project, populated the board, and started coding. While doing that, I routed another breakout, which came out “green wire free”. Picture on the right shows it proudly sitting on a breadboard between power supply from Sparkfun and PIC18F26K20 from Microchip. I will publish the schematic design in the next week or two; in the meantime, I’d like to tell more about the part.

First of all, it is full-blown USB SIE. From the developer’s perspective it means that from the whole USB specification you have to know only what is written in chapter 9. I checked with my weathered PDF copy of USB 2.0 spec and chapter 9 is 35 pages. The whole spec is 650.

Second, it has double-buffered FIFOs for usual IN and OUT transfers, as well as separate buffer for setup packets. This means you won’t get an interrupt on each byte received, and making function code of USB transfers much simpler.

It also has 8 general purpose input and 8 output pins; inputs can be configured as level or edge interrupt lines.

All that is accessed via SPI interface with clocking up to 26MHz. There is no minimum clock speed – and because MAX3421E does all the timing on USB bus, you can drive it with slow microcontroller without much difficulty.

MAX3421E doesn’t provide any functionality above USB packet layer; standard USB transfers – control, bulk, interrupt, and isochronous, is all it is capable of. It means that if you need to, say, talk to memory stick, your job is to develop code for enumeration, Mass Storage Driver, SCSI, FAT, and file functions. Thankfully, there are several free software source code packages for all of that, so you don’t need to start coding from scratch.

Lane Hauck from Maxim wrote an article for May 2007 issue of Circuit Cellar(issue #202). If you can find this issue, take a look. The article describes first enumeration transfers as well as connects, resets, and power management.

You can research MAX3421E further on its product page. I’m planning to write a series of articles describing the embedded USB host software that I wrote for this part. Come back next week to see the first one.

Oleg.

7 comments to Lightweight USB Host. Part 1 – Motivation.

  • Tom

    On the MAXIM website page for the MAX3421E, this note is under “Status”:

    All versions are Not Recommended for New Designs.

    Does this mean there is an issue with this part?

    • I don’t think so. The part has been around for quite a while, all bugs are known and documented together with workarounds. My guess for “not recommended” status is that they decided not to fix those bugs and not release the updated version of the part.

  • Cepin

    Hello,
    Dou you think that this chip can be capable of connect USB 2.0 Hi-speed webcam. Webcam I think use isochronous transfers to send frames to PC…I need connect USB webcam (Logitech C200 ,UVC class) to Texas DSP.I need transfer only one picture…no video stream. And I hope that writing firmware will be easier because webcam is UVC class…? Thank you

  • MAX3421E is full/low speed host; it won’t work at high speed. By spec, high speed USB devices shall be capable to fall back to full speed; you can check if your camera works in this mode by connecting it to the PC via full speed hub. Since you are transferring single images, you won’t need high speed anyway.

  • Just managed to buy the Circuit Cellar article as a PDF from their site for $3,00….

  • ManisB

    “Microchip makes several parts with built-in USB serial-interface engine (SIE). There is USB peripheral part or two in PIC18 family…”

    Why did you choose the MAX external controller over the built-in Microchip one?

    • MAX3421E has fewer bugs and limitations. Besides, I’m not choosing one over another – I’m working on USB host code for Microchip SIE too.