Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

esp32s3 usb host example cdc_acm_bg96 receive some message repeatly (IDFGH-7027) #8645

Closed
zhuyeaini9 opened this issue Mar 24, 2022 · 15 comments
Labels
Resolution: Done Issue is done internally Status: Done Issue is done internally

Comments

@zhuyeaini9
Copy link

zhuyeaini9 commented Mar 24, 2022

Hi all:
I used the esp32s3 board to develop one usb host fuction.
I used the master branch code.
the device was the cdc-like device which connect to esp32s3's usb[GPIO 19 20] via one usb to uart chip(ft231xq).
I can find this device by the example of usb host lib,which show below info:
//-----------------------------------------------------------------------
*** Device descriptor ***
bLength 18
bDescriptorType 1
bcdUSB 2.00
bDeviceClass 0x0
bDeviceSubClass 0x0
bDeviceProtocol 0x0
bMaxPacketSize0 8
idVendor 0x403
idProduct 0x6015
bcdDevice 0.00
iManufacturer 1
iProduct 2
iSerialNumber 3
bNumConfigurations 1
I (5417) CLASS: Getting config descriptor
*** Configuration descriptor ***
bLength 9
bDescriptorType 2
wTotalLength 32
bNumInterfaces 1
bConfigurationValue 1
iConfiguration 0
bmAttributes 0xa0
bMaxPower 90mA
*** Interface descriptor ***
bLength 9
bDescriptorType 4
bInterfaceNumber 0
bAlternateSetting 0
bNumEndpoints 2
bInterfaceClass 0xff
iInterface 2
*** Endpoint descriptor ***
bLength 7
bDescriptorType 5
bEndpointAddress 0x81 EP 1 IN
bmAttributes 0x2 BULK
wMaxPacketSize 64
bInterval 0
*** Endpoint descriptor ***
bLength 7
bDescriptorType 5
bEndpointAddress 0x2 EP 2 OUT
bmAttributes 0x2 BULK
wMaxPacketSize 64
bInterval 0
I (5477) CLASS: Getting Manufacturer string descriptor
FTDI
I (5487) CLASS: Getting Product string descriptor
FT231X USB UART�
I (5487) CLASS: Getting Serial Number string descriptor
DQ008964
//-----------------------------------------------------------------------
but when I try the example of cdc_acm_bg96,
of course I change the code of vid,pid to my device.
comment some code of bg96 special,like send AT cmd etc.
so the code is simple:
1.open the device with rx handle function.
2.print data of rx handle function.
the device seems open ok from log:
//--------------
D (2430) USBH: Processing actions 0x100
D (2430) USBH: New device 1
D (2440) cdc_acm: New device connected
D (2440) cdc_acm: Checking list of connected USB devices
D (2450) CDC_ACM: Submitting poll for BULK IN transfer
D (2450) CDC_ACM: in xfer cb
//-------------
but I received repeated messages which has len 2,
first was 0x11,two was 0x60.
it received again and again.
the device is ok,I connect it to pc's usb port.
it works,it not send the 0x11 0x60 message.
it just return message after I send some cmd to it.
I check the ascii,the 0x11 ofter used for XON flag,I don't know what should I do.
from the cdc_acm_bg96's readme,the device should be support:
//--------------------------------------

Supported Devices

The CDC-ACM Host driver supports the following types of CDC devices:

  1. CDC-ACM devices
  2. CDC-like vendor specific devices (usually found on USB to UART bridge devices)

CDC-Like Vendor Specific Devices

The CDC-ACM Class driver supports CDC-like devices that meet the following requirements:

  • The device class code must be set to the vendor specific class code 0xFF
  • The device needs to provide and interface containing the following endpoints:
    • (Mandatory) Two Bulk endpoints (IN and OUT) for data
    • (Optional) An interrupt endpoint (IN) for the notification element

For CDC-like devices, users are responsible for ensuring that they only call APIs (e.g., cdc_acm_host_send_break()) that are supported by the target device.
//-----------------------------------------------

any advice is welcome!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

@espressif-bot espressif-bot added the Status: Opened Issue is new label Mar 24, 2022
@github-actions github-actions bot changed the title esp32s3 usb host example cdc_acm_bg96 receive some message repeatly esp32s3 usb host example cdc_acm_bg96 receive some message repeatly (IDFGH-7027) Mar 24, 2022
@tore-espressif
Copy link
Collaborator

Hello @zhuyeaini9 , thank you for reaching out to us.

I can confirm that I reproduced the problem with FTDI 232RQ (PID: 0x6001), that is almost the same as your chip (comparison here)

It is something FTDI specific, but I'll prepare an example how to handle this

@tore-espressif
Copy link
Collaborator

Hello again @zhuyeaini9

I could reproduce the same issue on Windows too:
FTDI chips use their custom packet format, so the first two bytes are not data but rather status bytes. They are coded as follows:

image

