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

ESP32 S3 TinyUSB problems with USB unplugging detection (IDFGH-11193) #12360

Closed
3 tasks done
SlySquirrel opened this issue Oct 5, 2023 · 14 comments
Closed
3 tasks done
Assignees
Labels
Resolution: Done Issue is done internally Status: Done Issue is done internally Type: Bug bugs in IDF

Comments

@SlySquirrel
Copy link

Answers checklist.

  • I have read the documentation ESP-IDF Programming Guide and the issue is not addressed there.
  • I have updated my IDF branch (master or release) to the latest version and checked that the issue is present there.
  • I have searched the issue tracker for a similar issue and not found a similar issue.

IDF version.

esp-idf-v5.1.1

Espressif SoC revision.

ESP32 S3

Operating System used.

Linux

How did you build your project?

Eclipse IDE

If you are using Windows, please specify command line type.

None

Development Kit.

ESP32-S3-WROOM-1

Power Supply used.

USB

What is the expected behavior?

I'm using an example tusb_msc from esp-idf-v5.1.1 and using spiflash to store files. My device is expected to be Self-Powered Device.
I did everything as described in this documentation in the section Self-Powered Device

const tinyusb_config_t tusb_cfg = {
.device_descriptor = &descriptor_config,
.string_descriptor = string_desc_arr,
.string_descriptor_count = sizeof(string_desc_arr) / sizeof(string_desc_arr[0]),
.external_phy = false,
.configuration_descriptor = desc_configuration,
.self_powered = true,
.vbus_monitor_io = GPIO_NUM_1
};

I expect that when I disconnect the device from USB I will have access to files on the SPI flash. But when I disconnect the device from the PC, the tud_umount_cb() function is not called and tinyusb_msc_storage_in_use_by_usb_host() returns true. Function tud_umount_cb() call only when I umount device from PC, if remove device without umount from PC there is no event to determine whether the device is connected or not.

What is the actual behavior?

I expected that using the vbus_monitor_io would generate a connection and disconnection event on the USB bus.

Steps to reproduce.

Flash tusb_msc example and remove from PC without manual umount.

Debug Logs.

No response

More Information.

No response

@SlySquirrel SlySquirrel added the Type: Bug bugs in IDF label Oct 5, 2023
@espressif-bot espressif-bot added the Status: Opened Issue is new label Oct 5, 2023
@github-actions github-actions bot changed the title ESP32 S3 TinyUSB problems with USB unplugging detection ESP32 S3 TinyUSB problems with USB unplugging detection (IDFGH-11193) Oct 5, 2023
@tore-espressif
Copy link
Collaborator

hi @SlySquirrel could you please share your HW connection of VBUS to ESP32-S3?

@SlySquirrel
Copy link
Author

Hi, I use hw design similar as https://github.com/wuxx/nanoESP32-S3 with battery supply and VBUS connection
image_2023-10-23_10-49-24
VBUS connect only R35(20 kOm)/R36(41.2 KOm). When USB connect on IO1 about 3.3V. C24 not present.

@tore-espressif
Copy link
Collaborator

Thanks, I'll try to reproduce the problem with your HW setup and let you know ;)

@silverchris
Copy link

I am also having this issue.
ESP-IDF v5.1.2

If I read the GPIO with gpio_get_level, it returns the expected value with usb connected and disconnected.

@tore-espressif
Copy link
Collaborator

Hi, I'm sorry for the extraordinary slow responses here. I'll get to it ASAP

@tore-espressif
Copy link
Collaborator

Hello @silverchris and @SlySquirrel thank you for your patience.
Indeed, there is a regression in our tinyusb version >= 0.15, we will fix soon.

In the meanwhile, you can use tinyusb v0.14. It contains the same features for MSC device as v0.15.

You can do this be requiring specific version in your main/idf_component.yml like this:

## IDF Component Manager Manifest File
dependencies:
  espressif/esp_tinyusb: "^1.4.2"
  espressif/tinyusb: '0.14.2'

Also please make sure that the pin you are using for VBUS monitoring is not used by any other peripheral. Here's a nice summary for ESP32-S3 https://www.luisllamas.es/en/which-pins-can-i-use-on-esp32-s3/

@tore-espressif tore-espressif self-assigned this Jan 12, 2024
@espressif-bot espressif-bot added Status: Selected for Development Issue is selected for development and removed Status: Opened Issue is new labels Jan 12, 2024
@silverchris
Copy link

@tore-espressif downgrading to 0.14.2 fixed it for me. Thank you!

@espressif-bot espressif-bot added Status: Reviewing Issue is being reviewed and removed Status: Selected for Development Issue is selected for development labels Jan 17, 2024
@diplfranzhoepfinger
Copy link
Contributor

Hi, 

Question:

when the USB Storage is exposed to the Host, the Storage is no more accessible by the Application ?

@diplfranzhoepfinger
Copy link
Contributor

https://github.com/espressif/esp-idf/tree/b3f7e2c/examples/peripherals/usb/device/tusb_msc

well described here. 

so a "Shared" Access is per Standard not possible right ?

@tore-espressif
Copy link
Collaborator

so a "Shared" Access is per Standard not possible right ?

This is not per (USB) Standard but per differences how the MSC host and the application access the memory partition.

The MSC host accesses memory sectors while the application accesses files (implemented in FATFS):

in general it is impossible to ensure file consistency when the disk is mounted both to the app and to the host (Unless both the host and the device mount the FS read-only)
The problem is that if the MSC host updates the FAT, then the FAT FS code running on the device won't "know" that something on disk has changed, and won't "reload" the FAT from disk.

@igrr
Copy link
Member

igrr commented Jan 22, 2024

Just to add, MTP class tries to address this problem. Here is the issue about supporting it in tinyusb: hathach/tinyusb#1079

@diplfranzhoepfinger
Copy link
Contributor

@igrr very cool

@espressif-bot espressif-bot added Status: Selected for Development Issue is selected for development Status: In Progress Work is in progress and removed Status: Reviewing Issue is being reviewed Status: Selected for Development Issue is selected for development labels Jan 23, 2024
@roma-jam
Copy link
Collaborator

Hello everyone,
Thank you for your patience.

Indeed, there is a regression in our tinyusb version >= 0.15, we will fix soon.

New version is available: espressif/tinyusb^0.15.0~5
Please update the manifest file accordingly.

@espressif-bot espressif-bot added Status: Done Issue is done internally Resolution: Done Issue is done internally and removed Status: Reviewing Issue is being reviewed labels Mar 11, 2024
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 Type: Bug bugs in IDF
Projects
None yet
Development

No branches or pull requests

8 participants