Skip to content

Commit

Permalink
Merge branch 'feature/usb_msc_updates' into 'master'
Browse files Browse the repository at this point in the history
refactor(usb_host/msc_example): Increase transfer speeds

See merge request espressif/esp-idf!26319
  • Loading branch information
tore-espressif committed Oct 24, 2023
2 parents 687c5cc + e6fde2e commit 717aa73
Show file tree
Hide file tree
Showing 6 changed files with 276 additions and 119 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## IDF Component Manager Manifest File
dependencies:
espressif/esp_tinyusb: "^1.2"
espressif/esp_tinyusb: "^1.4.2"
idf: "^5.0"
6 changes: 4 additions & 2 deletions examples/peripherals/usb/device/tusb_msc/main/tusb_msc_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,8 @@ void app_main(void)

const tinyusb_msc_spiflash_config_t config_spi = {
.wl_handle = wl_handle,
.callback_mount_changed = storage_mount_changed_cb /* First way to register the callback. This is while initializing the storage. */
.callback_mount_changed = storage_mount_changed_cb, /* First way to register the callback. This is while initializing the storage. */
.mount_config.max_files = 5,
};
ESP_ERROR_CHECK(tinyusb_msc_storage_init_spiflash(&config_spi));
ESP_ERROR_CHECK(tinyusb_msc_register_callback(TINYUSB_MSC_EVENT_MOUNT_CHANGED, storage_mount_changed_cb)); /* Other way to register the callback i.e. registering using separate API. If the callback had been already registered, it will be overwritten. */
Expand All @@ -357,7 +358,8 @@ void app_main(void)

const tinyusb_msc_sdmmc_config_t config_sdmmc = {
.card = card,
.callback_mount_changed = storage_mount_changed_cb /* First way to register the callback. This is while initializing the storage. */
.callback_mount_changed = storage_mount_changed_cb, /* First way to register the callback. This is while initializing the storage. */
.mount_config.max_files = 5,
};
ESP_ERROR_CHECK(tinyusb_msc_storage_init_sdmmc(&config_sdmmc));
ESP_ERROR_CHECK(tinyusb_msc_register_callback(TINYUSB_MSC_EVENT_MOUNT_CHANGED, storage_mount_changed_cb)); /* Other way to register the callback i.e. registering using separate API. If the callback had been already registered, it will be overwritten. */
Expand Down
52 changes: 36 additions & 16 deletions examples/peripherals/usb/host/msc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,24 @@

## Overview

This example demonstrates usage of Mass Storage Class to get access to storage on USB memory stick.
Upon connection of USB stick, storage is mounted to Virtual filesystem. Example then creates `ESP` subdirectory(if not present already), as well as `text.txt` file. Its content is then repetitively printed to monitor until USB stick is manually ejected. User can decide whether or not to deinitialize the whole
USB stack or not by shorting GPIO10 to ground. When GPIO10 is left unconnected USB stack is not deinitialized, USB stick can be plugged-in again.
This example demonstrates usage of the MSC (Mass Storage Class) to access storage on a USB flash drive. Upon connection of the flash drive, it is mounted to the Virtual filesystem. The following example operations are then performed:

1. Print device info (capacity, sectors size, and count...)
2. List all folders and files in the root directory of the USB flash drive
3. Create `ESP` subdirectory (if not present already), as well as a `text.txt` file
4. Run read/write benchmarks by transferring 1 MB of data to a `dummy` file


### USB Reconnections

The example is run in a loop so that it can demonstrate USB connection and reconnection handling. If you want to deinitialize the entire USB Host Stack, you can short GPIO0 to GND. GPIO0 is usually mapped to a BOOT button, thus pressing the button will deinitialize the stack.


### Hardware Required

* Development board with USB capable ESP SoC (ESP32-S2/ESP32-S3)
* A USB cable for Power supply and programming
* A USB memory stick
* A USB flash drive

### Common Pin Assignments

Expand All @@ -30,7 +39,7 @@ ESP BOARD USB CONNECTOR (type A)
--
```

Additionally, GPIO10 can be shorted to ground in order to deinitialize USB stack after ejecting USB stick.
Additionally, GPIO0 can be shorted to ground in order to deinitialize USB stack.

### Build and Flash

Expand All @@ -48,16 +57,27 @@ See the Getting Started Guide for full steps to configure and use ESP-IDF to bui

```
...
I (274) cpu_start: Starting scheduler on PRO CPU.
I (339) APP: Waiting for USB stick to be connected
I (380) example: Waiting for USB flash drive to be connected
I (790) example: MSC device connected
...
Device info:
PID: 0x5678
VID: 0xFFFF
iProduct: Disk 2.0
iManufacturer: USB
iSerialNumber: 92072836B2589224378
I (719) APP: Writing file
I (749) APP: Reading file
I (749) APP: Read from file: 'Hello World!'
I (759) APP: Done
Capacity: 29339 MB
Sector size: 512
Sector count: 60088319
PID: 0x5595
VID: 0x0781
iProduct: SanDisk 3.2Gen1
iManufacturer: USB
iSerialNumber: 0401545df64623a907abf299bae54c9
I (990) example: ls command output:
SYSTEM~1
ESP
DUMMY
I (1000) example: Reading file
I (1010) example: Read from file '/usb/esp/test.txt': 'Hello World!'
I (1030) example: Writing to file /usb/esp/dummy
I (2160) example: Write speed 0.93 MiB/s
I (2160) example: Reading from file /usb/esp/dummy
I (3110) example: Read speed 1.10 MiB/s
I (3140) example: Example finished, you can disconnect the USB flash drive
```
2 changes: 1 addition & 1 deletion examples/peripherals/usb/host/msc/main/idf_component.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## IDF Component Manager Manifest File
dependencies:
idf: ">=4.4"
usb_host_msc: "^1.0.4"
usb_host_msc: "^1.1.1"
Loading

0 comments on commit 717aa73

Please sign in to comment.