Programming Arudino as USB mass storage device

HI All,

There are article talking about we can program an Arduino (with 8u2 or 16u2) to appear as USB devices other than Arduino (e.g. http://arduino.cc/en/Hacking/DFUProgramming8U2 ). It is something I wanted to do since my first day with Arduino ...

Where can I find information about programing 8u2 or 16u2 chips as some specific USB devices (e.g. mass storage device)? I have tried google for information, no luck. Is that some kinds of secret that requires hacking?

A note on USB, please somebody correct me if I'm wrong:

USB devices need specific drivers (and protocols) for different device types. Most popular is HID (Human Interface Device), designed for mouse and keyboard input, because such a driver is available in every Windows installation. AFAIR Arduino installs its own driver, that turns the USB port into a serial device (COM). Drivers for an mass storage port should be part of a Windows distribution as well (external HD, memory sticks...).

Every USB driver uses its own protocol in the communication with the USB device, so that you'll have to find the appropriate firmware code for the 8u2, that implements the desired protocol. Once you have updated the 8u2, the Arduino board will behave as such a memory device, no more as a serial device. I.e. you can not program the Arduino (ATmel chip) via COM any more!

A somewhat simple solution can be a second Arduino board, from which you can remove the controller chip and replace it by the chip for your mass storage board. Then you can program the controller as usual (from the Arduino IDE). Afterwards you put the programmed chip back into your mass storage board.

More problematic IMO is the communication between the controller and the 8u2, because now your Arduino code must handle the mass storage protocol expected by the 8u2 firmware code. Details should be available with the 8u2 firmware, if you ever can find one.

I'd never try such an ambitious project, without being familiar with the low-level USB protocols, and without debugging aids for the controller. With two Arduino boards you can make these communicate via SoftwareSerial, so that you can use the Serial Monitor or a terminal program with the COM port of the second board, to display debug information from your mass storage controller, sent to the second board and from there to your PC.

Another solution may be an Arduino board without an extra 8u2, where both the USB handler and your application code can be implemented in the controller code. Then it may be possible to check an input pin on startup, and switch the controller into either an COM port or some other (mass storage) port. But such a switch is not possible on-the-fly, most probably the board has to be detached from the PC USB port and reconnected, so that Windows has a chance to detect a different device in that port, and attaches it to the proper Windows driver (COM or mass storage). It also may be required to eject the mass storage device, using "Safely Remove Hardware and Eject Media" from the Windows systray. Otherwise Windows may refuse to attach any but the same mass storage device to the USB port.

Thanks man. Google with HID and USB, I finally got the specification I needed. Even better than just information, there is also demo firmware examples too.

Its funny though, most of the information is a kind of avoid mentioning the keyword USB, which make them so difficult for me to search.

Here is what Google lead me to...

The committee developed the HID standard (IMHO, it should be USB, instead of HID)

Mass Storage Specification

USB AVR firmware examples