ESP32-P4 and USB Device + Host

Adraen
Posts: 8
Joined: Wed Jun 21, 2017 10:17 am

ESP32-P4 and USB Device + Host

Postby Adraen » Wed Jul 09, 2025 8:59 pm

Hi,

One of the (many) great addition of the P4 is the support for USB HS and the dual USB (FS + HS) as well as the JTAG/Serial.

In the device i'm developing I'm trying to get one USB as a USB-NCM device, and have the second USB in host mode to connect a 4G modem (or potentially something else).

I got TinyUSB NCM working without any problem, I configured ESP-IDF to use the HS port for tinyusb and that works pretty flawlessly (and it was working really well on the S3 before)

However and that's where the catch is. How can I use the second port in host mode? Looking at esp-modem for instance I can't find out how to specify which USB interface to use and pretty much the same story in other USB host code.

Looking around I can see that TinyUSB supports only one port at a time, but if I'm not mistaken the host code in the esp-idf is not using tinyusb?

Apologies if this is answered somewhere else, I've been digging through the forum and github quite a lot but i've seen the question come up a few times but I haven't seen any answer.

Sprite
Espressif staff
Espressif staff
Posts: 10596
Joined: Thu Nov 26, 2015 4:08 am

Re: ESP32-P4 and USB Device + Host

Postby Sprite » Thu Jul 10, 2025 5:04 am

At least the hardware supports this; the USB JTAG/serial shares a port with an USB FS OTG controller. Not sure of the software side of things, though.

Adraen
Posts: 8
Joined: Wed Jun 21, 2017 10:17 am

Re: ESP32-P4 and USB Device + Host

Postby Adraen » Thu Jul 10, 2025 9:39 pm

> the USB JTAG/serial shares a port with an USB FS OTG controller

Is that right? Looking at the technical reference manual (not sure if there is anything more recent than the 0.1) it says that the ESP32-P4 has two FS transceivers and that by default FS_PHY1 is on GPIO24/GPIO25 and FS_PHY2 on GPIO26/GPIO27

From that it's my understanding that unlike the S3 for instance you can have USB HS on D+ and D-, as well as USB OTG_FS on 26/27 and JTAG/Serial on 24/25

But at the end of the day if the USB HS and USB FS can't be used at the same time it's a bit of a problem, I will keep digging to see if I can figure out a way but neither the doc or the API has been of much help so far.

Sprite
Espressif staff
Espressif staff
Posts: 10596
Joined: Thu Nov 26, 2015 4:08 am

Re: ESP32-P4 and USB Device + Host

Postby Sprite » Fri Jul 11, 2025 12:13 am

No, you can. What I'm saying is that you have USB OTG HS on one port, and the choice of either USB OTG FS or USB serial-JTAG on the other port. You can have an USB host on the one and an USB device on the other; you just need to be mindful that you don't have a PHY left for USB-serial-JTAG functions, meaning you may want to leave UART0 (and possibly the JTAG pins) accessible to do debugging.

Adraen
Posts: 8
Joined: Wed Jun 21, 2017 10:17 am

Re: ESP32-P4 and USB Device + Host

Postby Adraen » Fri Jul 11, 2025 5:43 am

Thanks Sprite,

Apologies my previous wasn't particularly clear and it was two different things. I understand that USB HS and FS are usable at the same time it's "just" a software issue at the moment (still very limiting).

What I meant to ask was that in the TRM (at least from my understanding) both USB FS OTG and USB JTAG/Serial can be used at the same time.

For reference here is point "USB 2.0 Full-Speed Interface" in section 45.4.1
ESP32-P4 has two full-speed transceivers. This interface is used to connect the controller core to one of USB 2.0 full-speed serial transceivers. Aside from USB OTG, ESP32-P4 also includes a USB Serial/JTAG controller, see Chapter 46USB Serial/JTAG Controller (USB_SERIAL_JTAG). These two USB controllers can utilize the integrated internal transceivers by time-division multiplexing. In the following sections, GPIO24 and GPIO25 are referred to as FS_PHY1, while GPIO26 and GPIO27 as FS_PHY2.

By default FS_PHY1 connects to USB Serial/JTAG controller and FS_PHY2 to OTG_FS. The connection is
configurable via eFuse settings:
– 0: FS_PHY1 is connected to USB Serial/JTAG controller, while FS_PHY2 to OTG_FS.
– 1: FS_PHY2 is connected to USB Serial/JTAG controller, while FS_PHY1 to OTG_FS.

Adraen
Posts: 8
Joined: Wed Jun 21, 2017 10:17 am

Re: ESP32-P4 and USB Device + Host

Postby Adraen » Fri Jul 11, 2025 1:36 pm

Okay for anyone interested I think I got it working, the setup is like this:
  • Waveshare ESP32-P4 Nano
  • USB -> Serial on the main USB port of the waveshare board, connected to PC
  • USB JTAG/Serial on GPIO24/GPIO25, connected to PC
  • USB FS Device on GPIO26/GPIO27, connected to PC
  • USB HS Host on D+/D- connected, connected to SIM7600E module
Result:
  • on the PC I have ttyACM0 (usb to serial), ttyACM1 (JTAG/Serial) and a cdc_ncm network interface (USB OTG FS / tinyusb)
  • I can open both ttyACM terminals (usb serial + jtag/serial)
  • I can ping the ESP32-P4 through the cdc_ncm interface
  • I see esp_modem establishing the connection to the SIM7600E (but it's not working because of RX buffer append not supported on P4 and hence not supporting SIM7600 modules, but I can just use a different 4g module)
Steps:
  • ESP_Modem uses the USB Host library and the USB host library support only the USB HS interface at the moment (and it's hardcoded). So the main limitation at the moment is that you can't use the slower usb port for host and the fast one for device
  • TinyUSB supports only once instance at a time but isn't used for ESP_modem and USB Host so it's not an issue. Just go in the config of ESP-IDF and make sure to select OTG1.1 as the USB Peripheral for TinyUSB (this will use by default USB FS on GPIO26 and GPIO27)
So it looks to be mostly working, I will need to do more tests but it seems to be working fine. It also looks like the 3 USB peripherals on te ESP32-P4 can be used at the same time (HS, FS, Serial/JTAG)
1cd77ad6-f560-4ad6-87fc-276c2e53097b.jpeg
1cd77ad6-f560-4ad6-87fc-276c2e53097b.jpeg (132.46 KiB) Viewed 1902 times

Sprite
Espressif staff
Espressif staff
Posts: 10596
Joined: Thu Nov 26, 2015 4:08 am

Re: ESP32-P4 and USB Device + Host

Postby Sprite » Mon Jul 14, 2025 3:50 am

Ah, sorry, you seem to be right in that USB FS and USB-serial-JTAG don't share any ports. I probably have it confused with either a previous internal version of the chip, or with the rest of the ESP32 line.

Who is online

Users browsing this forum: Applebot, Baidu [Spider], Bytespider, ChatGPT-User, meta-externalagent, PerplexityBot, Qwantbot and 3 guests