Enable USB CDC to log "hello world" to ESP32-S3 dev board for ESPHome

Hello there! I am a total newbie for ESPHome.

Problem

I am trying to log “hello world” to my dev board via the command line option esphome run hello.yaml, but I have been unsuccessful.

Versions and board

  1. macOS Monterey 12.6
  2. Python: 3.10.6
  3. pip3 version: 22.2.2
  4. esphome version: 2022.8.3
  5. ESP32-S3-DevKitC-1-N8R2, the official dev board from Espressif
  6. Arduino ESP32 package install 2.0.4

What works

I successfully uploaded a simple hello world to the board ESP32-S3-DevKitC-1 via the Arduino IDE with ESP32 Arduino 2.0.4.

I have also successfully compiled and uploaded to the board the following complete YAML file:

esphome:
  name: hello

esp32:
  board: esp32dev
  variant: ESP32S3
  framework:
    type: arduino

logger:
  level: DEBUG
  baud_rate: 0

The final terminal output lines are:

Hard resetting via RTS pin...
INFO Successfully uploaded program.
INFO UART logging is disabled (baud_rate=0). Not starting UART logs.

What does not work

But, when I try to log it gives an error. The YAML file is:

esphome:
  name: hello

  on_boot:
    then:
      - logger.log: "Hello World"

esp32:
  board: esp32dev
  variant: ESP32S3
  framework:
    type: arduino

logger:
  level: DEBUG
  baud_rate: 115200

The final terminal output is:

Leaving...
Hard resetting via RTS pin...
INFO Successfully uploaded program.
INFO Starting log output from /dev/cu.usbmodem14101 with baud rate 115200
[17:16:52]Saved PC:0x40378ae8
[17:16:52]SPIWP:0xee
[17:16:52]mode:DIO, clock div:1
[17:16:52]load:0x3fce3808,len:0x43c
[17:16:52]load:0x403c9700,len:0xbec
[17:16:52]load:0x20747261,len:0x26203d3c
[17:16:52]Invalid image block, can't boot.
[17:16:52]ets_main.c 329
[17:16:54]ESP-ROM:esp32s3-20210327
[17:16:54]Build:Mar 27 2021
[17:16:54]rst:0x7 (TG0WDT_SYS_RST),boot:0x28 (SPI_FAST_FLASH_BOOT)

I have also tried tweaking the board details as suggested in another forum thread with the YAML file:

esphome:
  name: hello

  on_boot:
    then:
      - logger.log: "Hello World"

esp32:
  board: esp32-s3-devkitc-1
  framework:
    type: esp-idf
    platform_version: 4.4.0
  variant: esp32s3

logger:
  level: DEBUG
  baud_rate: 115200

The final terminal output is:

HARDWARE: ESP32S3 240MHz, 320KB RAM, 4MB Flash
 - framework-espidf @ 3.40302.0 (4.3.2)
 - tool-cmake @ 3.16.4
 - tool-ninja @ 1.9.0
 - toolchain-riscv32-esp @ 8.4.0+2021r2-patch3
 - toolchain-xtensa-esp32s3 @ 8.4.0+2021r2-patch3
Error: This board doesn't support espidf framework!
====================================== [FAILED] Took 0.58 seconds ======================================

Hunches

I don’t know whether esptool is having a problem. Another suspicion on enabling USB CDC on boot, which I had to do when uploading to this board via the Arduino IDE. Either could be completely wrong.

Please help! Thanks!

Esptool is not part of esphome. Why are you using it rather than esphome?

Sorry, it is one of the dependencies for Arduino ESP32. Please ignore it then :pray:t2: Just a hunch.
I am only using esphome with command esphome run hello.yaml.

The newer esp32 chips like the s3 seem problematic. There is so much information and misinformation, and the requirements seem ever changing. I try to stick to straight esp32

1 Like

This worked for me!

esp32:
  board: esp32-s3-devkitc-1
  framework:
    type: arduino
    version: 2.0.3
    platform_version: 5.1.0
  variant: esp32s3
2 Likes

Thanks @ihr !

I tried the following YAML config:

esphome:
  name: hello

  on_boot:
    then:
      - logger.log: "Hello World"

esp32:
  board: esp32-s3-devkitc-1
  framework:
    type: arduino
    version: 2.0.3
    platform_version: 5.1.0
  variant: esp32s3

logger:
  level: DEBUG
  baud_rate: 115200

And it seems hung.

Leaving...
Hard resetting via RTS pin...
INFO Successfully uploaded program.
INFO Starting log output from /dev/cu.usbmodem14101 with baud rate 115200
[08:23:49]rst:0x15 (USB_UART_CHIP_RESET),boot:0x8 (SPI_FAST_FLASH_BOOT)
[08:23:49]Saved PC:0x40378b41
WARNING Decoded 0x40378b41: rtc_sleep_pu at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/esp_hw_support/port/esp32s3/rtc_sleep.c:44
[08:23:50]SPIWP:0xee
[08:23:50]mode:DIO, clock div:1
[08:23:50]load:0x3fcd0108,len:0x39c
[08:23:50]load:0x403b6000,len:0x9a4
[08:23:50]load:0x403ba000,len:0x2868
[08:23:50]SHA-256 comparison failed:
[08:23:50]Calculated: 9127e332554622857d5c753c9ffbb9862bfb72e81ded80db80617d5974000cec
[08:23:50]Expected: 867c0d6cb8d08f5a22bebcb1e4a5d457c2700a1c6b76abeb4d778eadcc3446e2
[08:23:50]Attempting to boot anyway...
[08:23:50]entry 0x403b61c0