The real RX data start at data[2]. So very simple RX handler would look like this:

static void handle_rx(uint8_t *data, size_t data_len, void *user_arg) {
    if (data_len > 2) {
        // You can check the status bytes here
        for (int j = 2; j < data_len; j++) {
            putchar(data[j]); // Print to ESP monitor
        }
    }
}

However, the FTDI chip won't send you any data before you configure it's line properties (parity, stop bits...) and baudrate via FTDI's custom commands.

ATM, I'm updating the CDC driver to allow such extension. I'll keep you updated.

@zhuyeaini9
Copy link
Author

thanks@tore-espressif,really helpful.
for the line coding setting.
I remember I also try the method:cdc_acm_host_line_coding_set
after open the device,but the log show error of it:
//---------------------------------
E (9640) cdc_acm: cdc_acm_host_set_control_line_state(1113):
//---------------------------------

@tore-espressif
Copy link
Collaborator

That's correct, FTDI chips don't use commands as defined in USB CDC specification but their own vendor specific commands.

The FTDI implementation is currently under internal review. I'll update this issue when it gets public, thanks!

@zhuyeaini9
Copy link
Author

That's correct, FTDI chips don't use commands as defined in USB CDC specification but their own vendor specific commands.

The FTDI implementation is currently under internal review. I'll update this issue when it gets public, thanks!

got it.

@espressif-bot espressif-bot added Status: In Progress Work is in progress and removed Status: Opened Issue is new labels Mar 31, 2022
@zhuyeaini9
Copy link
Author

any update?

tore-espressif added a commit to tore-espressif/esp-idf that referenced this issue Apr 11, 2022
This example implements usual UART/USB convertor driver.
Closes espressif#8645
@tore-espressif
Copy link
Collaborator

tore-espressif commented Apr 11, 2022

@zhuyeaini9 sorry for the delay.

If you are willing to test my work-in-progress code, you can try this example: https://github.com/tore-espressif/esp-idf/tree/feature/usb_host/cdc_custom_commands/examples/peripherals/usb/host/cdc/cdc_acm_vcp

The API can change in the official release, though.

There are couple of points we need to internally agree upon/fix:

  • Currently the examples are in C++ only, as we need to override certain functions (FTDI specific) which is easily done in C++
  • Creating and destroying the driver object is not clean

Your feedback would be greatly appreciated, thanks!

@zhuyeaini9
Copy link
Author

thanks update!

I try your example cdc_acm_vcp,it works well!
I can get correct reply from my cmd:
//---------------------------------------------------------
I (313) VCP example: Installing USB Host
I (343) VCP example: Installing CDC-ACM driver
I (343) VCP example: Opening FT232 UART device
I (743) FT23x: Baudrate required: 115200, set: 115384
I (743) VCP example: Setting up line coding
I (743) FT23x: Baudrate required: 115200, set: 115384
Manual Read
RD -0.64220,0.11727,0.47023
//---------------------------------------------------------

tore-espressif added a commit to tore-espressif/esp-idf that referenced this issue Apr 22, 2022
This example implements usual UART/USB convertor driver.
Closes espressif#8645
@espressif-bot espressif-bot added Resolution: NA Issue resolution is unavailable Status: Done Issue is done internally Resolution: Done Issue is done internally and removed Status: In Progress Work is in progress Resolution: NA Issue resolution is unavailable labels Apr 24, 2022
@S0UL4
Copy link

S0UL4 commented Mar 26, 2024

Hello,
Thank you for your work @tore-espressif
Does this example works also with the FT2232D ?

@tore-espressif
Copy link
Collaborator

Hello,
Thank you for your work @tore-espressif
Does this example works also with the FT2232D ?

Hello, I have not tested with FT2232D.

You can easily try it out by updating the PID of the device in the driver and invoke this constructor https://github.com/espressif/esp-usb/blob/master/host/class/cdc/usb_host_ftdi_vcp/include/usb/vcp_ftdi.hpp#L38

@S0UL4
Copy link

S0UL4 commented Mar 26, 2024

Thank you so much for your quick reponse, the codes are compatible also with the SIP ESP32-S3-PICO as it has the USB 1.1 OTG support right ?

@tore-espressif
Copy link
Collaborator

yep, all modules based on S3 have USB 1.1 host support.

@S0UL4
Copy link

S0UL4 commented Mar 26, 2024

You are the best guys, thank you !

@tore-espressif
Copy link
Collaborator

Beaware of hardware of your development board. Not all boards have USB (pin 19 and 20) wired out to USB-A connector

@S0UL4
Copy link

S0UL4 commented Mar 31, 2024

Excuse me, please. Can this library be independent of ESP32? I believe it can be used on other boards as well, since it's written entirely in C++ code. Am I right? Also, does this library support bidirectional communication?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution: Done Issue is done internally Status: Done Issue is done internally
Projects
None yet
Development

No branches or pull requests

4 participants