Skip to content

Create two USB MSC using different partitions, with access to only one partition (IEC-468) #362

@PR2403

Description

@PR2403

Answers checklist.

  • I have read the component documentation ESP-IDF Components and the issue is not addressed there.
  • I am using target and esp-idf version as defined in component's idf_component.yml
  • I have searched the issue tracker for a similar issue and not found any related issue.

Which component are you using? If you choose Other, provide details in More Information.

device/esp_tinyusb

ESP-IDF version.

v5.5.1

Development Kit.

custom esp32s3 n16r8

Used Component version.

2.0.1~1

More Information.

I saw #define TINYUSB_MSC_STORAGE_MAX_LUNS 2
run the code

static esp_err_t storage_init_spiflash(wl_handle_t *wl_handle, char *label)
{
    char TAG[] = "usb_msc_test";
    ESP_LOGI(TAG, "Initializing wear levelling");

    const esp_partition_t *data_partition = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_FAT, label);
    if (data_partition == NULL)
    {
        ESP_LOGE(TAG, "Failed to find FATFS partition. Check the partition table.");
        return ESP_ERR_NOT_FOUND;
    }

    return wl_mount(data_partition, wl_handle);
}
void usb_msc_test(void *arg)
{
    char TAG[] = "usb_msc_test";
    ESP_LOGI(TAG, "Initializing storage...");

    wl_handle_t wl_handle = WL_INVALID_HANDLE;

    ESP_ERROR_CHECK(storage_init_spiflash(&wl_handle, "lua"));

    tinyusb_msc_storage_handle_t storage_hdl = NULL;

    tinyusb_msc_storage_config_t storage_cfg;
    memset(&storage_cfg, 0, sizeof(storage_cfg));
    storage_cfg = {
        .medium = {.wl_handle = wl_handle},
        .fat_fs = {
            .base_path = "/usb", // User specific base path
        },
        .mount_point = TINYUSB_MSC_STORAGE_MOUNT_USB, // Initial mount point to APP
    };

    ESP_ERROR_CHECK(tinyusb_msc_new_storage_spiflash(&storage_cfg, &storage_hdl));

    wl_handle_t wl_handle2 = WL_INVALID_HANDLE;

    ESP_ERROR_CHECK(storage_init_spiflash(&wl_handle2, "lua_2"));

    tinyusb_msc_storage_handle_t storage_hdl2 = NULL;

    tinyusb_msc_storage_config_t storage_cfg2;
    memset(&storage_cfg2, 0, sizeof(storage_cfg2));
    storage_cfg2 = {
        .medium = {.wl_handle = wl_handle2},
        .fat_fs = {
            .base_path = "/usb_2", // User specific base path
        },
        .mount_point = TINYUSB_MSC_STORAGE_MOUNT_USB, // Initial mount point to APP
    };

    ESP_ERROR_CHECK(tinyusb_msc_new_storage_spiflash(&storage_cfg2, &storage_hdl2));

    const tinyusb_config_t tusb_cfg = TINYUSB_DEFAULT_CONFIG();
    ESP_ERROR_CHECK(tinyusb_driver_install(&tusb_cfg));
}

partitions.csv

nvs,      data, nvs,     0x9000,  0x6000,
phy_init, data, phy,     0xf000,  0x1000,
factory,  app,  factory, 0x10000, 1M,
lua,      data, fat,     ,        1M,
lua_2,    data, fat,     ,        1M,

on host, it shows 2 usb disk, but they are the same partition, they have same content

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions