Esp32-S3 TinyUSB config not working

Hello,

I am struggling to manage to have my ESP32-S3-DevKitC-1 N8R2 being recognized as a USB MIDI peripheral (or any other USB descriptor) using the adafruit_tinyusb library.
I am reaching out there as I spent quite some time on it and running out of ideas.

While I was about to give up, I tried using the arduino IDE, and it works when compiled there.
Also, things are working when using platformio and an esp32-s2 lolin mini.

But platformio+esp32s3, not working…

Debug shows the code boots but stops at end of setup in

while( !TinyUSBDevice.mounted() ) delay(1); 

Which make sense as it never gets detected in device manager and stays stuck in the while loop.

I struggle to know if my json board configuration is wrong or if there is a deeper issue.

Here is my board config file:

  "build": {
    "arduino":{
      "ldscript": "esp32s3_out.ld",
      "partitions": "default_8MB.csv",
      "memory_type": "qio_qspi"
    },
    "core": "esp32",
    "extra_flags": [
      "-DARDUINO_ESP32S3_DEV",
      "-DBOARD_HAS_PSRAM",
      "-DARDUINO_USB_MODE=1",
      "-DARDUINO_RUNNING_CORE=1",
      "-DARDUINO_EVENT_RUNNING_CORE=1",
    ],
    "f_cpu": "240000000L",
    "f_flash": "80000000L",
    "flash_mode": "qio",
    "psram_type": "qspi",
    "hwids": [
      [
        "0x303A",
        "0x1001"
      ]
    ],
    "mcu": "esp32s3",
    "variant": "esp32s3"
  },
  "connectivity": [
    "wifi"
  ],
  "debug": {
    "default_tool": "esp-builtin",
    "onboard_tools": [
      "esp-builtin"
    ],
    "openocd_target": "esp32s3.cfg"
  },
  "frameworks": [
    "arduino",
    "espidf"
  ],
  "name": "Espressif ESP32-S3-DevKitC-1-N8R2",
  "upload": {
    "flash_size": "8MB",
    "maximum_ram_size": 327680,
    "maximum_size": 8388608,
    "require_upload_port": true,
    "speed": 460800
  },
  "url": "https://docs.espressif.com/projects/esp-idf/en/latest/esp32s3/hw-reference/esp32s3/user-guide-devkitc-1.html",
  "vendor": "Espressif"
}

And here is my platformio.ini


[env:esp32-s3-devkitc-1-N8R2]
platform = espressif32
board = esp32-s3-devkitc-1-N8R2
framework = arduino

upload_port = COM10
monitor_port = COM10
monitor_speed = 115200

build_flags =
-DUSE_TINYUSB

lib_archive = no
lib_deps =
adafruit/Adafruit TinyUSB Library@^2.2.1
fortyseveneffects/MIDI Library@^5.0.2

Tried to switch USB_DE and CDC mode, but no matter the board descriptor won’t change

Any ideas ?

  1. What Arduino-ESP32 core version do you have installed in the Arduino IDE? (Tools->Board->Board Manager → esp32)
  2. Screenshot / Listing of every Arduino IDE → Tools settings with which it works in the Arduino IDE?
  3. Minimal, reproducable example code?

Hello,

Thanks for looking at it.

1- I believe the Arduino ESP32 core version is 2.0.9 (I deduce it from this path: C:\Users\user\AppData\Local\arduino15\packages\esp32\hardware\esp32\2.0.9)

2-Working Arduino config is

3- minimal code

#include <Arduino.h>
#include <Adafruit_TinyUSB.h>
#include <MIDI.h>

Adafruit_USBD_MIDI usb_midi;
MIDI_CREATE_INSTANCE(Adafruit_USBD_MIDI, usb_midi, MIDI);

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
  MIDI.begin(MIDI_CHANNEL_OMNI);

  Serial.begin(115200);
  while (!TinyUSBDevice.mounted()) delay(1);
}

unsigned long previous=0;

void loop() {
    unsigned long current=millis();
    if (current-previous>800)
    {  
      MIDI.sendNoteOn(100, 127, 1);
      Serial.println("send");
      previous=current;
    }
  MIDI.read();  
}

Well you do select “USB Mode: USB-OTG (TinyUSB)” in the Arduino IDE, which per boards.txt is

But in PlatformIO you give it

I noticed this too. And tried both usb modes. Also tried enabling cdc on boot (which is also ticked in the arduino ide)
Still I will try again and confirm
Unfortunately none of those resolve the issue

And you also have the most recent platform-espressif32 installed so that PlatformIO gets the same core version? E.g., use CLIpio pkg update -g -p espressif32.

Yep. reinstalled recently, and ran the update command line. Have indeed the same esp32 core in platformio 2.0.9.

Added CDC enabled as my arduino config.
Check more detailed debug level and after boot, I get :

While the code seems to instruct the switch, still not detected in the device manager…

Meaning only CDC is detected in Windows but MIDI not at all?

Yep.

This is what I get And nothing in the sound section, as I could get with s2 for eg.
image
Both COM17 and Espressif device correspond to the USB-OTG port.
COM10 is the UART port.

It seems there is also an issue open in ESP32-S3 not appearing as a MIDI device · Issue #279 · adafruit/Adafruit_TinyUSB_Arduino · GitHub, so that’s link that here.

You have tried out other Adafruit TinyUSB versions per PlatformIO Registry?

Which version of the library do you have installed in the Arduino IDE? (<Documents\Arduino\libraries\Adafruit TinyUSB\library.properties)

Yep. the issue seems similar. But seems there is not much activity there.

I might try different version of the library, but the actual Adafruit TinyUSB version are same in arduino and platformio, 2.2.1.

When looking around, I noticed in the tusb_config.h of the s3, that one line is defined as it would be for the s2. As I don’t really know what this constant is used for, I am unsure wherther it could be an issue.
But as this is part of the framework, I guess it is intentional, would be surprised this would be wrong.
Just a hint:
#define CFG_TUSB_MCU OPT_MCU_ESP32S2

Another project brought me back here,
digged a bit further, and finally I reached a working config.
I confirm this is purely platformio related.

The following ini config works with an esp32-s3 Devkit c1 N8R2:

platform = espressif32
board = esp32-s3-devkitc-1
framework = arduino
build_unflags = -DARDUINO_USB_MODE=1
build_flags = 
	-DUSE_TINYUSB=1
	-DARDUINO_USB_MODE=0
	-DARDUINO_USB_CDC_ON_BOOT=1
	'-DCFG_TUSB_CONFIG_FILE="/Users/rup/.platformio/packages/framework-arduinoespressif32/tools/sdk/esp32s3/include/arduino_tinyusb/include/tusb_config.h"'
lib_archive = no
lib_deps = 
	lathoub/BLE-MIDI@^2.2
	max22/ESP32-BLE-MIDI@^0.3.2
	fortyseveneffects/MIDI Library@^5.0.2
	adafruit/Adafruit TinyUSB Library@^3.1.0

I am unsure how this should be dealt with for future proof solution. Should a issue be filed somewhere so that it gets corrected ?
The include order problem and library archive option are beyond my undersanding of the compilation process, but I feel like the manual addition of the tinyusb config file is not the long term solution :slight_smile:

By the way, I struggled to find my way in the mapping between arduino IDE settings, and the corresponding build flags in platformio. Anybody has a table or an reference to point to ?

1 Like

would you be able to share this project (or something stripped down) on github?

Thanks, im going to give this a test now