esphome / issues

Issue Tracker for ESPHome
https://esphome.io/
290 stars 34 forks source link

HARDWARE_UART: USB_CDC fails in framework esp-idf #5866

Open NonaSuomy opened 4 months ago

NonaSuomy commented 4 months ago

The problem

ESP-IDF not handling the usb-cdc option.

Works with type: arduino just not type: esp-idf

Which version of ESPHome has the issue?

DEV

What type of installation are you using?

Docker

Which version of Home Assistant has the issue?

DEV

What platform are you using?

ESP32

Board

ESP32-S3-N16R8 esp32-s3-devkitc-1 style

Component causing the issue

logger: hardware_uart: usb_cdc

Example YAML snippet

esp32:
  board: esp32-s3-devkitc-1
  variant: esp32s3
  flash_size: 16MB
  framework:
    #type: arduino
    type: esp-idf

# Enable logging
logger:
  level: VERY_VERBOSE
  hardware_uart: USB_CDC

Anything in the logs that might be useful for us?

Compiling .pioenvs/esp32-s3-n16r8-001/esptimer/src/system_time.o
/config/.esphome/platformio/packages/framework-espidf/components/esp_system/port/soc/esp32s3/usb_console.c:77:1: error: static assertion failed: "usb_osglue_int is not multicore capable"
 Static_assert(SOC_CPU_CORES_NUM == 1, "usb_osglue_int is not multicore capable");
 ^~~~~~
*** [.pioenvs/esp32-s3-n16r8-001/esp_system/port/soc/esp32s3/usb_console.o] Error 1
========================= [FAILED] Took 84.28 seconds =========================

Additional information

https://github.com/esphome/esphome/pull/3105

ssieb commented 4 months ago

The default is USB_SERIAL_JTAG, doesn't that work?

NonaSuomy commented 4 months ago

It seems that it should be compatible with both: https://github.com/esphome/esphome/blob/1f301df51d4389f16e6a059c2ac87186c9631be8/esphome/components/logger/__init__.py#L86 VARIANT_ESP32S3: [UART0, UART1, USB_CDC, USB_SERIAL_JTAG],

On chips with an integrated USB Serial/JTAG Controller, it is possible to use the part of this controller that implements a serial port (CDC) to implement the serial console, instead of using UART with an external USB-UART bridge chip.

It doesn't give that error though with:

esp32:
  board: esp32-s3-devkitc-1
  variant: esp32s3
  flash_size: 16MB
  framework:
    #type: arduino
    type: esp-idf

# Enable logging
logger:
  level: VERY_VERBOSE
  hardware_uart: USB_SERIAL_JTAG

https://docs.espressif.com/projects/esp-idf/en/stable/esp32s3/api-guides/usb-otg-console.html

Seems it says you need to use an efuse to use usb_cdc

Some development boards may offer a USB connector for the internal USB peripheral — in that case, no extra connections are required.

By default, [USB_SERIAL_JTAG](https://docs.espressif.com/projects/esp-idf/en/stable/esp32s3/api-guides/usb-serial-jtag-console.html) module is connected to the internal PHY of the ESP32-S3, while USB_OTG peripheral can be used only if the external USB PHY is connected. Since CDC console is provided via USB_OTG peripheral, it cannot be used through the internal PHY in this configuration.

You can permanently switch the internal USB PHY to work with USB_OTG peripheral instead of USB_SERIAL_JTAG by burning USB_PHY_SEL eFuse. See ESP32-S3 Technical Reference Manual for more details about USB_SERIAL_JTAG and USB_OTG.

Note however that USB_SERIAL_JTAG also provides a CDC console, so enabling the CDC console should not be the primary reason for switching from USB_SERIAL_JTAG to USB_CDC.

I personally don't mind what I use just wanted to point out the bug. As it works fine with framework type arduino just not esp-idf.

Maybe bump the user to use USB_SERIAL_JTAG if the efuse is not set to prevent the error or something like that.