Adafruit_TinyUSB_Arduino icon indicating copy to clipboard operation
Adafruit_TinyUSB_Arduino copied to clipboard

ESP32-S3 not being recognized as MIDI device on PC with Windows 10

Open jhsa opened this issue 6 months ago • 3 comments

Operating System

Windows 10

Arduino IDE version

Arduino IDE 2.3.5

Board

ESP32-S3 Dev Module

ArduinoCore version

ESP32 By Espressif Systems 3.2.0

TinyUSB Library version

Adafruit TinyUSB 3.5.0

Sketch as ATTACHED TXT

"midi_test.ino" Example

Compiled Log as ATTACHED TXT

N/A

What happened ?

Flashed the "midi_test.ino" example but the ESP32-S3 doesn't appear on the PC as a Midi device, but as "COM 17 (ESP32 Family Device).

How to reproduce ?

Same as explained above..

Debug Log

N/A

Screenshots

Image

jhsa avatar May 26 '25 16:05 jhsa

USB CDC on Boot must be Enabled, it is mentioned in the readme

hathach avatar May 29 '25 03:05 hathach

USB CDC on Boot must be Enabled, it is mentioned in the readme

I did compile it with USB CDC on Boot enabled, but I believe that DFU on boot must be disabled as well? I managed to make it work, well, sort of. There are a couple issues. The device is recognized and it works on my Android Smartphone, but it is not recognized on my PC with windows 10. Also, there is another problem when using this library on the ESP32-S3. If we want to have USB Midi and normal serial Midi working together, enabling the USB CDC on boot will prevent the Serial Midi from working and will even make the Board crash. We need to use Serial2 for the Serial Midi and configure pins as TX and RX. Example below. Anyway, the tittle of this topic is still valid as TinyUSB is not recognized as a Midi device by windows 10. I still have win7 on another partition and will test. Will report as soon as I have some time. Thank you for all..

#include <MIDI.h>
#include <HardwareSerial.h>

HardwareSerial MySerial(2); // define a Serial for UART1
const int MySerialRX = 11;
const int MySerialTX = 12;

MIDI_CREATE_INSTANCE(HardwareSerial, Serial2, MIDI);

void setup()
{
    pinMode(LED_BUILTIN, OUTPUT);
     Serial2.begin(31250, SERIAL_8N1, MySerialRX, MySerialTX);
    
    MIDI.begin(MIDI_CHANNEL_OMNI); 

     digitalWrite(LED_BUILTIN, HIGH);
    delay(200);
    
      MIDI.sendNoteOn(42, 127, 1);                  // Launch MIDI and listen to channel 4
digitalWrite(LED_BUILTIN, LOW);
}

void loop()
{
    if (MIDI.read())                    // If we have received a message
    {
        digitalWrite(LED_BUILTIN, HIGH);
        MIDI.sendNoteOn(42, 127, 1);    // Send a Note (pitch 42, velo 127 on channel 1)
        delay(1000);		            // Wait for a second
        MIDI.sendNoteOff(42, 0, 1);     // Stop the note
        digitalWrite(LED_BUILTIN, LOW);
    }
}

jhsa avatar May 29 '25 13:05 jhsa

I have just tested another project I have built based on a STM32 board with USBComposite library and it is recognized by windows 10. Could the problem be with the TinyUSB driver?

EDIT: TinyUSB works on a very old "Eee PC" notebook with Linux. EDIT1: It works on Windows 7 too..

jhsa avatar May 29 '25 14:05 jhsa

@jhsa I had the same problem and then noticed that my 'device' was being enumerated as ESP-DEV or JTAG. I removed this device in Device Manager and scanned for changes. The S3 now enumerated correctly.

It seems that Win10 / 11 hijacked the S3 and failed to release it as the S3 switched from the initial boot condition of JTAG to user defined TinyUSB device type.

Sounds like a timing issue with either TinyUSB or the S3 Core. But I've not had a problem since removing the device. I only had to do it once.

nikthefix avatar Jun 23 '25 11:06 nikthefix

did the stock midi_test example work for you ? device may already enumerated when MIDI.begin() is called. Try to detach and attach as the stock eaxmple.

hathach avatar Jul 05 '25 05:07 hathach

closed due to lack of response. Try the update stock midi_test, which include the detach/attach to see if that works for you.

hathach avatar Jul 17 '25 02:07 hathach

I am sorry, I couldn't find time to try this and also didn't have an S3 board to try it as I used it on my latest project. Just got another one, and I will update the library and try the stock midi_test sketch. Thank you.

