Arduino support for TinyUSB stack

Overview

Adafruit TinyUSB Library for Arduino

Build Status License

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.

Features

Currently only support device mode only, supported class drivers are:

  • Communication (CDC): which is used to implement Serial monitor
  • Human Interface Device (HID): Generic (In & Out), Keyboard, Mouse, Gamepad etc ...
  • Mass Storage Class (MSC): with multiple LUNs
  • Musical Instrument Digital Interface (MIDI)
  • WebUSB with vendor specific class

Supported Cores

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.

Cores with built-in support

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.

Cores without built-in support

Following is cores without built-in support

  • mbed_rp2040

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()
  • Use SerialTinyUSB name instead of Serial for serial monitor
  • And there could be more other issues, using on these cores should be considered as experimental

Class Driver API

More document to write ...

Porting Guide

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.

Arduino Core Changes

If possible, making changes to core will allow it to have built-in which make it almost transparent to user sketch

  1. Add this repo as submodule (or have local copy) at your ArduioCore/libraries/Adafruit_TinyUSB_Arduino (much like SPI).
  2. Since Serial as CDC is considered as part of the core, we need to have #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".
  3. In your 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.
  4. 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:
  • Use USB IRQn to set flag then invoke function later on after exiting IRQ.
  • Just invoke function after the loop(), within yield(), and delay()
  1. TinyUSB_Device_FlushCDC() should also be called often to send out Serial data as well.
  2. Note: For low power platform that make use of WFI()/WFE(), extra care is required before mcu go into low power mode. Check out my PR to circuipython for reference https://github.com/adafruit/circuitpython/pull/2956

Library Changes

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

  1. 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.
  2. TinyUSB_Port_EnterDFU() which is called when device need to enter DFU mode, usually by touch1200 feature
  3. TinyUSB_Port_GetSerialNumber() which is called to get unique MCU Serial ID to used as Serial string descriptor.