Did you need to press the dev board’s buttons to bring it into some bootloader mode? Also, I am unsure which SHA-256 comparison is failing.

Hmm… No, I don’t need to press any button on the board.

SHA-256 comparison failed:

This is not good. t looks like the board received a different code than the code you compiled? or even a broken code? Take a look at your hardware, and serial port

I did delete the folder .esphome and compile it again. It’s the same SHA comparison error.

I found a couple of similar issues with ESP32S3 on the GitHub and Espressif forums, but no idea how to go about fixing it as it’s the official board from Espressif and not a custom PCB :thinking:

I’d exactly the same problem but just when updating the firmware using OTAU (wifi) not when using the USB connection

Now, I have slightly better results by downgrading the Arduino version to 2.0.3 as I read in this GitHub issue.

esphome:
  name: hello

  on_boot:
    then:
      - logger.log: "Hello World"

esp32:
  board: esp32-s3-devkitc-1
  variant: esp32s3
  framework:
    type: arduino
    version: 2.0.3
    platform_version: 5.1.0

logger:
  level: DEBUG
  baud_rate: 115200
  deassert_rts_dtr: true

Compilation and upload are both successful, but I do not see any logs for Hello World.

Leaving...
Hard resetting via RTS pin...
INFO Successfully uploaded program.
INFO Starting log output from /dev/cu.usbmodem14101 with baud rate 115200
[15:35:19]ESP-ROM:esp32s3-20210327
[15:35:19]Build:Mar 27 2021
[15:35:19]rst:0x15 (USB_UART_CHIP_RESET),boot:0x8 (SPI_FAST_FLASH_BOOT)
[15:35:19]Saved PC:0x4202168e
WARNING Decoded 0x4202168e: esp_pm_impl_waiti at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/esp_pm/pm_impl.c:839
[15:35:19]SPIWP:0xee
[15:35:19]mode:DIO, clock div:1
[15:35:19]load:0x3fcd0108,len:0x39c
[15:35:19]load:0x403b6000,len:0x9a4
[15:35:19]load:0x403ba000,len:0x2868
[15:35:19]entry 0x403b61c0

Any idea how I can view the log?

1 Like

Make sure you are connected from serial (USB) port.
If you connect over WIFI to the ESP the log line could be written before the log connection is established.

1 Like

Yep, I am using the USB port. Just trying the simplest example, so definitely not going to add more complications with WiFi :sweat_smile:

As with Arduino IDE’s menu “CDC enable” and platformIO’s CDC enable I was successful in uploading and viewing the logs. I tried to add the same option for USB CDC in the ESPHome’s logger in hopes that I will be able to see the logs.

logger:
  level: VERBOSE
  baud_rate: 115200
  deassert_rts_dtr: true
  hardware_uart: USB_CDC

But unfortunately, I see the error that USB CDC is only for the ESP-IDF platform. I do see a GitHub issue / PR on this feature and I am wondering whether it is missing for Arduino / PlatformIO.

Time to raise an issue in the repository to add USB_CDC logger option for Arduino/ Platform? :sweat_smile:

Failed config

logger: [source hello-esphome.yaml:17]
  level: VERBOSE
  baud_rate: 115200
  deassert_rts_dtr: True

  Only esp-idf framework supports USB_CDC.
  hardware_uart: USB_CDC

I am closing this issue as I am able to finally get the “Hello World” log. And the solution is pretty trivial.

Since the Espressif ESP32-S3-DevKitC-1 board has 2 ports, first use the USB port to compile and upload, and then change to the UART port to view the logs.

If we want to use the same USB port, CDC USB needs to be enabled just like Arduino IDE and PlatformIO. I have raised a feature request to enable USB CDC for ESPHome using Arduino / PlatformIO.

And since, we need to split the steps for compile, upload and monitor, we cannot use esphome run.

And for future reference for anyone, here are the steps:

  1. Compile firmware for this board with esphome compile hello.yaml

    esphome:
      name: hello
    
      on_boot:
        then:
          - logger.log: "Hello World"
    
    esp32:
      board: esp32-s3-devkitc-1
      variant: esp32s3
      framework:
        type: arduino
        version: 2.0.3
        platform_version: 5.1.0
    
    logger:
      level: VERBOSE
      baud_rate: 115200
      deassert_rts_dtr: true
    
  2. Plug into the USB port of the board and check the port address

  3. Upload the firmware esphome upload --device /dev/cu.usbmodem14101 hello.yaml

  4. Unplug and plug into the UART port of the board

  5. Check the new port address

  6. Access the logs esphome logs --device /dev/cu.usbserial-1410 hello.yaml

Thanks for the discussion everyone! Please let me know if you spot any mistakes :pray:t2:

2 Likes