ESP32-S3 USB MSC and FatFs coexistence

gregory.heifets
Posts: 1
Joined: Sun Jul 09, 2023 11:24 am

ESP32-S3 USB MSC and FatFs coexistence

Postby gregory.heifets » Sun Jul 09, 2023 11:43 am

We're working on an ESP32-S3 project that uses EMMC flash with FAT32 file system that runs on the ESP32.
The EMMC is also accessed by USB MSC when plugged into the PC.

As far as I understand, FatFs that runs on the ESP cannot coexist with MSC.
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.

What is the best strategy to implement this switchover?
Thanks
Greg

pacucha42
Posts: 33
Joined: Fri Mar 29, 2019 12:56 pm

Re: ESP32-S3 USB MSC and FatFs coexistence

Postby pacucha42 » Wed Jul 12, 2023 11:51 am

Hi Greg,
thank you for the report - the question makes a good sense, now we are checking internally what the steps would be the best solution for you. We will let you know ASAP.

Regards,
Martin

tore-espressif
Posts: 19
Joined: Thu Oct 07, 2021 8:11 am

Re: ESP32-S3 USB MSC and FatFs coexistence

Postby tore-espressif » Wed Jul 12, 2023 12:12 pm

Hi Greg,
You are right. Current implementation notifies the user after the memory was unmounted from FatFs https://github.com/espressif/idf-extra- ... age.c#L323, which does not allow you to gracefully end your EMMC transactions.

As a first step, we will provide a hotfix, that will call the callback before the unmount (with possibility to deny the USB mount).

As a second step, we want to investigate options of parallel access to Virtual File System from both USB Host and your application at the same time.

I'll keep you posted

ESP_saurabh.bansal
Posts: 1
Joined: Tue Sep 27, 2022 8:51 am

Re: ESP32-S3 USB MSC and FatFs coexistence

Postby ESP_saurabh.bansal » Wed Jul 19, 2023 5:27 am

Hello Greg,

The code v3.1.1 is released that notifies through callback before mount/unmount operation.

Code commit: https://github.com/espressif/idf-extra- ... 86c1209e3d

Thanks.

mcclellansws
Posts: 1
Joined: Mon Oct 21, 2024 3:50 pm

Re: ESP32-S3 USB MSC and FatFs coexistence

Postby mcclellansws » Mon Oct 21, 2024 4:09 pm

tore-espressif wrote:
Wed Jul 12, 2023 12:12 pm

As a second step, we want to investigate options of parallel access to Virtual File System from both USB Host and your application at the same time.

I'll keep you posted
Any progress with this?

ESP_Sprite
Posts: 9764
Joined: Thu Nov 26, 2015 4:08 am

Re: ESP32-S3 USB MSC and FatFs coexistence

Postby ESP_Sprite » Wed Oct 23, 2024 1:28 am

mcclellansws wrote:
Mon Oct 21, 2024 4:09 pm
tore-espressif wrote:
Wed Jul 12, 2023 12:12 pm

As a second step, we want to investigate options of parallel access to Virtual File System from both USB Host and your application at the same time.

I'll keep you posted
Any progress with this?
Don't expect this to work reliably over MSC. MSC offers a block device to the host, and the host can do whatever it wants with that block device; the only implicit rule is that it leaves a valid fatfs filesystem once it's done (unplugged). That means as long as it's plugged in, the flash can be in any random state, and fatfs won't be able to correctly interpret its contents (as it doesn't know the internal state of the host). There's other protocols, like mtp, that work on a file-based level and would be more stable.

Who is online

Users browsing this forum: Bing [Bot] and 114 guests