ESP32-S2 USB bus detection

matt.wood
Posts: 3
Joined: Mon Apr 12, 2021 1:32 pm

ESP32-S2 USB bus detection

Postby matt.wood » Mon Apr 12, 2021 1:39 pm

Hi All,
I'm currently using the ESP-IDF USB console feature on ESP-IDF v4.4-dev-744-g1cb31e509-dirty
And I have been unable to find any means to detect if the USB CDC has actually enumerated, is there anyway to detect when the data connection has been made?
In my firmware I would like to go to sleep if the connection appears to be power only, but stay awake for CDC comms if a PC is attached.

I looked through the USB docs on the wiki and the page in the reference manual, is there a register perhaps I can use to determine if the device has been enumerated? Or perhaps a sneeky function hidden away.

Thanks In Advance
Matt

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

Re: ESP32-S2 USB bus detection

Postby chegewara » Mon Apr 12, 2021 10:04 pm

To detect connection with host you can use this callback. Good CDC/ACM driver will always change DTR and/or RTS line state:

Code: Select all

tud_cdc_line_coding_cb
Also this callback should be good (maybe even better):

Code: Select all

tud_mount_cb

matt.wood
Posts: 3
Joined: Mon Apr 12, 2021 1:32 pm

Re: ESP32-S2 USB bus detection

Postby matt.wood » Tue Apr 13, 2021 8:58 am

Hi chegewara
Thanks for the tip,
I was using the menuconfig usb stdio system but I guess I have to switch back to using tiny usb to get this feature.

These call back do appear to work correctly, thanks, but I am now having a different issue.
I was using the esp console system but this requires the esp-idf cdc setup, I have attempted to force it to work over the tiny usb cdc port but this seems to be broken.
First issues:
The tinyusb CDC system does not have functions to configure line endings so there were no implementations for these functions

Code: Select all

void esp_vfs_dev_cdcacm_set_tx_line_endings(esp_line_endings_t mode)
void esp_vfs_dev_cdcacm_set_rx_line_endings(esp_line_endings_t mode)
Fortunately the CDC is preconfigured with line ending that match what the console system was going to set them too

After putting in some stub functions to allow this setup to compile I was able to run the system but the com port seems to put out esp> followed by a large block of 0xFF characters and it repeats this endlessly...

This appears to be related to how linenoise uses the stdio, if I force it out of 'dumb mode' it stops spamming 0xFF but starts spamming 'esp>'

Does anyone have any suggestions of what I can do to get esp console to play nicely with tinyusb CDC?
Or perhaps an existing example I can examine

Many Thanks
Matt

matt.wood
Posts: 3
Joined: Mon Apr 12, 2021 1:32 pm

Re: ESP32-S2 USB bus detection

Postby matt.wood » Tue Apr 13, 2021 4:49 pm

I think I've figured out why it is misbehaving, they getc does not seem to block on the redirected stdio using TUSB,
not using the ESP Console system at them moment, if anyone knows a real solution or work around it would be much appreciated.

Best Regards,
Matt

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

Re: ESP32-S2 USB bus detection

Postby chegewara » Tue Apr 13, 2021 5:48 pm

If you could post simple code to explain where it is not working for you and with your findings it could be useful. Also it may be a bug, so it can help espressif.

Who is online

Users browsing this forum: ESP_Roland, ESP_rrtandler and 109 guests