feature-requests icon indicating copy to clipboard operation
feature-requests copied to clipboard

UART over USB (CDC/VCP)

Open ruben-iteng opened this issue 1 year ago • 6 comments

Describe the problem you have/What new integration you would like

I would like to have the option to use the USB hardware port on selected platforms (R2040, ESP32-C3/S2...) as UART bus. Similar to how the logger component can use the USB_CDC as hardware port but then for the uart component.

Please describe your use case for this integration and alternatives you've tried:

With this functionality it is possible to write new/custom components that require UART over USB. e.g. I could make an AT command component to control the ESPHome device with a host, or the other way around (some solar inverters use ModBus over USB CDC/VCP to communicate).

Additional context

ruben-iteng avatar Oct 18 '24 11:10 ruben-iteng

like this one? https://github.com/esphome/esphome/pull/7520

randybb avatar Oct 18 '24 17:10 randybb

like this one? esphome/esphome#7520

I saw that pr, but I'm not sure it is the same issue. I'm really just looking to do this:

uart:
  hardware_uart: USB_CDC

instead of rx/tx_pin or port

ruben-iteng avatar Oct 18 '24 17:10 ruben-iteng

should be as for now USB_CDC or USB_SERIAL_JTAG are only for logger. With this you could use it for anything else - as a standard serial port, HID on some never even as USB OTG.

randybb avatar Oct 18 '24 18:10 randybb

should be as for now USB_CDC or USB_SERIAL_JTAG are only for logger. With this you could use it for anything else - as a standard serial port, HID on some never even as USB OTG.

Yes, thank you. I indeed looked into it a bit, but this also requires changes to the uart component I expect. This features request is still valid in that case (independent from how other USB related things will be implemented). I don't know the code base that well, but it might be a small change to support UART over USB already for the uart component as it is already implemented for the logger.

ruben-iteng avatar Oct 18 '24 18:10 ruben-iteng

With this you could use it for anything else - as a standard serial port, HID on some never even as USB OTG.

Not exactly. USB OTG is a host function, can can't be used at the same time as USB client mode, which is what this request relates to. Using the USB-CDC or JTAG serial as a UART shouldn't be hard since it's built into the microcode and would not need changes to the UART component, just need to implement the UART class in a separate component. HID would need a significant amount of new code.

clydebarrow avatar Oct 18 '24 20:10 clydebarrow

Sure not with the host one, but would be possible to make similar for otg... - mentioned that how it is with usb in general. And Tom is already working on HID.

randybb avatar Oct 18 '24 20:10 randybb

Hello, This improvement would be very useful in my case, my heat pump communicates in serial with a gateway in USB CDC. To replace the manufacturer gateway by a DIY one with esphome, I need a bridge USB CDC/TTL. With this new feature the esp32 s2 would be sufficient.

djtef avatar Jan 12 '25 09:01 djtef

@clydebarrow could you give some pointers on how to implement this. I might be able to implement it with some help 🙂

ruben-iteng avatar Jan 21 '25 11:01 ruben-iteng

Depends what "this" is. If it's the subject of this feature request, i.e. a USB client as a UART component, then I have not looked at it.

clydebarrow avatar Jan 21 '25 11:01 clydebarrow

Depends what "this" is. If it's the subject of this feature request, i.e. a USB client as a UART component, then I have not looked at it.

Oh yes sorry for not being clear. I indeed ment USB client as UART component (what the logger component is using currently).

ruben-iteng avatar Jan 21 '25 12:01 ruben-iteng

Just I was looking for this. I have a climate device that uses a USB connector as UART and I have bought a ESP32-C3 to try to use the USB as UART, but I see that for now is not possible.

Danixu avatar Feb 07 '25 20:02 Danixu

@Danixu, maybe @clydebarrow's solution will work for you.

felipecrs avatar Feb 07 '25 20:02 felipecrs

ESP32-C3 to try to use the USB as UART, but I see that for now is not possible.

You need an S3 or S2. The C3 does not support USB OTG.

clydebarrow avatar Feb 07 '25 21:02 clydebarrow

Luckily the ESP32 is a cheap hardware 😅 . I'll try to buy some S3 and I'll test it. For now I have soldered a USB cable to the GPIO1 and GPIO3 pins to use the normal UART, but I prefer a cleaner approach.

Thanks!!

Danixu avatar Feb 07 '25 21:02 Danixu

anyone is working on it? I also need this :) It could be implemented using rom firmware or tinyusb.

tomaszduda23 avatar Oct 15 '25 18:10 tomaszduda23

Isn't this done already?

https://esphome.io/components/usb_uart/

felipecrs avatar Oct 15 '25 18:10 felipecrs

Isn't this done already?

https://esphome.io/components/usb_uart/

This seems OTG host mode where you can connect serial device https://en.wikipedia.org/wiki/USB-to-serial_adapter to esp. I would like to have it the other way around.

tomaszduda23 avatar Oct 15 '25 18:10 tomaszduda23

Do you want to achieve something like communicating via serial from a computer for example? Computer SerialPort <--> ESP

AzonInc avatar Oct 15 '25 18:10 AzonInc

There is some confusion here. USB host support has been added. This allows you to connect a USB serial device to the ESP, like a USB-TTL adapter. But this is not what the original request was for. What is requested here is to be able to plug the ESP USB port into a computer and have some component be able to communicate with the computer instead of sending logs. This only applies to devices like the S3 and C3 that have native USB. Someone was recently looking at implementing this, but I'm not sure how far he got on it.

ssieb avatar Oct 15 '25 18:10 ssieb

I wonder what would be a use case for this.

felipecrs avatar Oct 15 '25 18:10 felipecrs

I was doing something similar here: https://github.com/AzonInc/Doorman/blob/dev/components/tc_bus_serial/tc_bus_serial_component.cpp

Example usecase app: https://dev.doorman.azon.ai/reference/esphome-component-serial

I wonder what would be a use case for this.

In my case there is a Desktop application to configure devices on an intercom bus. They offer a USB interface that communicates via serial.

Now if you want to build your own cheap bus interface for this application, you also need to be able to use the serial connection.

AzonInc avatar Oct 15 '25 18:10 AzonInc

https://github.com/esphome/esphome/pull/11634 I started implementation for nrf52.

tomaszduda23 avatar Oct 31 '25 20:10 tomaszduda23

There is also work being done here:

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

ruben-iteng avatar Nov 03 '25 09:11 ruben-iteng