User Tools

Site Tools

Trace: notes_on_v-usb

Notes on V-USB

V-USB by objective development is a nice library to connect AVR ATmegas and ATtinys via USB to hosts. All it requires is two MCU pins, one of which must be able to trigger an interrupt.

Coding efforts are a bit more complex than serial lines, simply because USB has so many options. Control transfers, bulk transfers, serial line emulation (CDC), optionally multiple endpoints, whatnot. Best idea is to take one of the sample projects and to hack it until it fits the purpose.

Binary Size

Especially small chips like the ATtiny2313 can be a bit a challenge. This MCU comes with only 2 kB of Flash memory, so binary size matters. Surprisingly, binary size changes considerably depending on which clock frequency the chip runs at.

The following collection was done with the very same code, which is about just enough to get a communications to the host running at all. Changed between compilations was only F_CPU. V-USB uses different code paths for each supported clock frequency. Target MCU was an ATtiny2313. RAM usage was always 46 bytes.

F_CPU in kHz Code size Remarks
12000 1464 bytes
12800 1780 bytes
15000 1520 bytes
16000 1414 bytes
16500 1536 bytes
18000 2360 bytes(requires CHECK_CRC enabled)
20000 1396 bytes

Another observation: clocks of 12.8 Mhz and 16.5 MHz work without clock crystal, so with just the internal R/C oscillator. This oscillator needs calibration, there is an osccal method and an osctune method. The former one occupies 297 bytes, the latter one just 36 bytes.

notes_on_v-usb.txt ยท Last modified: 2018/05/27 16:10 (external edit)