ESP32, serial library suddenly stopped to work

Hi

Today I encountered strange problem when working with ESP32 S3 code - serial library for some reason refused to print anything on terminal and I don’t have any clue what happened. Here is code I’m testing it with:

#include <Arduino.h>

void setup() {
  Serial.begin(115200);
}

void loop() {
  Serial.println("hello");
  delay(1000);
}

This is output I’m getting on serial port monitor (both PIO, Arduino or Putty):

ESP-ROM:esp32s3-20210327
Build:Mar 27 2021
rst:0x1 (POWERON),boot:0x8 (SPI_FAST_FLASH_BOOT)
SPIWP:0xee
mode:DIO, clock div:1
load:0x3fce3808,len:0x4bc
load:0x403c9700,len:0xbd8
load:0x403cc700,len:0x2a0c
entry 0x403c98d0

When I compile and upload same code through Arduino IDE, it work as expected:

ESP-ROM:esp32s3-20210327
Build:Mar 27 2021
rst:0x1 (POWERON),boot:0x8 (SPI_FAST_FLASH_BOOT)
SPIWP:0xee
mode:DIO, clock div:1
load:0x3fce3818,len:0x508
load:0x403c9700,len:0x4
load:0x403c9704,len:0xad0
load:0x403cc700,len:0x29e4
entry 0x403c9880
hello
hello
hello
hello

Content of platformio.ini is:

[env:esp32-s3-devkitc-1-n16r8v]
platform = espressif32
board = esp32-s3-devkitc-1-n16r8v
framework = arduino
monitor_speed = 115200

Code was working just fine until last couple of hours (did not install any library as such in the meantime). Apparently HW (serial and ESP32 S3) is working as I can see boot messages.

Espressif32 is v.6.8.1 according to PIO.

Tried to uninstall PIO, VS code, delete .platformio and .vscode folder, reinstall everything, but nothing. Same issue. I noticed this issue on much bigger project (spend hours chasing this issue), code I used above is for troubleshooting purposes only.

Btw. I tried same stuff on some regular ESP32 WROOM, and it work as expected.

Any clue what is going on???

Thx

Hhhhm - which of the both USB-Connectors are you using?

If I use the right one (labeled com) everything works like a charm

Processing esp32-s3-devkitc-1-n16r8v (platform: espressif32; board: esp32-s3-devkitc-1-n16r8v; framework: arduino)
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/esp32-s3-devkitc-1-n16r8v.html
PLATFORM: Espressif 32 (6.7.0) > Espressif ESP32-S3-DevKitC-1-N16R8V (16 MB QD, 8MB PSRAM)
HARDWARE: ESP32S3 240MHz, 320KB RAM, 16MB Flash
DEBUG: Current (esp-builtin) On-board (esp-builtin) External (cmsis-dap, esp-bridge, esp-prog, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa)
PACKAGES: 
 - framework-arduinoespressif32 @ 3.20016.0 (2.0.16) 
 - tool-esptoolpy @ 1.40501.0 (4.5.1) 
 - tool-mkfatfs @ 2.0.1 
 - tool-mklittlefs @ 1.203.210628 (2.3) 
 - tool-mkspiffs @ 2.230.0 (2.30) 
 - toolchain-riscv32-esp @ 8.4.0+2021r2-patch5 
 - toolchain-xtensa-esp32s3 @ 8.4.0+2021r2-patch5
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 33 compatible libraries
Scanning dependencies...
No dependencies
Building in release mode
Retrieving maximum program size .pio/build/esp32-s3-devkitc-1-n16r8v/firmware.elf
Checking size .pio/build/esp32-s3-devkitc-1-n16r8v/firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [=         ]   5.7% (used 18596 bytes from 327680 bytes)
Flash: [          ]   4.1% (used 266829 bytes from 6553600 bytes)
Configuring upload protocol...
AVAILABLE: cmsis-dap, esp-bridge, esp-builtin, esp-prog, espota, esptool, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa
CURRENT: upload_protocol = esptool
Looking for upload port...
Auto-detected: /dev/ttyACM0
Uploading .pio/build/esp32-s3-devkitc-1-n16r8v/firmware.bin
esptool.py v4.5.1
Serial port /dev/ttyACM0
Connecting...
Chip is ESP32-S3 (revision v0.2)
Features: WiFi, BLE
Crystal is 40MHz
MAC: 24:58:7c:cd:a6:48
Uploading stub...
Running stub...
Stub running...
Changing baud rate to 921600
Changed.
Configuring flash size...
Flash will be erased from 0x00000000 to 0x00003fff...
Flash will be erased from 0x00008000 to 0x00008fff...
Flash will be erased from 0x0000e000 to 0x0000ffff...
Flash will be erased from 0x00010000 to 0x00051fff...
Compressed 15104 bytes to 10429...
Writing at 0x00000000... (100 %)
Wrote 15104 bytes (10429 compressed) at 0x00000000 in 0.4 seconds (effective 344.8 kbit/s)...
Hash of data verified.
Compressed 3072 bytes to 146...
Writing at 0x00008000... (100 %)
Wrote 3072 bytes (146 compressed) at 0x00008000 in 0.1 seconds (effective 424.7 kbit/s)...
Hash of data verified.
Compressed 8192 bytes to 47...
Writing at 0x0000e000... (100 %)
Wrote 8192 bytes (47 compressed) at 0x0000e000 in 0.1 seconds (effective 596.5 kbit/s)...
Hash of data verified.
Compressed 267200 bytes to 149497...
Writing at 0x00010000... (10 %)
Writing at 0x0001c7f6... (20 %)
Writing at 0x000248d0... (30 %)
Writing at 0x00029e51... (40 %)
Writing at 0x0002f360... (50 %)
Writing at 0x0003497a... (60 %)
Writing at 0x0003d346... (70 %)
Writing at 0x000453b6... (80 %)
Writing at 0x0004aa96... (90 %)
Writing at 0x000507d5... (100 %)
Wrote 267200 bytes (149497 compressed) at 0x00010000 in 2.2 seconds (effective 973.0 kbit/s)...
Hash of data verified.