jhsa avatar Jul 20 '25 21:07 jhsa

Ok, I have updated the TinyUSB library to the latest 3.7.1 (I think), and added the Detach/Attach code to my projects code as seen below. The result is the same as before. Windows 10 does NOT recognize the device. It shows up in "Device manager" under "Ports(COM & LPT)" as " USB Serial Device (COM21)" It does not show up as Midi Device. On android, it does show up as Midi device and I can send and receive Midi. But I must connect it to my phone wit the phone unlocked, otherwise it is not recognized.

Here is the code I have mentioned above and the Board settings.

//************ USB MIDI init ***************
  TinyUSBDevice.setManufacturerDescriptor("My_Manufacturer");
  TinyUSBDevice.setProductDescriptor("iL9_USB");
  // usb_midi.setStringDescriptor("iL9_USB");

  // Initialize MIDI, and listen to all MIDI channels
  // This will also call usb_midi's begin()
  MidiUsb.begin(MIDI_CHANNEL_OMNI);

  // If already enumerated, additional class driverr begin() e.g msc, hid, midi won't take effect until re-enumeration
  if (TinyUSBDevice.mounted()) {
    TinyUSBDevice.detach();
    delay(10);
    TinyUSBDevice.attach();
  }

  // Attach the handleNoteOn function to the MIDI Library. It will
  // be called whenever the Bluefruit receives MIDI Note On messages.
  MidiUsb.setHandleProgramChange(USB_ProgramChange);
  MidiUsb.setHandleControlChange(USB_ControlChange);

Image

jhsa avatar Jul 20 '25 22:07 jhsa

@jhsa Take a look in device manager (with the S3 board disconnected) and select 'show hidden devices' from the View drop down menu. Expand 'Universal Serial Bus Devices' If you see ESP_DEV or USB JTAG or similar then uninstall the device along with the driver if the option is offered. Restart PC.

I had the same problem not just with the midi example but with all the examples. In my case it turned out that if I forgot to 'Enable CDC on boot' or set 'USB-OTG (TinyUSB)' or both, from then on all examples would fail to enumerate properly even after I'd corrected the build settings and re-flashed. This behaviour is repeatable for me on two different Win10/11 computers. The stubborn ESP_DEV or USB JTAG entries re-appear if I deliberately misconfigure the build options.

nikthefix avatar Jul 21 '25 06:07 nikthefix

@jhsa Take a look in device manager (with the S3 board disconnected) and select 'show hidden devices' from the View drop down menu. Expand 'Universal Serial Bus Devices' If you see ESP_DEV or USB JTAG or similar then uninstall the device along with the driver if the option is offered. Restart PC.

I had the same problem not just with the midi example but with all the examples. In my case it turned out that if I forgot to 'Enable CDC on boot' or set 'USB-OTG (TinyUSB)' or both, from then on all examples would fail to enumerate properly even after I'd corrected the build settings and re-flashed. This behaviour is repeatable for me on two different Win10/11 computers. The stubborn ESP_DEV or USB JTAG entries re-appear if I deliberately misconfigure the build options.

This seems to have worked. I can now send and receive midi on my Windows 10 PC. Thank you so much.

@hathachThis explanation should perhaps be shared somewhere on the information page of the library.

jhsa avatar Jul 21 '25 15:07 jhsa

@jhsa Glad it worked for you too.

nikthefix avatar Jul 21 '25 15:07 nikthefix

@hathach For what it's worth I don't think the problem is with Adafruit_TinyUSB. I use the S2 as much as the S3 and have never had issues with the S2 even when I've inadvertently caused #VID #PID clashes thru reckless experimentation. Win10/11 did not exhibit a problem with either device until fairly recent updates of both. My Linux machines have no problem. I've also not had any problems anywhere since ESP_Arduino 3.2.1

nikthefix avatar Jul 21 '25 17:07 nikthefix

@hathach For what it's worth I don't think the problem is with Adafruit_TinyUSB. I use the S2 as much as the S3 and have never had issues with the S2 even when I've inadvertently caused #PID clashes thru reckless experimentation. Win10/11 did not exhibit a problem with either device until fairly recent updates of both. My Linux machines also have no problem. I've also not had any problems anywhere since ESP_Arduino 3.2.1

Oh, I have just noticed I still have 3.2.0 ESP Boards version.. Will update shortly. Thank you.

