I would like to use USB host on ESP32-S2 in ESP-IDF

ploegmma
Posts: 20
Joined: Mon Jun 08, 2020 9:10 pm

Re: I would like to use USB host on ESP32-S2 in ESP-IDF

Postby ploegmma » Wed Apr 28, 2021 4:33 pm

cannot open source file "hal/usb_types_private.h"

chegewara
Posts: 2375
Joined: Wed Jun 14, 2017 9:00 pm

Re: I would like to use USB host on ESP32-S2 in ESP-IDF

Postby chegewara » Wed Apr 28, 2021 5:57 pm

zliudr wrote:
Wed Apr 28, 2021 3:14 pm
Thank you! There is a misprint in the README file of both examples, the device descriptor type is not 18, but 1. 18 is length. I hope it's not caused by issues with structs or else.
Yes, there is error in README, it was a bug in logs, but it is also fixed in most recent update in both repositories.
zliudr wrote:
Wed Apr 28, 2021 3:14 pm
So how certain are you that this host interface will be eventually become release version? I'm eager to pick it apart to see how it's done. Anything special to connect the wires? Serial resistors? Be great to have a photo in your repo to show how it's done.
Those repositories are not production ready, but after adding few more esp_err_t checks from esp-idf function and it should be pretty stable code. The thing is esp-idf is supporting only BULK endpoint type so far, which means you are limited to devices that are not using INT or ISO. I was not sure how to handle port and pipes events and i decided to support both, callbacks and events handler, letting users to pick. I also decided to completely ignore polling option, as you can use it without my implementation.
CDC-ACM driver also was initially tested with device based on esp32 S2 and app from arduino.

As for hardware, you dont need anything but wires. Here is description:
https://docs.espressif.com/projects/esp ... s/usb.html
https://docs.espressif.com/projects/esp ... s/dfu.html

ploegmma wrote:cannot open source file "hal/usb_types_private.h"
Did you update esp-idf to most recent master? Latest update is from yesterday.

zliudr
Posts: 360
Joined: Thu Oct 03, 2019 5:15 am

Re: I would like to use USB host on ESP32-S2 in ESP-IDF

Postby zliudr » Fri Apr 30, 2021 3:26 am

Thanks. Any photo of how you connected your dev board to the USB device? I have an ESP32-S2-saola-1 V1.2


zliudr
Posts: 360
Joined: Thu Oct 03, 2019 5:15 am

Re: I would like to use USB host on ESP32-S2 in ESP-IDF

Postby zliudr » Fri Apr 30, 2021 3:52 am

Thanks. From what I gathered in the docs and inspecting my dev board, there are no serial resistors on the D+ and D- lines. I couldn't find any information on the documents regarding what value of serial resistors for inline with D+ and D-, which worries me. The only place I saw them is on S2-WROVER "6 Peripheral Schematics" with two zero-ohm resistors R4 and R6. I know it's not that big of a deal for a mere USB 1.1 host but it's good to know what values to have. I'm used to MAX3421E usb 1.1 host, which requires 33 ohm serial resistors.

chegewara
Posts: 2375
Joined: Wed Jun 14, 2017 9:00 pm

Re: I would like to use USB host on ESP32-S2 in ESP-IDF

Postby chegewara » Fri Apr 30, 2021 4:01 am

Here is my breadboard setup. There is more elements than you need, because sometimes i am using it to do passthru to PC and i am connecting logic analyzer to see packets.
20210430_055907.jpg
20210430_055907.jpg (3.1 MiB) Viewed 8139 times

chegewara
Posts: 2375
Joined: Wed Jun 14, 2017 9:00 pm

Re: I would like to use USB host on ESP32-S2 in ESP-IDF

Postby chegewara » Fri Apr 30, 2021 4:05 am

zliudr wrote:
Fri Apr 30, 2021 3:52 am
Thanks. From what I gathered in the docs and inspecting my dev board, there are no serial resistors on the D+ and D- lines. I couldn't find any information on the documents regarding what value of serial resistors for inline with D+ and D-, which worries me. The only place I saw them is on S2-WROVER "6 Peripheral Schematics" with two zero-ohm resistors R4 and R6. I know it's not that big of a deal for a mere USB 1.1 host but it's good to know what values to have. I'm used to MAX3421E usb 1.1 host, which requires 33 ohm serial resistors.
I dont know MAX3421E, but on S2 saola i dont need any resistors.

godzilla2
Posts: 19
Joined: Wed Apr 28, 2021 5:15 am

Re: I would like to use USB host on ESP32-S2 in ESP-IDF

Postby godzilla2 » Sun May 09, 2021 9:25 am

chegewara, I really apreciate your help.

Were you able to get Bulk endpoints working? Whenever I try to initiate a transfer the pipe goes into a halted hcd_pipe_state and reports a generic error.

Also, I took your code and made a libusb inspired API for hcd. You can see it here.

https://github.com/chipweinberger/xesp- ... ain/main.c

If you're curious to look at my code, the halting problem happens in main.c when I call xesp_usbh_xfer_from_pipe(midi_pipe_in, data_buff);

I've tried a million ways of setting up the transfer, but no luck yet.

zliudr
Posts: 360
Joined: Thu Oct 03, 2019 5:15 am

Re: I would like to use USB host on ESP32-S2 in ESP-IDF

Postby zliudr » Mon May 10, 2021 3:09 am

Hope I have time to check this out in the summer. I can probe with my USB analyzer. I just did some probing to answer an Arduino forum problem on MAX3421E hardware with UHS V2.0 library. Turns out some driver routine probably didn't turn on retry or something so that a set_address command didn't actually keep polling for IN and just gave up. And a more generic sample code with no device-specific driver was able to keep polling a dozen times and the device eventually responded with IN, as the status stage of control transfer. I wonder if there's similar issues with this host stack. Is anyone using USB analyzers to help debug? I'm using Beagle. It's been big help. If you do PC-based USB device-class stuff, you can scrape by with WireShark but with host-class stuff, you need a hardware analyzer or you're just shooting blind.

godzilla2
Posts: 19
Joined: Wed Apr 28, 2021 5:15 am

Re: I would like to use USB host on ESP32-S2 in ESP-IDF

Postby godzilla2 » Mon May 10, 2021 4:55 am

Yes! found the issue. When I open the bulk endpoint the usb device address is no longer zero. I needed that number to be dynamic. Totally overlooked that.

hcd_pipe_config_t config = {
.callback = pipe_isr_callback,
.callback_arg = (void *)port,
.context = NULL,
.ep_desc = use_ep0 ? NULL : ep,
.dev_addr = 0, // Bug! This needed to be the updated device address
.dev_speed = port_speed,
};

Who is online

Users browsing this forum: No registered users and 397 guests