ESP32-S3 Midi over usb not working

Hello All!

I got an esp32-s3, to make an MIDI controller (i’m mostly interested in USB), but it only shows up as an USB JTAG/Serial unit or ESP32-S3 (even if it goes into the otg mode, it doesn’t initialise as an midi class device).
I had tried custom board.json, MANY build flags, additional .py scripts, and it just doesnt work. If this wasn’t frustraiting enough, it works perfectly when flashed from ArduinoIDE, or when i run the MIDI example from ESP-IDF (I don’t want to use either tool, becouse one doesnt have proper IDE funcionality, and other having unnatural sytax).
I tried using platformIO.ini from this thread, but it doesn’t work too.
This is my code:

#include <Arduino.h>
#include <Control_Surface.h>

USBMIDI_Interface midi;
CCPotentiometer pot {1, MIDI_CC::General_Purpose_Controller_1};

void setup() {
delay(100);
Control_Surface.begin();
}

void loop() {
Control_Surface.loop();
}

My Platformio.ini
v1

[env:esp32s3]
platform = espressif32
board = esp32-s3-devkitc-1
framework = arduino
lib_deps =
    tttapa/Control Surface@^2.1.0
build_flags =
  -D ARDUINO_USB_MODE=0
  -D ARDUINO_USB_CDC_ON_BOOT=0

v2

[env:esp32-s3-devkitc-1-midi]
platform = espressif32
board = esp32s3_midi
framework = arduino
lib_deps =
    tttapa/Control Surface@^2.1.0
upload_protocol = esptool
build_flags =
  -D USB_PRODUCT="S3_MIDI_Mixer"

v3

[env:esp32-midi]
platform = espressif32
board = esp32-s3-devkitc-1
framework = arduino
monitor_speed = 115200
build_flags = -DARDUINO_USB_CDC_ON_BOOT=1
lib_deps =
  tttapa/Control Surface@^2.1.0

Custom esp32s3_midi.json

{
{
  "build": {
    "arduino": {
      "ldscript": "esp32s3_out.ld",
      "partitions": "default_8MB.csv"
    },
    "core": "esp32",
    "extra_flags": [
      "-DARDUINO_ESP32S3_DEV",
      "-DARDUINO_USB_MODE=0",
      "-DARDUINO_USB_CDC_ON_BOOT=0",
      "-DARDUINO_USB_DFU_ON_BOOT=0",
      "-DARDUINO_USB_MSC_ON_BOOT=0",
      "-DARDUINO_RUNNING_CORE=1",
      "-DARDUINO_EVENT_RUNNING_CORE=1"
    ],
    "f_cpu": "240000000L",
    "f_flash": "80000000L",
    "flash_mode": "qio",
    "hwids": [
      "0x303A",
      "0x1001"
    ],
    "mcu": "esp32s3",
    "variant": "esp32s3"
  },
  "frameworks": [
    "arduino",
    "espidf"
  ],
  "name": "ESP32-S3 MIDI",
  "upload": {
    "flash_size": "4MB",
    "maximum_ram_size": 327680,
    "maximum_size": 4194304,
    "require_upload_port": true,
    "speed": 921600
  },
  "vendor": "Espressif",
  "url": "anton.com"
}

Arduino build flags

USB CDC On Boot: “Disabled”
CPU Frequency: “240MHz (WiFi)”
Core Debug Level: “None”
USB DFU On Boot: “Disabled”
Erase All Flash Before Sketch Upload: “Disabled”
Events Run On: “Core 1”
Flash Mode: “QIO 80MHz”
Flash Size: “4MB (32Mb)”
JTAG Adapter: “Disabled”
Arduino Runs On: “Core 1”
USB Firmware MSC On Boot: “Disabled”
Partition Scheme: “Default 4MB with spiffs (1.2MB APP/1.5MB SPIFFS)”
PSRAM: “Disabled”
Upload Mode: "UARTO / Hardware CDC”
Upload Speed: “921600”
USB Mode: “USB-OTG (TinyUSB)”
Zigbee Mode: “Disabled”

Thanks in advance!

You can’t set USB Mode 0 if 1 is the the default in the board definition.

Unset it properly with

build_unflags = 
  -DARDUINO_USB_MODE=1

first.