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

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

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

Postby zliudr » Mon Jan 04, 2021 4:52 am

The current support is a USB composite device with a CDC driver. That's not what I'm interested in using. Are there any references of how to write your own code to interface with tinyUSB, such as sending out BULK IN, responding to control transfer etc.? My first place to look will be the CDC driver in IDF though but I just wonder if there are anything else. My goal is to port my usb device-class code to esp32-s2 or s3. Also, any plan to enable usb host mode on s2 and s3? Thanks.
Last edited by zliudr on Fri Mar 19, 2021 3:08 am, edited 1 time in total.

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

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

Postby chegewara » Mon Jan 04, 2021 5:27 am

I think the best source is this repository with examples:
https://github.com/hathach/tinyusb

but you can also check those examples:
https://github.com/chegewara/esp-idf/tr ... herals/usb

I dont have any info about host driver, but i think its still few months before we will get it ready to start with.

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

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

Postby zliudr » Thu Feb 18, 2021 10:00 pm

Thanks for your response and sorry it took so long to get back. I'm still interested in tinyUSB host stuff.

When you said the host code won't be ready, do you mean there's currently no way to interact with the ESP32-s2 USB controller in the host mode using tinyUSB calls?

Are the basic functions supported under ESP-IDF, tinyUSB, both, such as control transfer, BULK IN and OUT? I could just do straight polling instead of using the "periodic TX FIFO" which sounds like it's for INT EP purposes. If I could do the bare minimum, with control transfer, bulk in and out, then I'm good. I can transplant my own host stack on top of these functions.

I don't see any inclusion of usb host code:

https://github.com/espressif/esp-idf/bl ... eLists.txt

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

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

Postby ESP_Sprite » Fri Feb 19, 2021 1:21 am

There is no functional host mode in ESP-IDF/tinyUSB as of yet. We're working on developing something.

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

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

Postby zliudr » Fri Feb 19, 2021 1:50 pm

Thank you! Would you be posting in the announcement if you have something like basic host setup function and control_transfer, bulk in/out? I am happy to test your code. I just started reading the hardware reference manual on S2's USB peripheral and could provide some assistance in testing your code. I'm familiar with the UHS library made for arduino and MAX3421E USB host IC. I'm going to read tinyUSB's host stack for some understanding.

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

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

Postby ESP_Sprite » Sat Feb 20, 2021 1:50 am

Sure, will see if we can give you a headsup once the code hits the public git repos. Note that we likely won't be using the TinyUSB host stack, we have something more libusb-like in the works.

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

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

Postby zliudr » Mon Feb 22, 2021 3:07 am

Great! I've started reading libusb documentation. It's good to know how it does its work. TinyUSB doesn't have a good usb host stack so it's good to not use it for host. I will definitely test out libusb once you release a version of ESP-IDF with the support.

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 Mar 19, 2021 3:08 am

Any release date for the usb host stack? Thanks.

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

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

Postby ESP_Dazz » Fri Mar 19, 2021 7:59 am

A part of the HCD is now pushed to master (see link) if you need some sort of support immediately. However the HCD currently only supports Bulk and Control transfers.

However, do note that this is a private_include and the API will likely change. See the maintainers_notes.md for more information regarding the API.

chegewara
Posts: 2378
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 Mar 19, 2021 8:28 pm

ESP_Dazz wrote:
Fri Mar 19, 2021 7:59 am
A part of the HCD is now pushed to master (see link) if you need some sort of support immediately. However the HCD currently only supports Bulk and Control transfers.

However, do note that this is a private_include and the API will likely change. See the maintainers_notes.md for more information regarding the API.
I would like to thank you for update and posting API to github.
I am trying to start to work with it, by copy/paste code from test cases, but i can get any port events even if basic code should be fine. Here is output log from init of USB host:

Code: Select all

I (632) : USB host setup properly
I (732) : hcd_port_state_t: 0 // HCD_PORT_STATE_NOT_POWERED
I (732) : Port powered ON
I (732) : hcd_port_state_t: 1 // HCD_PORT_STATE_DISCONNECTED
Then i have task that is awaiting port queue events and nothing received. I also added this code, but still nothing:

Code: Select all

    hcd_port_state_t state = hcd_port_get_state(port_hdl);
    ESP_LOGI("", "hcd_port_state_t: %d", state);
    //Power ON the port
    if(ESP_OK == hcd_port_command(port_hdl, HCD_PORT_CMD_POWER_ON)) ESP_LOGI("", "Port powered ON");
    state = hcd_port_get_state(port_hdl);
    ESP_LOGI("", "hcd_port_state_t: %d", state);
    //Wait for connection event
    printf("Waiting for conenction\n");
    phy_force_conn_state(true, pdMS_TO_TICKS(100));     //Allow for connected state on PHY
    hcd_port_event_t event;

    while (!isConnected) // await on port queue event
    {
        if(HCD_PORT_EVENT_CONNECTION == (event = hcd_port_handle_event(port_hdl))) { // additionally polling for debugging purpose
            ESP_LOGI("", "HCD_PORT_EVENT_CONNECTION");
            isConnected = true;
        } else if(event != HCD_PORT_EVENT_NONE) {
            ESP_LOGE("", "port event: %d", event);
        }
        vTaskDelay(1);
    }
I am using socket like this (i know its USB 3.0) soldered on PCB:
https://pl.rs-online.com/web/p/zlacza-usb/1225096/

Ive been trying to swap pins 19 and 20, but no success.
EDIT connected USB device is just CP2102N (esp32 S2 - saola)

Am i missing something?

Thanks

Who is online

Users browsing this forum: No registered users and 132 guests