jhsa avatar Jul 21 '25 17:07 jhsa

@jhsa let me know how is your testing with latest version. We can re-open this issue if needed.

hathach avatar Jul 28 '25 05:07 hathach

@jhsa let me know how is your testing with latest version. We can re-open this issue if needed.

Yeah, it is still working, thank you. I have the last version installed. I also followed the workaround mentioned before, and that made it work. after that I already compiled different codes with different CDC options, and it seems my USB projects are still recognized on my windows 10 PC. I have another PC that never ran Midi that I could also test. Thank you so much for looking into this. Amazing library... Now if we could make USB MIDI Host work, that would be wonderful :D

jhsa avatar Jul 28 '25 15:07 jhsa

@hathach @jhsa Tested with ESP V3.3.0 - all working. However, I'm still able to cause the problem if I deliberately set the build options wrongly, recovering only by deleting the JTAG device in Device Manager as outlined above. This will be a gotcha for many I imagine.

I'll also test with the P4 to see if I can reproduce this (using ESP V3.3.0 / Adafruit Tiny_USB V3.7.1).

nikthefix avatar Jul 28 '25 16:07 nikthefix

@hathach @jhsa Tested with ESP V3.3.0 - all working. However, I'm still able to cause the problem if I deliberately set the build options wrongly, recovering only by deleting the JTAG device in Device Manager as outlined above. This will be a gotcha for many I imagine.

Yeah, I think your solution should be mentioned on the Library's main page.

jhsa avatar Jul 28 '25 18:07 jhsa

maybe windows cached the driver and does not do a full configuration parser. I don't know why this is not the case with S2. Maybe it is something specific to the S3. I will consider to add this note to the readme later. Thanks all for testing and walkaround.

hathach avatar Jul 29 '25 03:07 hathach

@hathach I thought it might be something like this but the USB examples supplied with the ESP_Arduino core do enumerate correctly even when the dreaded JTAG device is present in Device Manager. Using TinyUSB with IDF also works without issue.

nikthefix avatar Jul 29 '25 11:07 nikthefix

Hi, I also have the same or similar problem. I'm building with PlatformIO on VSCode. I've tried two types of Lilygo boards: t-display-s3 and t-embed-s3. Tried both Windows 10 and Windows 11. In Device Manager I've tried deleting drivers, scanning for new hardware, and rebooting my PC, all as described above. The results are the always the same every time i.e. the programmed esp32-s3 appears as a COM port and as a JTAG device. Any new ideas or tests to run please?

AtmosphEng avatar Aug 06 '25 06:08 AtmosphEng

@AtmosphEng When you see the JTAG device in Device Manager, delete the driver as well as the device. Something else to try is connecting your S3 board via a USB 2 hub to the PC. Someone in another thread found that this introduced a small timing difference at enumeration / negotiation and cured the problem all the while the hub was used.

Not a very satisfactory solution (if it works for you) but it would then hint at the problem being something to do with a race condition or similar.

nikthefix avatar Aug 06 '25 08:08 nikthefix

@nikthefix Thanks for your quick reply. When I 'delete' the driver in Device Manager, I right-click on the 'USB JTAG/serial debug unit' and select Uninstall device - it only ever gives me the option to uninstall, and never offers me a delete driver option. Do you also delete the COM port which also appears with the JTAG driver? I've tried this also, but had no success. I've also tried 3x different USB2 hubs as you suggested but again unfortunately no success. Where exactly and how does your MIDI device driver show in Device Manager when it works for you?

AtmosphEng avatar Aug 06 '25 09:08 AtmosphEng

@AtmosphEng You might have missed a little detail on the following post above from "nikthefix". Please read the bit that says "Show Hidden Devices..."

Take a look in device manager (with the S3 board disconnected) and select 'show hidden devices' from the View drop down menu. Expand 'Universal Serial Bus Devices' If you see ESP_DEV or USB JTAG or similar then uninstall the device along with the driver if the option is offered. Restart PC.

I had the same problem not just with the midi example but with all the examples. In my case it turned out that if I forgot to 'Enable CDC on boot' or set 'USB-OTG (TinyUSB)' or both, from then on all examples would fail to enumerate properly even after I'd corrected the build settings and re-flashed. This behaviour is repeatable for me on two different Win10/11 computers. The stubborn ESP_DEV or USB JTAG entries re-appear if I deliberately misconfigure the build options.

jhsa avatar Aug 06 '25 13:08 jhsa

