ESP32-S3 USB ID pin

leonardo.costa
Posts: 2
Joined: Thu Jan 06, 2022 6:21 pm

ESP32-S3 USB ID pin

Postby leonardo.costa » Wed Feb 09, 2022 10:49 am

Hello,
i couldn't find on any ESP32-S3 documents the position of the USB OTG ID pin on the pinout, is it managed by the USB OTG controller or can i use any pins managing the USB_CONIDSTS bit in the USB_GOTGCTL_REG by firmware?
Any help is appreciated.

Leo

ESP_Dazz
Posts: 308
Joined: Fri Jun 02, 2017 6:50 am

Re: ESP32-S3 USB ID pin

Postby ESP_Dazz » Wed Feb 09, 2022 11:55 am

On the ESP32-S3, D- and D+ should be tied to GPIO19 and GPIO20. See section "2.2 Pin Description" of the S3 datasheet for more details.

ESP_Sprite
Posts: 8921
Joined: Thu Nov 26, 2015 4:08 am

Re: ESP32-S3 USB ID pin

Postby ESP_Sprite » Thu Feb 10, 2022 1:25 am

Do you actually need the ID pin? If you simply want to use the chip in host or device mode, it's not needed, you can simply leave it open. If you need it anyway, I think you can route it to any GPIO pin using the GPIO matrix; it doesn't have a dedicated pin.

User avatar
mvduin
Posts: 6
Joined: Wed Feb 16, 2022 1:57 pm

Re: ESP32-S3 USB ID pin

Postby mvduin » Wed Feb 16, 2022 5:09 pm

The esp32-s2/s3 usb phy does not appear to handle the ID and VBUS pins like you'd normally expect from an integrated phy. It seems that most of the control signals of the usb core's phy interface are instead just hooked up to the gpio matrix:

Code: Select all

~/.../esp-idf/components$ grep -P 'USB_(OTG|SRP)_' soc/esp32s3/include/soc/gpio_sig_map.h
#define USB_OTG_IDDIG_IN_IDX          58
#define USB_OTG_AVALID_IN_IDX         59
#define USB_SRP_BVALID_IN_IDX         60
#define USB_OTG_IDPULLUP_IDX          60
#define USB_OTG_VBUSVALID_IN_IDX      61
#define USB_OTG_DPPULLDOWN_IDX        61
#define USB_SRP_SESSEND_IN_IDX        62
#define USB_OTG_DMPULLDOWN_IDX        62
#define USB_OTG_DRVVBUS_IDX           63
#define USB_SRP_CHRGVBUS_IDX          64
#define USB_SRP_DISCHRGVBUS_IDX       65
(See e.g. the UTMI+ specification for a description of these signals.)

The outputs are simply ignored and the inputs get muxed to constant-0 or constant-1 by software, which also manually controls the D+/D− pullups via phy registers, see:
  • esp-idf/components/usb/usb_phy.c
  • esp-idf/components/hal/usb_phy_hal.c
  • esp-idf/components/hal/esp32s3/include/hal/usb_phy_ll.h
Note that the lack of VBUS monitoring means that any esp32-s2/s3 based usb device that uses this code and isn't powered solely from VBUS (but e.g. battery or external supply) will be in violation of the USB specification, which requires devices to refrain from pulling up D+ or D− unless VBUS is present:
  • "The voltage source on the pull-up resistor must be derived from or controlled by the power supplied on the USB cable such that when VBUS is removed, the pull-up resistor does not supply current on the data line to which it is attached."
    —USB 2.0 Specification, section 7.1.5
  • "No device shall supply (source) current on VBUS at its upstream facing port at any time. From VBUS on its upstream facing port, a device may only draw (sink) current. They may not provide power to the pull-up resistor on D+/D− unless VBUS is present. When VBUS is removed, the device must remove power from the D+/D− pull-up resistor within 10 seconds."
    —USB 2.0 Specification, section 7.2.1
(This to ensure you're not sourcing current into the host via D+/D− pullups when the host is powered off, which could potentially be harmful to the host.)

dejavu1987
Posts: 1
Joined: Sun Mar 19, 2023 6:33 pm

Re: ESP32-S3 USB ID pin

Postby dejavu1987 » Sun Mar 19, 2023 6:52 pm

"The voltage source on the pull-up resistor must be derived from or controlled by the power supplied on the USB cable such that when VBUS is removed, the pull-up resistor does not supply current on the data line to which it is attached."
—USB 2.0 Specification, section 7.1.5
How do I do that?
The ESP32-S3 datasheet shows following
Screenshot 2023-03-19 at 19.31.18.png
Screenshot 2023-03-19 at 19.31.18.png (30.71 KiB) Viewed 2610 times
What should be the values of those registers and capacitors?
"No device shall supply (source) current on VBUS at its upstream facing port at any time. From VBUS on its upstream facing port, a device may only draw (sink) current. They may not provide power to the pull-up resistor on D+/D− unless VBUS is present. When VBUS is removed, the device must remove power from the D+/D− pull-up resistor within 10 seconds."
For this can I just add a diode like this.
Screenshot 2023-03-19 at 19.41.34.png
Screenshot 2023-03-19 at 19.41.34.png (40.7 KiB) Viewed 2610 times

User avatar
mvduin
Posts: 6
Joined: Wed Feb 16, 2022 1:57 pm

Re: ESP32-S3 USB ID pin

Postby mvduin » Mon Mar 20, 2023 1:47 am

dejavu1987 wrote:
mvduin wrote: "The voltage source on the pull-up resistor must be derived from or controlled by the power supplied on the USB cable such that when VBUS is removed, the pull-up resistor does not supply current on the data line to which it is attached."
—USB 2.0 Specification, section 7.1.5
How do I do that?
If your device is solely powered via usb then this is automatically satisfied. If your device is (or can be) powered by some means other than via usb then to comply with that requirement you'd need to monitor the usb VBUS voltage and keep the data line pull-ups disabled if VBUS is not present. I don't remember the appropriate threshold voltage, I'd need to look that up.

The data line pull-up/down resistors are integrated in the ESP32 and, like I mentioned in my previous post, controlled by software. Last time I checked (which was a year ago) the usb-phy code in esp-idf didn't implement a mode for usb devices to keep the D+/D- resistors disabled (aka a "soft-disconnect" mode). Maybe that has changed since then, or otherwise it's probably not hard to patch in.
dejavu1987 wrote: The ESP32-S3 datasheet shows following
Screenshot 2023-03-19 at 19.31.18.png
What should be the values of those registers and capacitors?
That just looks like placeholders designed in to keep options open for tweaking the pcb if necessary for signal integrity issues. It has nothing to do with the issue I commented about.
dejavu1987 wrote:
mvduin wrote: "No device shall supply (source) current on VBUS at its upstream facing port at any time. From VBUS on its upstream facing port, a device may only draw (sink) current."
For this can I just add a diode like this.Screenshot 2023-03-19 at 19.41.34.png
A diode will indeed prevent backfeeding power to USB VBUS (whenever your device is powered via alternate means). Of course do be mindful of the voltage drop across the diode when USB is being used to power your device.

Who is online

Users browsing this forum: No registered users and 67 guests