Expose the ESP32-S3 flash as mass storage device

Hello everybody.

I am testing a ESP32-S3-WROOM-2 MCN32R16V (32 MB of flash and 16 MB PSAM).

I know how to enabled a mass storage device by going to tools and selecting the appropriate options. The thing is the mass storage device showed in the computer is for the firmware.

I would like to know if it is possible to present part of the flash memory as a different mass storage device in the computer. I mean, I would connect the ESP to the computer and a mass storage device would appear showing what is inside of a flash partition.

I know there are different types of file systems and to be compatible to the computer it would need to be some fat kind, I suppose. Is there an example code that does this?

I also know there is a similar post about htis but with no definitive answer.

Thank you for your time.

What firmware? Is that in flash? Is it safe from over-writing?

AFAIK every SD card has an MCU and flash. The MCU does wear-leveling of sectors as well as maintaining a front end that acts like a DOS FAT drive or as a Sansa drive.

Do you want to make a securable wifi flash drive?

Yes. You may need to write the code, though.

wouldn't the USB inteface need to looks like a falsh drive, not a serial interface?

When I wire SD to an Uno via SPI, it’s all text comms. The looks like a drive is done by the SD MCU but the interface is serial text.

The ESP should be able to act like a drive over wifi, no?

Not saying the code will be small but most of it may exist already.

The flash is big, 32 MB, so I can partition it. Some will be reserved to the firmware and other to flash whatever I want, and it is this last one that a want to expose as a normal USB stick to the computer when a USB cable is connected between the ESP and the computer.

I know I have to write code. The thing is, are any of you aware if there is an example for this? Some guidelines?

My objective is to put some files in a flash partition when initially programmed, but then after I can delete or add more files when connecting to a computer. I also want to be able to access the files by the code.

Thank you.

is this suppose to be code on the Arduino that allows it to be recognizeds as a FLASH drive plugged into USB?

or is this code that allows you to write code on the PC/laptop to read/write files via a USB serial interface ?

Hello @gcjr.

The only thing the computer sees is a mass storage device.

The code will be in the ESP32.

if the arduino USB is plugged into a computer, the computer sees a USB serial interface, not a USB flash drive interface.

Hello gcjr,

If I selected in the tools tab in the arduino IDE, I can expose a USB serial interface to the computer and a mass storage device. As I said previously, the mass storage device shows the firmware partition. What I want is to expose part of the free flash as a mass storage device and not the partition with the firmware.

I am trying to explain what I want clearly.

my understanding is the USB interface chip are specific types of interfaces. there are different types of usb interfaces recognized by a PC and use different device drivers. the USB interface chip on an Arduino is recognized as a serial interface and won't be recognized as a flash storage device.

below i listed the devices on my laptop before inserting an Arduino and a flash drive

Sheldon ls /dev
clipboard  fd     mqueue  pty0    sda   sda3  shm     stdout  urandom
disk       full   null    pty1    sda1  sda4  stderr  tty     windows
dsp        mixer  ptmx    random  sda2  sda5  stdin   ttyS5   zero

after i inserted the Arduino and flash drive, it now lists sdb, sdb1 and ttyS3.

Sheldon ls /dev
clipboard  fd     mqueue  pty0    sda   sda3  sdb   stderr  tty    urandom
disk       full   null    pty1    sda1  sda4  sdb1  stdin   ttyS3  windows
dsp        mixer  ptmx    random  sda2  sda5  shm   stdout  ttyS5  zero

below is a long list also indicating the device driver type in the 5th column and the specific device # for that type in the 6th. As you can see, sdb is device type 8, like sda which is storage devices while ttyS3 is device type 117, a serial interface.

Sheldon ls -l /dev
total 0
crw-rw-rw- 1 lenovo None  13, 254 Nov 30  2006 clipboard
dr-xr-xr-x 1 lenovo None        0 Nov 19 14:29 disk
crw-rw-rw- 1 lenovo None  14,   3 Nov 19 14:29 dsp
lrwxrwxrwx 1 lenovo None        0 Nov 19 14:29 fd -> /proc/self/fd
crw-rw-rw- 1 lenovo None   1,   7 Nov 19 14:29 full
crw-rw-rw- 1 lenovo None  14,   0 Nov 19 14:29 mixer
drwxrwxrwt 1 lenovo None        0 Nov 19  2021 mqueue
crw-rw-rw- 1 lenovo None   1,   3 Nov 19 14:29 null
crw-rw-rw- 1 lenovo None   5,   2 Nov 19 14:29 ptmx
crw--w---- 1 lenovo None 136,   0 Nov 19 14:29 pty0
crw--w---- 1 lenovo None 136,   1 Nov 19 14:29 pty1
crw-rw-rw- 1 lenovo None   1,   8 Nov 19 14:29 random
brw-rw-rw- 1 lenovo None   8,   0 Nov 19 14:29 sda
brw-rw-rw- 1 lenovo None   8,   1 Nov 19 14:29 sda1
brw-rw-rw- 1 lenovo None   8,   2 Nov 19 14:29 sda2
brw-rw-rw- 1 lenovo None   8,   3 Nov 19 14:29 sda3
brw-rw-rw- 1 lenovo None   8,   4 Nov 19 14:29 sda4
brw-rw-rw- 1 lenovo None   8,   5 Nov 19 14:29 sda5
brw-rw-rw- 1 lenovo None   8,  16 Nov 19 14:29 sdb
brw-rw-rw- 1 lenovo None   8,  17 Nov 19 14:29 sdb1
drwxrwxrwt 1 lenovo None        0 Nov 19  2021 shm
lrwxrwxrwx 1 lenovo None        0 Nov 19 14:29 stderr -> /proc/self/fd/2
lrwxrwxrwx 1 lenovo None        0 Nov 19 14:29 stdin -> /proc/self/fd/0
lrwxrwxrwx 1 lenovo None        0 Nov 19 14:29 stdout -> /proc/self/fd/1
crw--w---- 1 lenovo None   5,   0 Nov 19 14:29 tty
crw-rw-rw- 1 lenovo None 117,   3 Nov 19 14:29 ttyS3
crw-rw-rw- 1 lenovo None 117,   5 Nov 19 14:29 ttyS5
crw-rw-rw- 1 lenovo None   1,   9 Nov 19 14:29 urandom
crw-rw-rw- 1 lenovo None  13, 255 Nov 19 14:29 windows
crw-rw-rw- 1 lenovo None   1,   5 Nov 19 14:29 zero

There is this USB relevant document from Espressif : USB Device Driver - ESP32-S3 - — ESP-IDF Programming Guide v5.2.1 documentation

It refers to this sample code for creating a mass storage device: esp-idf/examples/peripherals/usb/device/tusb_msc at v5.2.1 · espressif/esp-idf · GitHub

Thank you 6v6gt. I will take a look.