Leaving...
Hard resetting via RTS pin...
--- Terminal on /dev/ttyACM0 | 115200 8-N-1
--- Available filters and text transformations: colorize, debug, default, direct, esp32_exception_decoder, hexlify, log2file, nocontrol, printable, send_on_enter, time
--- More details at https://bit.ly/pio-monitor-filters
--- Quit: Ctrl+C | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H
hello
hello
hello
hello

With the left one (labeled usb) I see your problem :wink:

The ESP32 S3 has UART to Serial and native USB Serial.

The Serial object is controlled by the compiler flag ARDUINO_USB_CDC_ON_BOOT

ARDUINO_USB_CDC_ON_BOOT = 1 the output of Serial is routed to the native USB port
ARDUINO_USB_CDC_ON_BOOT = 0 the output of Serial is routed to the UART port.

This corresponds to the ArduinoIDE setting “USB CDC on Boot”.

For details see ESP32-S3 native USB interface and Serial Monitor missing first messages - #10 by sivar2311

The esp32-s3-devkitc-1-n16r8v.json is not part of the official espressif32 platform and must be a custom one. Please show the content of this file and the content of your platformio.ini to determine the settings for ARDUINO_USB_CDC_ON_BOOT.

I’m such an ape :tired_face:

This is what happened: I was using from the beginning right USB connector (2nd when looking to USB-C ports) on ESP32-S3 dev kit and I was mainly using in my code ESP_LOGx for logging capabilities which shoed just fine in terminal. Then I added for some testing actual Serial.print() command and they were not visible. I assumed ESP_LOGx (e.g. Arduino translation to log_x) was also using serial library for sending data to terminal, so I went in loop thinking serial library died for some strange reason.

When now connected to left USB-C (first one) Serial.print() works, with a difference that there is no boot into. In that case will also exception handling, crashing and similar be visible using 1st port (I can see them now on 2nd one)?

Here is json definition file, took it from GitHub (found some reference here):

{
    "build": {
      "arduino":{
        "ldscript": "esp32s3_out.ld",
        "partitions": "default_16MB.csv",
        "memory_type": "qio_opi"
      },
      "core": "esp32",
      "extra_flags": [
        "-DARDUINO_ESP32S3_DEV",
        "-DBOARD_HAS_PSRAM",
        "-DARDUINO_USB_MODE=1",
        "-DARDUINO_USB_CDC_ON_BOOT=1"
      ],
      "f_cpu": "240000000L",
      "f_flash": "80000000L",
      "flash_mode": "qio",
      "psram_type": "opi",
      "hwids": [
        [
          "0x303A",
          "0x1001"
        ]
      ],
      "mcu": "esp32s3",
      "variant": "esp32s3"
    },
    "connectivity": [
      "wifi",
      "bluetooth"
    ],
    "debug": {
      "default_tool": "esp-builtin",
      "onboard_tools": [
        "esp-builtin"
      ],
      "openocd_target": "esp32s3.cfg"
    },
    "frameworks": [
      "arduino",
      "espidf"
    ],
    "name": "Espressif ESP32-S3-DevKitC-1-N16R8V (16 MB QD, 8MB PSRAM)",
    "upload": {
      "flash_size": "16MB",
      "maximum_ram_size": 327680,
      "maximum_size": 16777216,
      "require_upload_port": true,
      "speed": 921600
    },
    "url": "https://docs.espressif.com/projects/esp-idf/en/latest/esp32s3/hw-reference/esp32s3/user-guide-devkitc-1.html",
    "vendor": "Espressif"
  }

Thx

The board json has

-DARDUINO_USB_CDC_ON_BOOT=1

This means Serial output is routed to native USB and Serial0 is routed to UART.

As you have noticed ESP_LOGx doesn`t make use of the Arduino Serial objects.

Is there reason why boot information not present on native USB?

Refering to this here:

ESP-ROM:esp32s3-20210327
Build:Mar 27 2021
rst:0x1 (POWERON),boot:0x8 (SPI_FAST_FLASH_BOOT)
SPIWP:0xee
mode:DIO, clock div:1
load:0x3fce3808,len:0x4bc
load:0x403c9700,len:0xbd8
load:0x403cc700,len:0x2a0c
entry 0x403c98d0

Also when CPU crashes (like panic), will this be visible on native USB? I have seen this until now on UART port (which I used mainly).

I obtained S3 just couple of days ago and I’m in process of porting app from WROOM to S3, so don’t have that much experience with S3 flavor.

Because of the bootloader which output this on UART only. I dont’t see a way to change this.

Afaik also crash logs are set to UART output.

Hm, quite confusing, must confess…

Anyway, thx for the support. I will play with this configuration and try to see what is the best for my setup. With one port it was much simpler, all information on one pipe …

There is also the setDebugOutput method.

See USB Settings for Logging with the ESP32-S3 in PlatformIO • ThingPulse

Thx. I will check this also.

I use several different ESP32-S3 “devkit” boards and find that some have the USB port on the right and some have them on the left, depending on who made them. I have taken to putting a spot of red nail polish on the UART connector and that has saved me a lot of wasted time.