Simon Kaufmann

AVR USB Flash Drive

×

AVR USB Flash Drive

Jan 16, 2018

It’s fascinating to test how much you can get out of a tiny microcontroller, for example the Atmel ATmega 16, an 8 bit processor clocked at about 16 MHz.

Communicating via USB is a challenge for such a comparably slow and low power device (with as little as 32kB of storage available for the compiled code). The processor does not come with any hardware USB support and therefore everything needs to be done in software.

This project is based on VUSB, a library implementing low-speed USB 1.1 on the AVR microcontroller and the goal was to implement the USB Mass Storage protocol on the ATmega 16.

As part of the project endpoints, descriptors and communication with the EEPROM used by the microcontroller to store the actual data was created implementing the USB Mass Storage protocol.

This protocol requires communication over bulk transfer endpoint which is not supported for low speed USB and the VUSB library and the microcontroller’s specifications don’t allow any faster communication than low speed.

Overcoming the issue was suprisingly simple in the end: the Linux kernel had to be recompiled. With the help of a very useful tool to search the linux kernel code, I figured out that in fact only one if had to be removed which blocked bulk transfers on the PC side.

Unfortunately, this means that the USB stick will never be useable on a regular PC, but of course with only 64kB of EEPROM memory to store files, it wouldn’t be particularly useful anyway. Still I was amazed that it actually proved to work - even on Windows in a virtual machine with USB support the flash drive was recognised if the VM runs on a machine with a modified linux kernel.

Code can be found on my Github.
Additionally, there is also a short presentation explaining some of the concepts.

Here are some photos of the finished flash drive, I’d also like to thank a very good friend of mine for helping me with the hardware:

© Simon Kaufmann 2021 | Theme powered by w3.css