Two MSC with TinyUSB

psparodi
Posts: 3
Joined: Wed Oct 02, 2024 11:17 am

Two MSC with TinyUSB

Postby psparodi » Wed Oct 02, 2024 11:49 am

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.

aliarifat794
Posts: 200
Joined: Sun Jun 23, 2024 6:18 pm

Re: Two MSC with TinyUSB

Postby aliarifat794 » Wed Oct 02, 2024 4:31 pm


psparodi
Posts: 3
Joined: Wed Oct 02, 2024 11:17 am

Re: Two MSC with TinyUSB

Postby psparodi » Thu Oct 03, 2024 2:08 pm

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?
Attachments
tusb_msc_main.c
(11.34 KiB) Downloaded 44 times

Who is online

Users browsing this forum: Baidu [Spider], federicolonghin and 231 guests