ESP32-S3 USB Port uploads but serial comms are not working.

Chevelle
Posts: 19
Joined: Sun Nov 29, 2020 12:50 pm

ESP32-S3 USB Port uploads but serial comms are not working.

Postby Chevelle » Fri Aug 30, 2024 12:54 pm

Hi. Below is a test program I am using for a project that uses am ESP32-S3 device. I am using the USB-to-Serial internal support (pins 19 & 20) for both uploading the code as well as serial communications when the application is running. Oddly, the code uploads fine. The odd thing is that I cannot establish serial comminications over the port. Windows10 sees the port as open and the serial terminal opens for that port but the application itself does not open a port (Serial fails).

What makes this odder (for me anyway) is that I used an ESP32-C3-Mini on another project and was able to both upload the code and use the USB port for serial communications just fine. It is my understanding that both the C3 and S3 have internal USB-to-Serial support.

FYI: I am using Visual Studio 2023 with the VisualMicro extension for the IDE.

Any insight is most appreciated.

Code: Select all

/*
 Name:		USBComTest.ino
 Created:	8/29/2024
*/

/*********************************************************************
 This is the code is just to test the ability to program and
 communicate over the USB port on the ESP32-S3.
*********************************************************************/

#include <Arduino.h>

/********************REVISION HISTORY********************************
    0.0     08/29/24
        Inital unreleased development
*********************************************************************/

//  Define the command terms
constexpr auto CmdArraySize = 8;        //  Maximum number of parameters in any command elements
String Cmd[CmdArraySize];               //  The command array received 
bool CmdIsValid;                        //  The command received is valid

///////////////////////////////////////////     SETUP    //////////////////////////////////////////////////////// 

void setup() {

    //  Setup the serial com port
    Serial.begin(115200);
    Serial.setTimeout(20);
    //while (!Serial);
    delay(500);

    Serial.println("---------------------");
    Serial.println("   USB Serial Com Test");
    Serial.println("---------------------");

}
////////////////////////////////////////////    LOOP   /////////////////////////////////////////////////////////////

void loop() {

    //  Check to see if there is a serial command was received
    byte i = 0;
    byte ch;
    char charSerial[127];

    //  Serial data available
    while (Serial.available()) {
        ch = Serial.read();
        if ((ch == '\r') || (ch == '\n')) {
            charSerial[i] = '\0';
            Serial.println(charSerial);
            i = 0;
        }
        else {
            charSerial[i] = (char)ch;
            i++;
        }
    }


    delay(10);  //  Slow things down just a bit
}


User avatar
stevenbennett
Posts: 34
Joined: Sun May 19, 2024 7:30 am
Location: High Bentham, UK

Re: ESP32-S3 USB Port uploads but serial comms are not working.

Postby stevenbennett » Fri Aug 30, 2024 2:24 pm

Pins 19 & 20 are the pins for the internal JTAG debugging interface and present two COM ports, one of which needs the driver changing to function as a Universal Serial Bus Device called USB/JTAG Serial Debug Unit. The other port is a kind of COM port but seems to behave differently from a normal COM port. I have had similar problems to the one you describe. The solution I found was to use the S3 modules that have two USBC ports, the second non-JTAG is just a standard COM port driven by a USB chip like a CH340 and you should have no problem using that port. Try using a a module with 2 USB sockets.

chr_te
Posts: 9
Joined: Thu Apr 11, 2024 10:33 pm

Re: ESP32-S3 USB Port uploads but serial comms are not working.

Postby chr_te » Tue Sep 03, 2024 9:28 am

Hi Chevelle,

Serial actually is a macro and it gets defined according to the setup you've configured (e.g. in the arduino ide, more later). It can be especially confusing when accidentally getting the configuration wrong and going crazy over seeing no Serial output.

Without changing anything in your upload settings, you'd probably see your desired output if you'd change every occurrence of "Serial" to "USBSerial".

Here you can see the documentation of what you should configure in the arduino ide -> Tools section.
In short, if you want to use the internal USB peripheral (pin 19/20) for flashing and as serial interface that is associated with the Serial macro you'll have to use e.g.
USB Mode: Hardware CDC and JTAG
USB CDC on boot: enabled
Upload mode: Hardware CDC / JTAG
If you do this, then all your "Serial" usage in code gets routed to the USB peripherals (pin 19/20) CDC. This is what you'll talk to from your PC, e.g. in my case it shows up as "USB JTAG/serial debug unit (Interface 0) (COM7)". I can upload my firmware via COM7 and also connect the serial monitor to COM7 and Serial.println("Hello World") gets routed to COM7 from my PC's perspective. I think that way, as it's even initialized implicitly before setup(), you don't even need to Serial.begin()...

