There are two ways to add USB to a design: using an application-specific integrated circuit (ASIC) or selecting a microcontroller with built-in USB hardware support. Each approach has its pros and cons.
Implementing USB with an ASIC:
One simple way to add USB to a design is to use an ASIC that handles USB communication internally and outputs the necessary data and signals. One of the most common USB ASICs is a USB-UART bridge, which is a (relatively) transparent interface for moving data from a USB host to an embedded system. This often takes the form of a virtual COM port on the host, which can be opened by a serial terminal application for bidirectional communication. These ASICs often also include other features, such as USB-I2C, I/O line control, analog sampling, and so on. These devices are ready to be incorporated into a design, requiring minimal implementation effort, making them ideal for last-minute additions.
However, there are some limitations to using these ASICs. One drawback is that they are a one-size-fits-all approach. If there is any functionality that cannot be achieved with the ASIC, then this approach is impractical. Another disadvantage is the additional components added to the bill of materials (BOM). These parts require PCB area and increase the design cost.
Implementing USB with a Microcontroller:
If USB communication is known to be required before selecting a microcontroller, a good option is to consider a device with onboard USB hardware peripherals. This can be found in a wide variety of microcontrollers, from high-efficiency 8-bit devices to high-performance 32-bit devices. The selection of the appropriate microcontroller depends on the application.
For simple applications, such as keyboards, mice, and USB-UART converters, 8-bit MCUs are a good choice. These devices offer a combination of small size, low power consumption, low cost, and native +5V operation.
For computationally intensive applications, 32-bit MCUs should be considered, as they are more powerful and contain more available memory. However, 32-bit MCUs can be expensive, large, and have a limited operating voltage range. A comparative table of the pros and cons of the different approaches is shown below.

Figure 1: Comparative table of the different implementation approaches
Building USB applications on AVR DU
There is a wide variety of microcontrollers with USB peripherals. This section will focus on the AVR® DU family of microcontrollers, the spiritual successor to the XMEGA® D family.
The AVR DU family introduces several improvements over older devices. For one, it no longer requires an external crystal, which reduces the bill of materials cost. The DU family also contains an integrated linear dropout regulator (LDO) for the USB circuitry if the microcontroller is powered at 3.9 V or higher. Finally, the AVR DU family includes the Programmable Debug Interface (PDID) disable feature, which permanently locks the device, preventing the microcontroller from being read, erased, or reprogrammed.
The following examples are simple applications developed for the AVR DU family. These examples use MPLAB® Code Configurator (MCC), a free tool that configures and generates an API for the onboard hardware peripherals using the included USB stack library. The library is natively compatible with the Communications Device Class (CDC) and Human Interface Devices (HID), such as keyboards and mice.

Figure 2: Opening of the USB-SPI/I2C project in MCC
CDC Application: USB to SPI/I2C
This example implements a USB-to-SPI/I2C converter that works without a custom driver. This is achieved by identifying the microcontroller as a generic CDC-class device. Most operating systems have a generic driver for this type of communication, allowing the user to send and receive data without installing a special driver.
To initiate a serial operation, the user sends a specially formatted "phrase" to the microcontroller. The data received by the microcontroller is parsed and converted (if possible) into an SPI or I2C bus operation. The microcontroller then reports command errors, communication errors (I2C only), or data read during the exchange. For SPI, the "phrases" have the following format:
spi eeprom/dac/usd <byte of data to send>
where "eeprom," "dac," and "usd" refer to the components of the Curiosity Nano Explorer used in this application. The following snippet is an example of a user "statement" to communicate with an EEPROM device (25CSM04) on the Explorer board. This command reads the memory chip's identification register.
spi eeprom 9F 00 00 00 00 00
> FF 29 CC 00 01 00
I2C has three similar, but different, formats for "phrases," since the I2C bus is shared among all connected devices.
i2c <address> r <number of bytes to read>
i2c <address> w <bytes to write>
i2c <address> wr <register address byte> <number of bytes to read>
Similar to SPI, a quick test of this is to read the manufacturer ID of a sensor, in this case an MCP9808 temperature sensor.
i2c 1c wr 06 02
> 00 54
This example is available on Github.
HID Application: USB Keyboard.
A simple, yet easily adaptable, example of USB communication is implementing a keyboard. Normally, when a keyboard detects a key press, it sends a report to the host indicating the key or keys the user is pressing. When the key is released, another report is sent to indicate that the user has released the key.
This example is implemented differently. Instead of reporting a single key or button like a standard keyboard, this example reports multiple key inputs for a single button press to create function macros. For example, pressing SW0 on the AVR64DU32 Curiosity Nano sends a report with the keys "AVR DU" to the host computer. The LED on the Curiosity Nano indicates the Caps Lock status on the host system.
In addition to the Curiosity Nano, a 2x2 Click is also connected via the Curiosity adapter board. The buttons are assigned to the macros: CTRL+C (copy), CTRL+V (paste), CTRL+Z (undo), and CTRL+X (cut). An optional external button can also be connected to send ALT+F4 to the host. This example is available on GitHub.
Conclusion:
Although USB is one of the more complex serial communication types found in embedded systems, its ubiquity is a significant added value for designs. USB can be easily added to a design using an ASIC at the cost of a larger bill of materials, or alternatively, a microcontroller with onboard USB hardware could be selected. From there, you will need to decide whether your microcontroller-based design requires the power of a 32-bit device or whether a simpler, but more cost-effective, 8-bit device, such as the AVR DU family, will suffice for the design.
About the author:
Robert Perkel is an Applications Engineer at Microchip Technology. In this role, he develops technical content such as application notes, articles, and videos. He is also responsible for analyzing peripheral use cases and developing sample code and demonstrations. Perkel graduated from Virginia Tech with a bachelor's degree in computer engineering.