@jhsa Thanks for the reply, I double checked on uninstalling the hidden devices - I removed both COM and USB JTAG hidden devices and rebooted a Win10 and a Win11 PC. Unfortunately no improvement. Maybe I have some build differences from you as I'm building from PlatformIO, not the Arduino IDE. FYI the settings I am using in platformio.ini are: -D ARDUINO_USB_ON_BOOT=1 -D ARDUINO_USB_MODE=1 A post from SuGlider says the definitions mean the following: ARDUINO_USB_MODE=0 ==>for USB OTG (S2 and S3) ARDUINO_USB_MODE=1 ==> for USB HW JTAG Serial CDC (for S3, C3, C6 and H2) ARDUINO_USB_CDC_ON_BOOT=1 ==> it will make Serial to be the USB CDC port ARDUINO_USB_CDC_ON_BOOT=0 ==> it will make Serial to be the UART0 port

AtmosphEng avatar Aug 06 '25 15:08 AtmosphEng

@AtmosphEng Ah!, for the Adafruit TinyUSB examples to work the build options should be:

-D ARDUINO_USB_ON_BOOT=1 (CDC on boot enable) -D ARDUINO_USB_MODE=0 (OTG mode enable, USB-JTAG disable)

Check the TinyUSB readme for details. With your configuration the USB-JTAG device appearance is expected behavior and possibly nothing to do with the issues raised above.

My usb-midi devices appear in Device manager under 'Sound, video and game controllers'. In S3 OTG mode you may have to be in bootloader to upload new sketches - hold 'boot' button while tapping 'reset' button. After upload power cycle the board as it may not autorun the new sketch. This is rather board dependent.

BTW, the option to delete the driver as well as the device in Device Manager (win10/11) is often only presented if the physical device is either disconnected or deactivated. If the driver is currently system loaded then the option is likely not available.

So in order to 'see' and delete disconnected but registered devices you must enable 'show hidden devices' in Device manager. While you're there it might be worth cleaning out all the redundant historical com ports, usb devices etc which windows accumulates - especially on a developer's PC. In my experience these 'ghost' entries can cause problems.

nikthefix avatar Aug 07 '25 08:08 nikthefix

@hathach Looking at this thread:

https://github.com/hathach/tinyusb/issues/2943

It seems that a similar issue was raised and a solution presented here:

https://github.com/espressif/esp-idf/commit/9c8517045c207c6617bd4e34b263c4cf5c0fee1b

Do you know if this change was migrated to the pre-compiled headers in the latest Arduino_ESP core? Thank you for your terrific work!

nikthefix avatar Aug 07 '25 09:08 nikthefix

@nikthefix WOOHOO - success with midi_test.ino, many thanks. I did try earlier in PlatformIO the required USB settings of: -D ARDUINO_USB_ON_BOOT=1 (CDC on boot enable) -D ARDUINO_USB_MODE=0 (OTG mode enable, USB-JTAG disable) but I got dozens of warnings about redefinition of "ARDUINO_USB_MODE" and dozens of linker errors specifying multiple definitions of USB functions. After searching today I found the following workaround at https://community.platformio.org/t/new-tinyusb-doesnt-allow-compile/44281. After rolling back to Adafruit TinyUSB Library 3.3.1 the linker errors were removed. I was then able to see in Windows 11 Device Manager: Sound, video and game controllers > TinyUSB MIDI. I tried outputting some simple midi from Waveform Free DAW to the new USB Device TinyUSB MIDI. I modified midi_test.ino to output the print testing to Serial2 at 115200-8-n-1 and got the text of the corresponding notes played by the DAW. No more loopMIDI and Hairless Serial Bridge with this setup. Again, many thanks to @nikthefix and all.

AtmosphEng avatar Aug 07 '25 09:08 AtmosphEng

@jhsa FYI for a USB Host demo working on a Lilygo t-display-s3 board, you could have a look at: https://github.com/sauloverissimo/ESP32_Host_MIDI

AtmosphEng avatar Aug 07 '25 10:08 AtmosphEng

@AtmosphEng Glad you got it working. Please post here if you encounter any of the above issues in USB OTG mode.

Yes I've had good results with USB Host on the S3 too. Of particular interest to me is host CDC: https://github.com/bertmelis/USBHostSerial

This allows, say, an ESP32-S3 to speak to an Arduino Nano via USB. Useful for man-In-the-middle GRBL injection of jog controls for CNC (for example).

nikthefix avatar Aug 07 '25 13:08 nikthefix