When Serial is associated with the USBSerial, you can still use the device's uart, for this you'd e.g. use Serial0 in your arduino code. For my taste there is a bit much implicitly done in the background, but I guess that's just how it is in the arduino eco system.

My recommendation is to play around with these setups a bit, until you get what you want. E.g. if you disable usb cdc on boot, you'll have to use USBSerial isntead of Serial, try something small first:

Code: Select all

#include <Arduino.h>

void setup() {
  USBSerial.begin(115200); // baud doesn't matter to USBSerial
  delay(1000);
  USBSerial.println("Hello World");
}

void loop() {
  static int counter = 0;
  USBSerial.print("Counter: ");
  USBSerial.println(counter);
  counter++;
  delay(500);
}

Here you'll also find some good info, even though it's for platformio, the principle is the same. Also, take a look at the actual esp32 arduino USB CDC doc.

TL;DR You can have exactly what you wanted with the internal usb peripheral. You just need the to get the setup (in the ide / your config) right. The esp32-s3's usb peripheral really is amazing and extremely convenient!
stevenbennett wrote: The solution I found was to use the S3 modules that have two USBC ports, the second non-JTAG is just a standard COM port driven by a USB chip like a CH340 and you should have no problem using that port. Try using a a module with 2 USB sockets.
As mentioned above, if you get the board config right, there is nothing to worry about with the on board usb peripheral. And it's extremely powerful with the flexibility it provides.

chr_te
Posts: 9
Joined: Thu Apr 11, 2024 10:33 pm

Re: ESP32-S3 USB Port uploads but serial comms are not working.

Postby chr_te » Tue Sep 03, 2024 9:33 am

Also, somehow verify at least once, that your upload goes as planned and make sure you're not actually stuck in boot mode!
E.g. you could turn on an LED or something, that makes you see, that the uc is actually running your program.

copych
Posts: 20
Joined: Tue Mar 07, 2023 6:04 pm

Re: ESP32-S3 USB Port uploads but serial comms are not working.

Postby copych » Thu Sep 05, 2024 6:48 am

Hello, I also get confused when dealing with COM ports of S3. I use these ports with MIDI library, and I haven't yet made it clear nor found a universal solution for different versions of ESP Arduino core. But here's what I've found for now:
Core 2.0.17
When a board doesn't have a dedicated UART chip like CP2101 or CH340 etc., a port ot type HWCDC named USBSerial is available.
If a board has that UART chip, HardwareSerial Serial is defined.
Core 3.x.x
No matter of what board has, a HardwareSerial Serial is defined in all cases, but sometimes acts strangely, most probably because it needs an updated .begin().

In all mentioned cases I assume ARDUINO_USB_CDC_ON_BOOT to be 0 or not defined.

I'd appreciate any help in making S3's Serials more clear.

User avatar
stevenbennett
Posts: 34
Joined: Sun May 19, 2024 7:30 am
Location: High Bentham, UK

Re: ESP32-S3 USB Port uploads but serial comms are not working.

Postby stevenbennett » Thu Sep 05, 2024 8:13 am

copych wrote:
Thu Sep 05, 2024 6:48 am
Hello, I also get confused when dealing with COM ports of S3. I use these ports with MIDI library, and I haven't yet made it clear nor found a universal solution for different versions of ESP Arduino core. But here's what I've found for now:
Core 2.0.17
When a board doesn't have a dedicated UART chip like CP2101 or CH340 etc., a port ot type HWCDC named USBSerial is available.
If a board has that UART chip, HardwareSerial Serial is defined.
Core 3.x.x
No matter of what board has, a HardwareSerial Serial is defined in all cases, but sometimes acts strangely, most probably because it needs an updated .begin().

In all mentioned cases I assume ARDUINO_USB_CDC_ON_BOOT to be 0 or not defined.

I'd appreciate any help in making S3's Serials more clear.
The section on USB ports in the attached PDF might help.
Create, build & debug using ESP-IDF on VSCode.pdf
(188.23 KiB) Downloaded 139 times

Who is online

Users browsing this forum: No registered users and 70 guests