back to Arduino and ESP32-S2-Saola-1

Add TinyUSB to your project

TinyUSB Geneology

Adafruit ported TinyUSB to ESP32-S2 for Metro and FeatherS2 products,
mostly with CircuitPython but also the Arduino IDE.
Adafruit TinyUSB support:
Adafruit TinyUSB Library
GitHub releases
adafruit has https://github.com/adafruit/Adafruit_TinyUSB_Arduino and TinyUF2 Bootloader
  Their ESP32 port depends on Espressif's esp32-hal-tinyusb.c for building USB descriptors.
adafruit also has a WebUSB guide

ESP32TinyUSB

This appears to be Expressif's "official" USB library implementation
  • ESP32TinyUSB Arduino link
  • ESP32TinyUSB is the chegewara / EspTinyUSB implementation with seemingly useful example sketches..
    It includes device examples updated to work with esp32s2
  • Arduino ESP32TinyUSB library reference (points back to GitHub).
    Builds disabling e.g. MSC filesystem support require source code hacking...
  • ESP32-S2 TinyUSB composite reconfiguration
  • limited endpoints
    • ESP32-S2 provides 6 endpoint pairs, not counting pair 0.
      Only 5 IN endpoints can be active at a time, so usually just 5 pairs available.
    • Device endpoint requirements for each instance:
      • Endpoint pair 0 is always reserved for USB setup and control
      • MIDI: 1 IN/OUT pair
      • CDC: 1 IN/OUT pair for data + 1 IN endpoint for control
      • HID: 1 IN/OUT pair
    • MIDI was broken by midiusb.cpp:#define EPNUM_MIDI 0x05; fix by changing to 0x04
    • current assignments:
      grep -R EPNUM_ libraries | grep 0x | grep define
      libraries/ESP32TinyUSB/src/device/cdc/cdcusb.cpp:#define EPNUM_CDC   0x02
      libraries/ESP32TinyUSB/src/device/hid/hidcomposite.cpp:#define EPNUM_HID 0x03
      libraries/ESP32TinyUSB/src/device/hid/hidgamepad.cpp:#define EPNUM_HID   0x03
      libraries/ESP32TinyUSB/src/device/hid/hidgeneric.cpp:#define EPNUM_HID   0x03
      libraries/ESP32TinyUSB/src/device/hid/hidkeyboard.cpp:#define EPNUM_HID 0x02
      libraries/ESP32TinyUSB/src/device/hid/hidmouse.cpp:#define EPNUM_HID 0x03
      libraries/ESP32TinyUSB/src/device/hid/hidusb.cpp:#define EPNUM_HID   0x03
      libraries/ESP32TinyUSB/src/device/midi/midiusb.cpp:#define EPNUM_MIDI 0x04
      libraries/ESP32TinyUSB/src/device/msc/mscusb.cpp:#define EPNUM_MSC 0x04
      libraries/ESP32TinyUSB/src/webusb.h:#define EPNUM_VENDOR 0x04
      
    • This should allow CDC (1 & 2), gamepad (3) and MIDI (4) to play together..
    • EspTinyUSB configuration (including serial number) is discussed here
    • If more than one ESP32-S2 module will be connected to a single USB host (e.g., Windows PC),
      different serial numbers should be set

TinyUSB MIDI

Create Custom USB Devices with the esp32s2Stick

ESP32-S2 Hardware USB connection

USB cable preparation

USB GND should be connected to ESP32-S2 Board GND
USB signalling is differential, but signal voltages are still relative to device ground.

USB CDC device

  • Provided cdc.ino sketch loaded and ran fine, after re-enabling MSC and DFU devices...