Comments
  • MIDI - support for virtual wires/jacks

    MIDI - support for virtual wires/jacks

    Here is a working proof-of-concept to support virtual wires/jacks for MIDI devices: https://github.com/kaysievers/Adafruit_TinyUSB_Arduino/tree/midi-jacks https://github.com/kaysievers/ArduinoCore-samd/tree/tinyusb-midi-jacks

    Tested to create 1 or 3 virtual jacks.

    Please let me know how to proceed, or if you have any better ideas. I would finish it properly if this is an interesting feature. Thanks!

    Feature 
    opened by kaysievers 23
  • [Bug] WebUSB device fails to enumerate

    [Bug] WebUSB device fails to enumerate

    Since the restructured Core repositories (today), WebUSB devices fail to enumerate on Windows. I dumped the descriptor, but cannot see any obvious difference.

    Everything appears to work fine on Linux. Windows works with the code before the Core repository was split out (yesterday).

    I tried the webusb_rgb.ino example with the same result. See the attached screenshot:

    Unknown USB Device (Device Descriptor Request Failed) Properties 2019-12-21 0_15_02

    Bug 
    opened by kaysievers 15
  • ESP32-S2 msc_sdfat example crashes

    ESP32-S2 msc_sdfat example crashes

    Operating System

    MacOS

    IDE version

    1.8.19

    Board

    Adafruit ESP32-S2 Feather with BME280 Sensor - STEMMA QT (4MB Flash + 2 MB PSRAM) + Adafruit Micro SD SPI or SDIO Card Breakout Board connected as SPI device with CS = 15

    ArduinoCore version

    2.0.3

    TinyUSB Library version

    1.12.0

    Sketch (attached txt file)

    examples/MassStorage/msc_sdfat with two minor changes:

    const int chipSelect = 15;
    ...
    while ( !Serial ) delay(10);   // wait for native usb
    

    What happened ?

    If during loop() directory printing process one of the usb_msc.setReadWriteCallback callbacks is called, or in other words when USB driver is working on reading or writing SD card (SPI interface, CS = 15) the ESP32-S2 Feather crashes and reboots.

    If I disable root. and file. calls in loop() the device is working normally as a USB storage device.

    If I leave usb_msc.setUnitReady in FALSE state and keep fs_changed flag as TRUE, loop is printing directory listing periodically without any issues.

    If both usb_msc.setUnitReady is TRUE, and access to SD card file system is enabled in loop(), the device crashes and restarts constantly.

    How to reproduce ?

    1. Open Adafruit msc.sdfat example
    2. Change CS pin to 15
    3. Uncomment while(!Serial) line to enable serial monitor outputs
    4. Compile and upload the example

    Debug Log

    output.txt

    Screenshots

    No response

    Bug 
    opened by skobkars 12
  • MIDI Messages One Message Behind

    MIDI Messages One Message Behind

    Describe the bug Hey all. Not sure this is an issue with your library or the underlying MIDI Library but want to confirm. I am running the Adafruit TinyUSB MIDI version 0.9.0 and my messages appear to be one step behind.

    For example the first message the system sees is a NOTE_ON message, but only after I release the note. So hitting three consecutive keys on a virtual midi keyboard shows up like this in the NoteOn and NoteOff handlers:

    15:56:27.083 -> Note on: channel = 1, pitch = 60, velocity - 100 15:56:30.077 -> Note off: channel = 1, pitch = 60, velocity - 0 15:56:30.511 -> Note on: channel = 1, pitch = 62, velocity - 100 15:56:31.779 -> Note off: channel = 1, pitch = 62, velocity - 0 15:56:32.143 -> Note on: channel = 1, pitch = 65, velocity - 100

    As you can see I released the last note and the last message is a NOTE_ON type. This output is using your midi_test Example sketch with the MIDI sends commented out. Any ideas or pointers? Should I be bugging the maintainers of MIDI Library?

    Note: I am on OSX Catalina using CoreMIDI to connect to the board via USB. Thanks!

    Set up (please complete the following information)

    • Your Board and BSP version: Feather M4, not sure on BSP
    • TinyUSB library version : 0.9.0
    • Your OS (mac/windows/linux) and its version: Catalina via CoreMIDI
    • Serial debug log if any: see above

    To Reproduce Steps to reproduce the behavior:

    1. Run the midi_test example sketch with no MIDI output
    2. Connect to your board using OSX CoreMIDI and some kind of Virtual Midi Keyboard. Like "vmpk" (Note: I tested several, all with the same results)
    3. Turn on Serial Monitor and start pressing keys
    4. See debug output

    Expected behavior Pressing a note on the virtual KB should result in a NOTE_ON message when first pressed, then a NOTE_OFF message when released. Multiple notes at one time should behave the same.

    Screenshots If applicable, add screenshots to help explain your problem.

    Additional context Add any other context about the problem here.

    Bug 
    opened by acumartini 12
  • Failed to compile msc_external_flash, error

    Failed to compile msc_external_flash, error "Error compiling for board ESP32S2 Native USB"

    Operating System

    Windows 10

    IDE version

    1.8.16 (latest at the moment)

    Board

    ESP32S2 Native USB, ESP32S2 Dev Module

    BSP version

    2.0

    TinyUSB Library version

    1.5.0

    Sketch

    Adafruit_TinyUSB_Arduino/examples/MassStorage/msc_external_flash/msc_external_flash.ino

    What happened ?

    All my efforts on trying to compile it keeps failing. The compiler reaches the "Linking everything together" part and shortly after that fails with error message "Error compiling for board ESP32S2 Native USB".

    How to reproduce ?

    Compile the example with the board selected and you should have it.

    Debug Log

    No response

    Screenshots

    No response

    Bug 
    opened by mihkel615 11
  • Issue with devices behind a USB hub

    Issue with devices behind a USB hub

    With commit https://github.com/adafruit/Adafruit_TinyUSB_ArduinoCore/commit/8096c8a8f8aad8458ff5762c990e10ae9dad1a1b the devices seem no longer working when they are connected behind a USB hub. Directly connecting them to the host's root hub works fine.

    Reverting the commit makes the devices appear.

    This is a kernel log from Linux (Windows shows similar problems):

    [34324.981477] usb 1-3: new high-speed USB device number 120 using xhci_hcd
    [34325.122916] usb 1-3: New USB device found, idVendor=0bda, idProduct=5411, bcdDevice= 1.21
    [34325.122921] usb 1-3: New USB device strings: Mfr=1, Product=2, SerialNumber=0
    [34325.122924] usb 1-3: Product: 4-Port USB 2.0 Hub
    [34325.122927] usb 1-3: Manufacturer: Generic
    [34325.126468] hub 1-3:1.0: USB hub found
    [34325.128779] hub 1-3:1.0: 4 ports detected
    [34325.416491] usb 1-3.1: new full-speed USB device number 121 using xhci_hcd
    [34325.492536] usb 1-3.1: device descriptor read/64, error -71
    [34325.671522] usb 1-3.1: device descriptor read/64, error -71
    [34325.855503] usb 1-3.1: new full-speed USB device number 122 using xhci_hcd
    [34325.931543] usb 1-3.1: device descriptor read/64, error -71
    [34326.111541] usb 1-3.1: device descriptor read/64, error -71
    [34326.219655] usb 1-3-port1: attempt power cycle
    [34326.815518] usb 1-3.1: new full-speed USB device number 123 using xhci_hcd
    [34326.829286] usb 1-3.1: device descriptor read/8, error -32
    [34326.945371] usb 1-3.1: device descriptor read/8, error -32
    [34327.128514] usb 1-3.1: new full-speed USB device number 124 using xhci_hcd
    [34327.143060] usb 1-3.1: device descriptor read/8, error -32
    [34327.265333] usb 1-3.1: device descriptor read/8, error -32
    [34327.371687] usb 1-3-port1: unable to enumerate USB device
    
    opened by kaysievers 11
  • Add option to remove CDC ACM interface

    Add option to remove CDC ACM interface

    I propose adding a compile time option to remove the CDC ACM port. This allows Adafruit boards to more closely emulate real USB keyboards, joysticks, etc. The IAC class descriptor and CDC ACM descriptors confuse some embedded devices such as KVM switches, old computer BIOS, game consoles, etc.

    The PluggableUSB stack has this option. It requires some code patching but it does work. The symbol is CDC_ENABLED.

    I propose using CDC_DISABLED so when it is not defined (the default), the behavior is unchanged. The symbol can be defined by changing the boards.txt

    adafruit_qtpy_m0.menu.usbstack.tinyusb.build.flags.usbstack=-DUSE_TINYUSB -DCDC_DISABLED

    I use arduino-cli so it is possible to define the symbol without changing boards.txt. The VID, PID, and other USB parameters can be passed via command line options so exact emulation is much easier.

    The following change applies to this repo.

    diff --git a/Adafruit_USBD_Device.cpp b/Adafruit_USBD_Device.cpp
    index 1f51925..458c726 100644
    --- a/Adafruit_USBD_Device.cpp
    +++ b/Adafruit_USBD_Device.cpp
    @@ -60,11 +60,17 @@ Adafruit_USBD_Device::Adafruit_USBD_Device(void)
         .bDescriptorType    = TUSB_DESC_DEVICE,
         .bcdUSB             = 0x0200,
     
    +#ifdef CDC_DISABLED
    +    .bDeviceClass       = 0,
    +    .bDeviceSubClass    = 0,
    +    .bDeviceProtocol    = 0,
    +#else
         // Use Interface Association Descriptor (IAD) for CDC
         // As required by USB Specs IAD's subclass must be common class (2) and protocol must be IAD (1)
         .bDeviceClass       = TUSB_CLASS_MISC,
         .bDeviceSubClass    = MISC_SUBCLASS_COMMON,
         .bDeviceProtocol    = MISC_PROTOCOL_IAD,
    +#endif
     
         .bMaxPacketSize0    = CFG_TUD_ENDPOINT0_SIZE,
    

    Changes are required to the SAMD and nrf52 cores to conditionalize the call to addInterface based on !CDC_DISABLED.

    https://github.com/adafruit/ArduinoCore-samd/blob/master/cores/arduino/TinyUSB/Adafruit_TinyUSB_SAMD.cpp#L81

    https://github.com/adafruit/Adafruit_nRF52_Arduino/blob/master/cores/nRF5/TinyUSB/Adafruit_TinyUSB_nRF.cpp#L94

    I do not have an nRF52840 board around at the moment but have tested the changes out on an ItsyBitsy M0.

    opened by gdsports 11
  • HID echo to python example is losing a character (from the buffer?)

    HID echo to python example is losing a character (from the buffer?)

    Describe the bug hid_generic_inout.ino example appears to be losing the first character in the buffer. Here is the output from the python script:

    Openning HID device with VID = 0x239A
    {'path': b'\\\\?\\hid#vid_239a&pid_800f&mi_02#8&1f3020af&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}', 'vendor_id': 9114, 'product_id': 32783, 'serial_number': '84C8D28C5150484347202020FF042C23', 'release_number': 256, 'manufacturer_string': 'Adafruit', 'product_string': 'TinyUSB HID Generic', 'usage_page': 65280, 'usage': 1, 'interface_number': 2}
    Send text to HID Device : a
    Received from HID Device: b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
    
    Send text to HID Device : a
    Received from HID Device: b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
    
    Send text to HID Device : sa
    Received from HID Device: b'a\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
    
    Send text to HID Device : s
    Received from HID Device: b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
    
    Send text to HID Device : ss
    Received from HID Device: b's\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
    
    Send text to HID Device : sdf
    Received from HID Device: b'df\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
    
    Send text to HID Device : aaaa
    Received from HID Device: b'aaa\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
    
    Send text to HID Device : a
    Received from HID Device: b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
    
    Send text to HID Device : aa
    Received from HID Device: b'a\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
    
    Send text to HID Device : aaa
    Received from HID Device: b'aa\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
    
    Send text to HID Device : Traceback (most recent call last):
      File "hidTest.py", line 15, in <module>
        str_out = input("Send text to HID Device : ").encode('utf-8')
    KeyboardInterrupt
    

    Set up (please complete the following information)

    • ItsyBitsy M0, Adafruit SAMD boards V1.6.4
    • TinyUSB library version V0.10.0
    • Win10 2004

    To Reproduce Steps to reproduce the behavior:

    1. Run the example and send the ItsyBitsy some text over the python console.

    Expected behavior The same text I entered would be written back. Instead, it is missing the first character I type.

    Bug 
    opened by SimonMerrett 11
  • Linux CDC (/dev/ttyACM*) <=> TinyUSB on nRF52 freezes with too much data

    Linux CDC (/dev/ttyACM*) <=> TinyUSB on nRF52 freezes with too much data

    First of all many thanks :pray: :tada: for excellent and very useful software!

    Operating System

    Linux (reproduced on Ubuntu 21.04 and also Raspberry Pi OS "buster")

    IDE version

    Reproduced with Arduino IDE 1.8.16.

    Board

    Adafruit Circuit Playground Bluefruit, S140 6.1.1, Level 0 (Release) image

    BSP version

    Version 1.1.0, I think?

    image

    TinyUSB Library version

    Adafruit TinyUSB Library 1.4.4 (and whichever tinyusb that bundles)

    Sketch

    I can repro with this simple read-and-echo-back sketch:

    #include <Arduino.h>
    #include <Adafruit_TinyUSB.h>
    
    void setup() {
      Serial.begin(115200);
      while (!Serial) {
        digitalWrite(LED_BUILTIN, (millis() % 500) < 50);
        delay(10);
      }
    }
    
    void loop() {
      if (Serial.available()) {
        const char ch = Serial.read();
        Serial.write(ch);
        digitalToggle(LED_BUILTIN);
      }
    }
    

    I use the following Python script to write to the device (requires pyserial installed):

    #!/usr/bin/env python3
    
    import argparse
    import time
    
    import serial  # type: ignore
    
    parser = argparse.ArgumentParser()
    parser.add_argument("--port", default="/dev/ttyACM0")
    parser.add_argument("--bps", type=float, default=1000000)
    parser.add_argument("--chunk", type=int, default=128)
    
    args = parser.parse_args()
    
    with serial.Serial(args.port, timeout=0) as serial:
        start_mono = time.monotonic()
        rx_total = tx_total = 0
        next_status = 0.0
        while True:
            elapsed = time.monotonic() - start_mono
            if elapsed > next_status:
                print(
                    f"tx={tx_total}b/{elapsed:.1f}s={tx_total/elapsed:.1f}bps "
                    f"| rx={rx_total}b/{elapsed:.1f}s={rx_total/elapsed:.1f}bps"
                )
                next_status += 1.0
                continue
            
            rx_total += len(serial.read(serial.in_waiting) or b"")
            delay = ((tx_total + args.chunk) / args.bps) - elapsed
            if delay < 0:
                tx_total += serial.write(b"x" * args.chunk)
            else:
                time.sleep(min(1, delay))
    

    What happened ?

    With a small chunk size and a low rate, it will run for a while:

    % ./serial_spam.py --bps 100 --chunk 40
    tx=0b/0.0s=0.0bps | rx=0b/0.0s=0.0bps
    tx=80b/1.2s=66.6bps | rx=40b/1.2s=33.3bps
    tx=160b/2.0s=80.0bps | rx=120b/2.0s=60.0bps
    tx=280b/3.2s=87.5bps | rx=240b/3.2s=75.0bps
    tx=360b/4.0s=90.0bps | rx=320b/4.0s=80.0bps
    tx=480b/5.2s=92.3bps | rx=441b/5.2s=84.8bps
    tx=560b/6.0s=93.3bps | rx=520b/6.0s=86.7bps
    tx=680b/7.2s=94.4bps | rx=640b/7.2s=88.9bps
    tx=760b/8.0s=95.0bps | rx=720b/8.0s=90.0bps
    tx=880b/9.2s=95.6bps | rx=840b/9.2s=91.3bps
    tx=960b/10.0s=96.0bps | rx=920b/10.0s=92.0bps
    tx=1080b/11.2s=96.4bps | rx=1040b/11.2s=92.9bps
    tx=1160b/12.0s=96.7bps | rx=1120b/12.0s=93.3bps
    tx=1280b/13.2s=97.0bps | rx=1240b/13.2s=93.9bps
    tx=1360b/14.0s=97.1bps | rx=1320b/14.0s=94.3bps
    

    Going to a larger chunk size and/or higher rate freezes fairly quickly:

    % ./tools/serial_spam.py --bps 1024 --chunk 128
    tx=0b/0.0s=0.0bps | rx=0b/0.0s=0.0bps
    tx=896b/1.0s=895.7bps | rx=770b/1.0s=769.8bps
    tx=1920b/2.0s=959.8bps | rx=1795b/2.0s=897.3bps
    tx=2944b/3.0s=981.2bps | rx=2817b/3.0s=938.9bps
    tx=3968b/4.0s=991.9bps | rx=3840b/4.0s=959.9bps
    tx=4992b/5.0s=998.3bps | rx=4864b/5.0s=972.7bps
    [[[ process is hung here ]]]
    

    Once frozen, the USB-serial port is borked for host-to-device; any attempt to write will freeze the program. (Verified in a terminal program as well, or even just "cat" to the port.) Device-to-host data still flows, however.

    I took some usbmon traces which I can share if they are interesting, they seem to show the device failing to respond to requests for data in that direction?? But I am not very versed in the nuts and bolts of USB communication.

    POSSIBLY relevant: https://github.com/adafruit/Adafruit_TinyUSB_Arduino/issues/57 (but the opposite direction).

    How to reproduce ?

    Run the above sketch on the device.

    Run the above tester program on the connected host (setting --port if necessary).

    Debug Log

    (I'm not sure how to collect this log, but I can research it.)

    Screenshots

    (See text traces above.)

    Bug 
    opened by egnor 10
  • Crashing on SAMD

    Crashing on SAMD

    Using SAMD Core 1.5.7 and TinyUSB_Arduino 0.7.1 I can't get any of the examples I tried to work, the Serial port never comes back after uploading and Windows reports a malfunctioning USB device. Tested on SAMD21 and SAMD51.

    With just the blink example uploaded but TinyUSB selected it is still working.

    I tested generic HID and Keyboard HID. Both crash. I also tried MSC Ramdisk, which shows up after a while and the serial port also comes back but then disappears again after a bit.

    opened by timonsku 10
  • Missing header file: Adafruit_TinyUSB_Core.h

    Missing header file: Adafruit_TinyUSB_Core.h

    Git rev: 7b4814f6253dd06969a817adad2db80bcbac2226

    Can't compile any of the examples due to missing header file.

    Arduino: 1.8.9 (Linux), Board: "SparkFun Pro nRF52840 Mini, s140 6.1.1 r0, Level 0 (Release)"
    
    In file included from /home/bjc/Arduino/libraries/Adafruit_TinyUSB_Arduino/src/Adafruit_TinyUSB.h:28,
                     from /home/bjc/Arduino/libraries/Adafruit_TinyUSB_Arduino/examples/HID/hid_composite/hid_composite.ino:4:
    /home/bjc/Arduino/libraries/Adafruit_TinyUSB_Arduino/src/Adafruit_USBD_MSC.h:28:10: fatal error: Adafruit_TinyUSB_Core.h: No such file or directory
     #include "Adafruit_TinyUSB_Core.h"
              ^~~~~~~~~~~~~~~~~~~~~~~~~
    compilation terminated.
    exit status 1
    Error compiling for board SparkFun Pro nRF52840 Mini.
    
    This report would have more information with
    "Show verbose output during compilation"
    option enabled in File -> Preferences.
    
    
    opened by bjc 10
  • esp32 s2 HID stop working after PC wake from sleep

    esp32 s2 HID stop working after PC wake from sleep

    Operating System

    Windows 10

    IDE version

    Arduino 1.8.18

    Board

    esp32s2

    ArduinoCore version

    Adafruit feather esp32-s2

    TinyUSB Library version

    latest

    Sketch (attached txt file)

    examples\HID\hid_composite

    What happened ?

    hi i'm gellary i'm looking for help HID mouse and keyboard not working , after PC wake from sleep press restart button on board or replug usb cable to solve the problem

    not convenient appreciate for your help~

    How to reproduce ?

    Debug Log

    No response

    Screenshots

    No response

    Bug 
    opened by gellary 0
  • MIDI: support port name strings

    MIDI: support port name strings

    MIDI port names

    This patch allows to set custom descriptive names for virtual MIDI ports/cables. A MIDI port offers different functionality on the same physical USB device. The names make it easier to distinguish one from the other.

    Edit: the tinyusb part was merged: https://github.com/hathach/tinyusb/pull/1738

    Screenshot of Chrome on MacOS listing WebMIDI devices:

    Screenshot 2022-11-10 at 17 03 00

    Screenshot of MacOS system-level MIDI Setup

    Screenshot 2022-11-10 at 17 02 35

    Example calls in setup() of Arduino sketch:

      Device.usb.midi.setPortName(1, "Keyboard");
      Device.usb.midi.setPortName(2, "Drum Pads");
      Device.usb.midi.setPortName(3, "Lights");
    

    Calls to Adafruit_TinyUSB_Arduino from a local/custom MIDI Library:

      void setPorts(uint8_t n_ports) {
        _midi.interface.setCables(n_ports);
      }
    
      void setPortName(uint8_t port, const char *name) {
        _midi.interface.setCableNameStringIndex(port, _device.device->addStringToIndex(name));
      }
    
    opened by kaysievers 2
  • Boot keyboard is not able to enter BIOS

    Boot keyboard is not able to enter BIOS

    Operating System

    Linux

    IDE version

    5.2.0

    Board

    lolin_s2_mini

    ArduinoCore version

    2.0.5

    TinyUSB Library version

    1.14.4

    Sketch (attached txt file)

    main.txt

    What happened ?

    Unable to enter BIOS without reseting board during boot-up. It can be fixed by doing detach and attach or HW reset.

      TinyUSBDevice.detach();
      delay(100);
      TinyUSBDevice.attach();  
    

    How to reproduce ?

    1. Power on boot keyboard
    2. Try to enter BIOS

    Debug Log

    boot_usb_kbd.txt

    USBD Xfer Complete on EP 80 with 0 bytes
      Queue EP 83 with 8 bytes ...                          <- should there be complete for this EP?
    
    USBD Setup Received 80 06 00 01 00 00 12 00 
      Get Descriptor Device
      Queue EP 80 with 18 bytes ...
    USBD Xfer Complete on EP 80 with 18 bytes
    

    Screenshots

    No response

    Bug 
    opened by tomaszduda23 0
  • Any examples using this library to create a USB HID Power Device (UPS)?

    Any examples using this library to create a USB HID Power Device (UPS)?

    Prior art for Arduino HID UPS: https://github.com/abratchik/HIDPowerDevice

    An example on how to use this library to create a HID UPS would be really nice to have.

    Feature 
    opened by rickbassham 0
  • USB MIDI device name not being changed

    USB MIDI device name not being changed

    Operating System

    Windows 10

    IDE version

    Arduino 1.8.19

    Board

    Wemos ESP32-S2 Mini

    ArduinoCore version

    Espressif Systems Version 2.0.3

    TinyUSB Library version

    Version 1.14.3

    Sketch (attached txt file)

    #include <Arduino.h>
    #include <Adafruit_TinyUSB.h>
    #include <MIDI.h>
    
    // USB MIDI object
    Adafruit_USBD_MIDI usb_midi;
    
    // Create a new instance of the Arduino MIDI Library,
    // and attach usb_midi as the transport.
    MIDI_CREATE_INSTANCE(Adafruit_USBD_MIDI, usb_midi, MIDI);
    
    // Variable that holds the current position in the sequence.
    uint32_t position = 0;
    
    // Store example melody as an array of note values
    byte note_sequence[] = {
      74,78,81,86,90,93,98,102,57,61,66,69,73,78,81,85,88,92,97,100,97,92,88,85,81,78,
      74,69,66,62,57,62,66,69,74,78,81,86,90,93,97,102,97,93,90,85,81,78,73,68,64,61,
      56,61,64,68,74,78,81,86,90,93,98,102
    };
    
    void setup()
    {
    #if defined(ARDUINO_ARCH_MBED) && defined(ARDUINO_ARCH_RP2040)
      // Manual begin() is required on core without built-in support for TinyUSB such as mbed rp2040
      TinyUSB_Device_Init(0);
    #endif
    
      pinMode(LED_BUILTIN, OUTPUT);
      
    //  usb_midi.setStringDescriptor("TinyUSB MIDI");
      TinyUSBDevice.setProductDescriptor("TinyUSB MIDI");
    
      // Initialize MIDI, and listen to all MIDI channels
      // This will also call usb_midi's begin()
      MIDI.begin(MIDI_CHANNEL_OMNI);
    
      // Attach the handleNoteOn function to the MIDI Library. It will
      // be called whenever the Bluefruit receives MIDI Note On messages.
      MIDI.setHandleNoteOn(handleNoteOn);
    
      // Do the same for MIDI Note Off messages.
      MIDI.setHandleNoteOff(handleNoteOff);
    
      Serial.begin(115200);
    
      // wait until device mounted
      while( !TinyUSBDevice.mounted() ) delay(1);
    }
    

    What happened ?

    The line:

    TinyUSBDevice.setProductDescriptor("TinyUSB MIDI");

    should apparently change the USB device's product name, but it doesn't. The Midi device is still detected as "LOLIN-S2-MINI"

    Also the line: usb_midi.setStringDescriptor("TinyUSB MIDI"); doesn't seem to do anything.

    How to reproduce ?

    Flash the code to the ESP32-S2 Mini board, connect it to the computer's USB port, open the MIDI Monitor software, and check the MIDI device In/Out ports name. It should have changed to what I set in the code, but it doesn't.

    There seems to be very little information about how to use this library on the internet, specially with midi. Perhaps I am doing something wrong as I am a beginner, but this looks like a bug to me. As I said, there is very little information on this subject. Or at least I cannot find it.

    Debug Log

    No response

    Screenshots

    No response

    Bug 
    opened by jhsa 0
  • FlushCDC Problem with arduino-pico core

    FlushCDC Problem with arduino-pico core

    Operating System

    Windows 10

    IDE version

    1.8.19

    Board

    Raspberry PICO

    ArduinoCore version

    2.3.3

    TinyUSB Library version

    1.14.1

    Sketch (attached txt file)

    #include <Adafruit_TinyUSB.h>
    
    void setup() {
      Serial.begin(115200);
    }
    
    void loop() {
      Serial.println("blink!");
      delay(200);               
    }
    

    What happened ?

    Even/odd loop iteration doesn't send data to PC. Data is stored in buffer and transferred on next loop cycle.

    How to reproduce ?

    Compile and upload sketch with arduino-pico core with TinyUSB stack and open serial port monitor.

    Debug Log

    No response

    Screenshots

    screen

    Bug 
    opened by s-t-e-p-a-n-o-v 6
Releases(1.17.0)
Owner
Adafruit Industries
Adafruit Industries
Arduino Arduino library for the CloudStorage server project. The library provides easy access to server-stored values and operations.

Arduino-CloudStorage Arduino/ESP8266 library that allows you to easly store and retreive data from a remote (cloud) storage in a key/value fashion. Cl

Gil Maimon 7 Jan 30, 2022
Arduino library for making an IHC in or output module using an Arduino

Introduction This is an Arduino library for making an IHC in or output module using an Arduino. (IHC controller is a home automation controller made b

Jens Ƙstergaard Nielsen 2 Mar 26, 2020
ArduinoIoTCloud library is the central element of the firmware enabling certain Arduino boards to connect to the Arduino IoT Cloud

ArduinoIoTCloud What? The ArduinoIoTCloud library is the central element of the firmware enabling certain Arduino boards to connect to the Arduino IoT

Arduino Libraries 64 Dec 16, 2022
Simple application log library. supporting multiple log levels, custom output & flash memory support.

ArduinoLog - C++ Log library for Arduino devices An minimalistic Logging framework for Arduino-compatible embedded systems. ArduinoLog is a minimalist

Thijs Elenbaas 132 Nov 12, 2022
Arduino library for controlling the MCP2515 in order to receive/transmit CAN frames.

107-Arduino-MCP2515 Arduino library for controlling the MCP2515 in order to receive/transmit CAN frames. This library is prepared to interface easily

107-Systems 51 Nov 16, 2022
Arduino library for interfacing with any GPS, GLONASS, Galileo or GNSS module and interpreting its NMEA messages.

107-Arduino-NMEA-Parser Arduino library for interfacing with any GPS, GLONASS, Galileo or GNSS module and interpreting its NMEA messages. This library

107-Systems 15 Jan 1, 2023
Arduino library for providing a convenient C++ interface for accessing UAVCAN.

107-Arduino-UAVCAN Arduino library for providing a convenient C++ interface for accessing UAVCAN (v1.0-beta) utilizing libcanard. This library works f

107-Systems 54 Jan 2, 2023
A RESTful environment for Arduino

aREST Overview A simple library that implements a REST API for Arduino & the ESP8266 WiFi chip. It is designed to be universal and currently supports

null 1.2k Dec 29, 2022
Arduino web server library.

aWOT Arduino web server library. Documentation 1. Getting started Hello World Basic routing Application generator Serving static files 2. Guide Routin

Lasse Lukkari 246 Jan 4, 2023
Arduino, esp32 and esp8266 library for ABB (ex PowerOne) Aurora Inverter, implement a full methods to retrieve data from the Inverter via RS-485

ABB Aurora protocol You can refer the complete documentation on my site ABB Aurora PV inverter library for Arduino, esp8266 and esp32 I create this li

Renzo Mischianti 22 Nov 22, 2022
MCP2515 CAN Controller Driver for Arduino

MCP2515 CAN Controller Library for Arduino Compatibility with the ACAN library This library is fully compatible with the Teensy 3.x ACAN library https

Pierre Molinaro 47 Dec 13, 2022
Arduino library for the MCP2515 CAN Controller

MCP2515 CAN Controller Library for Arduino Compatibility with the ACAN library This library is fully compatible with the Teensy 3.x ACAN library https

Pierre Molinaro 4 Dec 18, 2022
Arduino CAN driver for MCP2517FD CAN Controller (in CAN 2.0B mode)

MCP2517FD CAN Controller Library for Arduino (in CAN 2.0B mode) Compatibility with the other ACAN libraries This library is fully compatible with the

Pierre Molinaro 13 Dec 22, 2022
Distribution of Arduino driver for MCP2517FD CAN controller (CANFD mode)

MCP2517FD and MCP2518FD CAN Controller Library for Arduino (in CAN FD mode) Compatibility with the other ACAN libraries This library is fully compatib

Pierre Molinaro 31 Dec 21, 2022
CAN / CANFD Arduino Library for Teensy 4.0

CAN Library for Teensy 4.0 / 4.1 It handles Controller Area Network (CAN) for CAN1, CAN2 and CAN3, and Controller Area Network with Flexible Data (CAN

Pierre Molinaro 12 Dec 9, 2022
Unified interface for selecting hardware or software SPI implementations on Arduino platforms

AceSPI Unified interface for selecting hardware or software SPI implementations on Arduino platforms. The code was initially part of the AceSegment li

Brian Park 1 Oct 22, 2021
Unified interface for selecting different implementations for communicating with a TM1637 LED controller chip on Arduino platforms

AceTMI Unified interface for communicating with a TM1637 LED controller chip on Arduino platforms. The code was initially part of the AceSegment libra

Brian Park 0 Feb 2, 2022
Unified interface for selecting different I2C implementations on Arduino platforms

AceWire Wrapper classes that provide a simple, unified interface for different I2C implementations on Arduino platforms. The code was initially part o

Brian Park 7 Dec 14, 2022
Analog Devices Analog Digital Converter AD7173 Arduino library

AD7173-Arduino Analog Devices AD7173 analog digital converter Arduino library Mostly tested setup for this library: 1007 data rate external crystal co

brain-duino 8 Nov 20, 2022