This library is a Arduino-friendly version of TinyUSB stack. It is designed with structure and APIs that are easily integrated to an Arduino Core.
Supported device class drivers are:
Serial
monitorHost stack is available with either addition of MAX3421E hardware (e.g Host FeatherWing) or rp2040 core (thanks to Pico-PIO-USB). Supported class driver are:
Note: Host stack is still work-in-progress
There are 2 type of supported cores: with and without built-in support for TinyUSB. Built-in support provide seamless integration but requires extra code added to core's source code. Unfortunately it is not always easy or possible to make those modification.
Following core has TinyUSB as either the primary usb stack or selectable via menu Tools->USB Stack
. You only need to include <Adafruit_TinyUSB.h>
in your sketch to use.
Note: For ESP32 port, version before v3.0 requires all descriptors must be specified in usb objects declaration i.e constructors. Therefore all descriptor-related fields must be part of object declaration and descriptor-related API have no effect afterwards. This limitation is not the case for version from v3.0.
Following is cores without built-in support
It is still possible to use TinyUSB but with some limits such as:
TinyUSB_Device_Init()
need to be manually called in setup()TinyUSB_Device_Task()
and/or TinyUSB_Device_FlushCDC()
may (or not) need to be manually called in loop()SerialTinyUSB
name instead of Serial for serial monitorMore document to write ...
To integrate TinyUSB library to a Arduino core, you will need to make changes to the core for built-in support and library for porting the mcu/platform.
If possible, making changes to core will allow it to have built-in which make it almost transparent to user sketch
#include "Adafruit_USBD_CDC.h"
within your Arduino.h
. For this to work, your platform.txt
include path need to have "-I{runtime.platform.path}/libraries/Adafruit_TinyUSB_Arduino/src/arduino"
.main.cpp
before setup() invoke the TinyUSB_Device_Init(rhport)
. This will initialize usb device hardware and tinyusb stack and also include Serial as an instance of CDC class.TinyUSB_Device_Task()
must be called whenever there is new USB event. Depending on your core and MCU with or without RTOS. There are many ways to run the task. For example:
TinyUSB_Device_FlushCDC()
should also be called often to send out Serial data as well.In addition to core changes, library need to be ported to your platform. Don't worry, tinyusb stack has already done most of heavy-lifting. You only need to write a few APIs
TinyUSB_Port_InitDevice()
hardware specific (clock, phy) to enable usb hardware then call tud_init(). This API is called as part of TinyUSB_Device_Init() invocation.TinyUSB_Port_EnterDFU()
which is called when device need to enter DFU mode, usually by touch1200 featureTinyUSB_Port_GetSerialNumber()
which is called to get unique MCU Serial ID to used as Serial string descriptor.