USB Notes, with special reference to AVR controllers.

May 25, 2013

USB Basics

You are going to have a hard time doing any USB programming if you don't have a grasp on USB concepts. The USB specification, even though it is 650 pages, is actually pretty accessible. There are sizeable sections of marketing rubbish that you can skip, and there are large sections on mechanical and electrical specifications that you don't need to get tangled up in. I highly recommend chapter 4, along with chapter 9.

An excellent book is "USB Complete" by Jan Axelson:

At this point I have no interest in USB 3.0, so I may try reading the older second edition to avoid learning all the USB 3.0 stuff, at least on a first pass.

Some real hardware

This is sort of getting ahead of ourselves, but here we go. The game is to poke around on my own linux system to see what I can learn ...

Device side programming - LUFA

You will discover when you first start playing with a 32u4 based AVR device, that as soon as you load the blink demo and start it running, your device disconnects from the USB. This is entirely normal and proper if you haven't included any USB stack in your application (which you certainly won't have done in a trivial blink demo). If you want your application to do USB communication, you are going to have to provide a USB stack. The LUFA library is probably the best candidate for this.

Host side programming - libusb

Some devices will be fully supported by an existing linux device driver. Other devices will require custom code, and that is where libusb comes in.

USB to serial adapters

Some AVR chips these days (such as the 32u4) have a built in USB interface. Older AVR chips (and other devices) require a USB to serial interface unit. You could use them with drivers for a plain old RS232 port I guess, but nobody seems to do that. Arduinos that need a USB interface use either the FT232 chip, or an AT16u2 chip programmed with dedicated usb to serial firmware. With the programmable 16u2 chip (or one of the chips with built in USB like the 32u4), you can fiddle with the firmware and make your device act like anything you want (a keyboard, joystick, whatever). Most cheap USB to serial "cables" you buy have the FT232 chip (or a clone) inside. The FT232 has firmware inside, but you can't get at it.


Feedback? Questions? Drop me a line!

Tom's Computer Info / tom@mmto.org