linux-xtensa icon indicating copy to clipboard operation
linux-xtensa copied to clipboard

USB Host Controller

Open zap8600 opened this issue 1 year ago • 11 comments

What would it take for a USB Host Controller driver to be made?

zap8600 avatar Jan 10 '24 19:01 zap8600

As mentioned here there's some figuring out the hardware details from the existing code that must happen. And then the standard: copy a similar driver -- fill in the hardware-specific details.

jcmvbkbc avatar Jan 23 '24 21:01 jcmvbkbc

I've pushed initial version with USB host support here. Currently it needs the following change to the esp_hosted that switches the USB PHY connection from the USB serial to the USB controller:

diff --git a/esp_hosted_ng/esp/esp_driver/network_adapter/main/linux_boot.c b/esp_hosted_ng/esp/esp_driver/network_adapter/main/linux_boot.c
index 0cf55f3a2389..fc9ae8329b4d 100644
--- a/esp_hosted_ng/esp/esp_driver/network_adapter/main/linux_boot.c
+++ b/esp_hosted_ng/esp/esp_driver/network_adapter/main/linux_boot.c
@@ -125,6 +125,8 @@ static void map_flash_and_go(void)
        extern int g_abort_on_ipc;
        g_abort_on_ipc = 1;
 
+       *(volatile uint32_t *)0x60008120 = 0x180000;
+       *(volatile uint32_t *)0x60039000 = 0x001d5000;
        asm volatile ("mov a2, %1 ; jx %0" :: "r"(linux), "r"(tag) : "a2");
 }
 

This version has DMA disabled so the performance is not impressive (dd from /dev/sda to /dev/null runs at about 650KBytes/s), my guess is that it would only work with the buffers and/or descriptors in DRAM but some further investigation is needed.

jcmvbkbc avatar Jul 25 '24 15:07 jcmvbkbc

Nice! Currently, I'm working on my U-Boot port and a small laptop with the ESP32-S3, so It'll be a minute before I give it a test. The low speeds are kind of expected. With ESP-IDF running alongside Linux, the capabilities are limited. Hopefully I finish up my U-Boot port soon so I can work on removing those limitations.

zap8600 avatar Jul 25 '24 18:07 zap8600

It might be a bit early to ask, but is being a device possible as well? I think Linux has USB OTG support, and I know the ESP32-S3 has it, too. I'm not sure how Linux handles the switch from host to device and vise versa or how the power supply change would be handled.

zap8600 avatar Aug 01 '24 16:08 zap8600

is being a device possible as well?

Yes, I tested it as an ethernet gadget, works pretty well as long as packet size stays small. I guess fine-tuning FIFO sizes is needed to make it solid.

jcmvbkbc avatar Aug 01 '24 18:08 jcmvbkbc

If both host and peripheral work, then does OTG work? I'd assume that external USB power would be needed. I'm not sure how Linux detects whether it's a host or peripheral, so I'm not sure how to put it together on a board.

zap8600 avatar Aug 01 '24 20:08 zap8600

If both host and peripheral work, then does OTG work?

My impression is that it wouldn't work with the internal USB PHY, but it might work with the external USB PHY. On the devkit-c1 board it 100% doesn't work through the onboard USB connector because the ID line is not connected to it. Even the host mode doesn't work for the bus-powered devices through the onboard USB connector.

jcmvbkbc avatar Aug 02 '24 07:08 jcmvbkbc

I thought that the ESP32-S3 had a UTMI+ OTG interface routed through the GPIO matrix for detecting A-mode or B-mode. I think they're called usb_otg_avalid_in and usb_otg_bvalid_in in the TRM. Could those be used, or am I wrong?

zap8600 avatar Aug 02 '24 15:08 zap8600

Could those be used

They can be used, but you need something that would drive them. Internal USB PHY cannot do it. In my configurations I statically set them high or low depending on whether the host or the device mode is configured in the DTS.

jcmvbkbc avatar Aug 03 '24 05:08 jcmvbkbc

I thought they were inputs, but I guess I was wrong. Sorry. In that case, then how does the external transceiver work? I'm not sure I understand it.

zap8600 avatar Aug 03 '24 18:08 zap8600

I thought they were inputs

They are.

jcmvbkbc avatar Aug 03 '24 19:08 jcmvbkbc