USB HID device

  • Provided gamepad.ino sketch loaded and ran,
  • joy.cpl detected ESP32S2 arduino device, but Test showed no activity...
    • Serial message were added to the sketch;
      if(!digitalRead(0)) was never true while using joy.cpl...
    • Another Gamepad.ino had no such test.
    • ESP32S2 arduino devices > Properties > Test
      got busy after rebuilding with that test defeated.
    • Meanwhile, there was also a LOT of serial traffic from Hidusb.cpp:
      ...
      ...
      [ 74914][D][hidusb.cpp:37] write(): len: 11
      [ 75013][D][hidusb.cpp:36] write(): write hid: 
      [ 75014][D][hidusb.cpp:37] write(): len: 11
      [ 75113][D][hidusb.cpp:36] write(): write hid: 
      [ 75114][D][hidusb.cpp:37] write(): len: 11
      ...
    • Commenting out 2 logging lines in hidusb.cpp stiffled that traffic.
  • Note:   Windows' Game Controllers > Test only updates while it has focus.

USB MIDI device

  • using Midi View to look for EspTinyUSB-2.0.0 MIDI traffic
  • midi-test loaded and ran, but no MIDI device was detected
  • midi.ino loaded and ran; MIDI CLASS was detected, but with no traffic, despite serial monitor output:
    ESP-ROM:esp32s2-rc4-20191025
    Build:Oct 25 2019
    rst:0x1 (POWERON),boot:0x8 (SPI_FAST_FLASH_BOOT)
    SPIWP:0xee
    mode:DIO, clock div:2
    load:0x3ffe6100,len:0x570
    load:0x4004c000,len:0xa50
    load:0x40050000,len:0x28d8
    entry 0x4004c18c
    [   580][D][usb_descriptors.cpp:45] getConfigurationDescriptor(): descriptor length: 101
    
    [   581][D][esptinyusb.cpp:48] esptinyusbtask(): USB tud_task created
    [  1582][V][midiusb.cpp:88] setSong(): MThd format => 0
    
    MTrk
    [  1583][V][midiusb.cpp:103] setSong(): song => 40, i = 40
    
    invoking midi.playSong()
    [  1593][V][midiusb.cpp:145] playSong(): play
    [  1594][V][midiusb.cpp:151] playSong(): delta => 40, _byte = 90
    
    [  2106][V][midiusb.cpp:28] noteON(): ON: 65
    
    [  2107][V][midiusb.cpp:181] playSong(): on
    [  2107][V][midiusb.cpp:151] playSong(): delta => 0, _byte = 90
    
    [  2109][V][midiusb.cpp:28] noteON(): ON: 60
    
    [  2113][V][midiusb.cpp:181] playSong(): on
    [  2117][V][midiusb.cpp:151] playSong(): delta => 0, _byte = 90
    ...
    • commented out log_v's in midiusb.cpp:
      ESP-ROM:esp32s2-rc4-20191025
      Build:Oct 25 2019
      rst:0x1 (POWERON),boot:0x8 (SPI_FAST_FLASH_BOOT)
      SPIWP:0xee
      mode:DIO, clock div:2
      load:0x3ffe6100,len:0x570
      load:0x4004c000,len:0xa50
      load:0x40050000,len:0x28d8
      entry 0x4004c18c
      [   558][D][usb_descriptors.cpp:45] getConfigurationDescriptor(): descriptor length: 101
      
      [   558][D][esptinyusb.cpp:48] esptinyusbtask(): USB tud_task created
      [  1560][V][midiusb.cpp:88] setSong(): MThd format => 0
      [  1561][V][midiusb.cpp:95] setSong(): MTrk
      [  1561][V][midiusb.cpp:103] setSong(): song => 40, i = 40
      invoking midi.playSong()
      [  1574][V][midiusb.cpp:145] playSong(): play
      [ 94030][V][midiusb.cpp:135] parseMeta(): meta => 2f, n = 2
      [ 94031][V][midiusb.cpp:191] playSong(): unknown note: x0
      [ 94526][V][midiusb.cpp:191] playSong(): unknown note: x30
      [ 95334][V][midiusb.cpp:191] playSong(): unknown note: x0
      [ 97702][V][midiusb.cpp:171] playSong(): ctrl x0 x0
      [ 97870][V][midiusb.cpp:191] playSong(): unknown note: x14
      [ 99886][V][midiusb.cpp:191] playSong(): unknown note: x3f
      [101926][V][midiusb.cpp:135] parseMeta(): meta => 3f, n = ffffffff

GitHub:




maintained by blekenbleu