Page 1 of 1

Two MSC with TinyUSB

Posted: Wed Oct 02, 2024 11:49 am
by psparodi
I am developing a system based on an ESP32 S3 where I have two flash memories connected to an SPI port (SPI3) with different CS (chip select). The final goal is to make these memories mountable (as an MSC) on a PC when connecting the ESP32 via USB.

I can successfully mount them on the system (ESP32) by using and modifying the `ext_flash_fatfs` example. Then, based on the `tusb_msc` example, I can mount only one memory when connecting the ESP32 to the PC (acting as a device).

The problem arises when I try to make both appear as MSC devices when connecting the system to a PC. When I attempt to mount the second unit using the function `tinyusb_msc_storage_mount`, the error occurs indicating that I cannot initialize another handler for the second partition, so it only allows me to mount one. The specific part where the error occurs in this function is: `assert(s_storage_handle);`.

Is it possible to use a single USB port (as a device) to mount two flash units when connecting the device to a PC? Is there any available example (I haven’t found anything in the official examples)? Any advice on what the workflow for this might look like?

Best regards.

Re: Two MSC with TinyUSB

Posted: Wed Oct 02, 2024 4:31 pm
by aliarifat794

Re: Two MSC with TinyUSB

Posted: Thu Oct 03, 2024 2:08 pm
by psparodi
Thank you very much for the input. Unfortunately, I can't find anything there that I can include in my current project or that seems compatible with the setup I have partially working. The code file is attached.

I'll summarize what I'm doing to see if anyone can give me a tip on how I could continue:

- I define the I2C bus with parameters of the type: "spi_bus_config_t" and the function "spi_bus_initialize".
- I mount one of the flash memories (16MB Winbond) in the system with parameters of the type "esp_flash_spi_device_config_t" and the sequence of functions: spi_bus_add_flash_device, esp_flash_init, and esp_partition_register_external.
- I do the same with a second flash memory, identical to the first one.
- Then I initialize the tinyUSB configuration, which includes the descriptor (this is the same as in the example included in esp-idf, without modifications).
- I mount the first memory with storage_init_spiflash(&wl_handle, partition_label)). I previously defined a handler (wl_handler). Then tinyusb_msc_storage_init_spiflash(&config_spi) is executed where "config_spi" is of the type "tinyusb_msc_spiflash_config_t" and includes the handler. The mounting is then done with tinyusb_msc_storage_mount(path)). Up to this point, everything works fine, and I have the memory accessible on the PC as an MSC device.

The problem arises when I want to repeat the last step to expose the second memory (already mounted in the ESP32) via USB. For that, I initialize a second handler (I'm not sure if this is fine), and since there is a second handler, I interpret that I should rerun the mounting functions tinyusb_msc_storage_init_spiflash(&config_spi) and tinyusb_msc_storage_mount(path)). The error seems to be that I cannot use another handler. Any clues on what might be happening or how I should adjust the flow of this code?