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.
Issues
  • 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
  • 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
  • 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 11
  • 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
  • Remove the need for periodical timer to run usb task for rp2040

    Remove the need for periodical timer to run usb task for rp2040

    Is your feature request related to a problem? Please describe. Currently rp2040 port use an periodic timer to run usb task, triggered every 1ms, which is pretty wasteful.

    https://github.com/adafruit/Adafruit_TinyUSB_Arduino/blob/5be0b21c0a5cf396b139bce0c6c0d403df051b0a/src/arduino/ports/rp2040/Adafruit_TinyUSB_rp2040.cpp#L84-L91

    Describe the solution you'd like We should make use of https://github.com/hathach/tinyusb/pull/1519 to register an shared IRQ to know when to invoke usb task.

    Feature RP2040 
    opened by hathach 0
  • Xinput support - emulate xbox 360 controllers

    Xinput support - emulate xbox 360 controllers

    Is your feature request related to a problem? Please describe. Existing solutions for xinput and the RP2040/pico require platform.io and other unstable solutions which are difficult to use.

    I am attempting to make a 4 player xinput solution for arcade cabinets

    Describe the solution you'd like Add xinput to the Adafruit_TinyUSB library similar to this:

    Describe alternatives you've considered I have am using David Madison's xinput library for Arduino in my arcade cabinet now, but it is slower to initilize and not as nice for flashing. RP2040 availability is also better for building custom boards.

    Additional context

    Arduino 32U4 and Teensy xinput library: https://github.com/dmadison/ArduinoXInput https://www.partsnotincluded.com/understanding-the-xbox-360-wired-controllers-usb-data/ (Extremely versbose explaination of xinput) https://www.partsnotincluded.com/xbox-360-controller-led-animations-info/ (details about the player LED data - LED data is useful for trying to build multiplayer controllers)

    Example project with RP2040 and xinput option (also nintendo switch): https://github.com/FeralAI/GP2040 (older version) https://github.com/OpenStickFoundation/GP2040-CE (Newer community fork under active development) https://discord.gg/kbU9FC2v (Discord channel with firmware developer channel - massive amounts of info regarding game controllers)

    composite libary for ST F1/F4 with xinput AND multiple Xinput on a single MCU (This would be amazing to have in arduino) https://github.com/arpruss/USBComposite_stm32f1

    Feature 
    opened by leecyrille 2
  • Support of Adafruit Feather STM32F405 Express

    Support of Adafruit Feather STM32F405 Express

    I bought a Feather board and I expected that will work with Adafruit ecosystem. This library does not support Adafruit Feather STM32F405 Express even it have native USB.

    I would like this library to support all the Adafruit products it can support.

    Feature 
    opened by eLEcTRiCZiTy 1
  • [Feature] USB Host functionality

    [Feature] USB Host functionality

    I have a USB peripheral (GPS puck) that I would like to read into an ESP32-S2 board. I naively thought this was going to be simple, but am now realizing it is quite nuanced. From what I understand, using USB_CDC is not realistic since the ESP32 board needs to be USB-host. Additionally, from what I understand, the tinyUSB library (https://github.com/hathach/tinyusb) supports USB-Host, but this library does not. I have been pointed to this library (https://github.com/chegewara/EspTinyUSB) in the meantime for USB-host functionality, but I believe it would be a good fit in this current library as well.

    opened by aschueth 1
  • Enable library for Arduino SAMD based on USBCON

    Enable library for Arduino SAMD based on USBCON

    TinyUSB can be used without explicitly defining USE_TINYUSB. This is useful for cores without built-in support for the define.

    Related PR: arduino/ArduinoCore-samd#668

    opened by Spegs21 1
  • use keydown event since keypress is not supported by Android

    use keydown event since keypress is not supported by Android

    as mentioned by https://github.com/adafruit/Adafruit_TinyUSB_Arduino/issues/26#issuecomment-1011587617 keypress event is not supported by chrome on Android. Change to use keydown event

    opened by hathach 0
Releases(1.14.2)
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 60 Jul 20, 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 126 Jul 30, 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 46 Aug 3, 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 12 May 16, 2022
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 49 Jul 24, 2022
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 Jul 27, 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 235 Jul 21, 2022
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 20 May 30, 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 40 Jul 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 3 Oct 1, 2021
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 11 Jun 10, 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 27 Jul 19, 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 9 Jul 6, 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 4 Feb 3, 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 Jan 13, 2022