Skip to content

refactor(tinyusb_msc): Device callbacks #178

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

Draft
wants to merge 3 commits into
base: esp_tinyusb/v2.0
Choose a base branch
from

Conversation

roma-jam
Copy link
Collaborator

@roma-jam roma-jam commented May 23, 2025

Requirements

The idea is to unmount the EMMC and finalize the EMMC transactions gracefully before MSC takes control of the EMMC. From what we've seen, the MSC takes over the EMMC at the moment the USB is plugged-in without any notification.

Reference link: https://esp32.com/viewtopic.php?f=13&t=34535

However, please consider a bit of polishing and adding more comments in future follow-ups.

Reference link: espressif/idf-extra-components#210 (review)

Description

This is a refactoring of currently present logic of MSC storage callbacks.

Changes simplify the callback logic by:

  • merging the callbacks into one callback with event_id and options argument.
  • decreasing amount of the code
  • splitting the code for spiflash and sdmmc to increase code clarity in tinyusb_msc.

Key Features

  1. Curved out storage code from tusb_msc_storage.c. Now, the spiflash and sdmmc have their own storage logic, available by the common API for the MSC storage.
  2. Renamed tusb_msc_storage.c to tinyusb_msc.c. The rule is: all the upstream code from TinyUSB starts with tusb_* all additional code from our side starts with tinyusb_*. For example: tinyusb_task.c, tinyusb_msc.c and so on.
  3. Introduced the dynamic configuration for the storage type: TINYUSB_MSC_STORAGE_TYPE_SPIFLASH or TINYUSB_MSC_STORAGE_TYPE_SDMMC. Only one function for the driver installation: tinyusb_msc_storage_init(&config).
  4. Added possibility to select mount point (APP or USB) during the driver installation. User can select config.mount_point = TINYUSB_MSC_STORAGE_MOUNT_APP, and after driver installation the storage will be mounted to the APP. Valuable, when device is self_powered and we need to access the storage from the APP before the device
    will be connected to the USB Host.
  5. Merged the callbacks to the one callback with user argument.
  6. Added the FS format flags configuration (instead of build-time Kconfig)

Related

Testing

  • Added a test application msc_storage, based on the spiflash that verifies the callbacks presence, mounting logic and memory leakages during intall/uninstall.

Checklist

Before submitting a Pull Request, please ensure the following:

  • 🚨 This PR does not introduce breaking changes.
  • All CI checks (GH Actions) pass.
  • Documentation is updated as needed.
  • Tests are updated or added as necessary.
  • Code is well-commented, especially in complex areas.
  • Git history is clean — commits are squashed to the minimum necessary.

@roma-jam roma-jam changed the title feat(tusb_msc): Add device mount/unmount callback refactor(tusb_msc): Device callbacks May 23, 2025
@roma-jam roma-jam self-assigned this May 24, 2025
@roma-jam roma-jam added this to the esp_tinyusb v2.0.0 milestone May 24, 2025
@roma-jam roma-jam force-pushed the refactor/tinyusb_msc_storage_callbacks branch from 893f617 to 3f44d4a Compare May 24, 2025 11:18
@roma-jam roma-jam changed the base branch from master to feature/tinyusb_events_callback May 24, 2025 11:20
@roma-jam roma-jam force-pushed the feature/tinyusb_events_callback branch from a738da5 to 35533b4 Compare May 28, 2025 08:24
@roma-jam roma-jam force-pushed the refactor/tinyusb_msc_storage_callbacks branch from 3f44d4a to a9e2976 Compare May 28, 2025 08:24
@roma-jam roma-jam changed the title refactor(tusb_msc): Device callbacks refactor(tinyusb_msc): Device callbacks May 28, 2025
@roma-jam roma-jam force-pushed the refactor/tinyusb_msc_storage_callbacks branch from a9e2976 to e6376fb Compare May 28, 2025 14:38
@roma-jam roma-jam force-pushed the feature/tinyusb_events_callback branch from 35533b4 to c3c3992 Compare June 2, 2025 08:08
@roma-jam roma-jam force-pushed the refactor/tinyusb_msc_storage_callbacks branch from e6376fb to 4be6ebd Compare June 2, 2025 08:12
Base automatically changed from feature/tinyusb_events_callback to esp_tinyusb/v2.0 June 2, 2025 10:33
@roma-jam roma-jam force-pushed the refactor/tinyusb_msc_storage_callbacks branch from 4be6ebd to 5c0fa6a Compare June 2, 2025 10:36
@roma-jam roma-jam force-pushed the refactor/tinyusb_msc_storage_callbacks branch from 5c0fa6a to f8e1a45 Compare June 2, 2025 17:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants