Esp32-s3 as usb host to read connected pendrive files

Hi,

I am struggling to setup esp32-s3-n16r8 to read my pendrive content in arduino/esp-idf or supporting libs

Any help will be appreciated.

ESP-IDF has the USB host library with mass-storage-class (MSC) support to read a USB pendrive. (component registry).

You should be able to use that library and the example code without problems. Just make sure to match the version of ESP-IDF that PlatformIO uses with the version of the ESP-IDF example.

For example, with the latest espressif32 (6.12.0) platform, ESP-IDF v5.5 is uesd, so you would use

as your base example. You might find https://github.com/maxgerhardt/esp32s3-usbtmc-example/tree/main as a reference PlatformIO + ESP-IDF example interesting, too.

The post ESP32 S3 as USB host with TinyUSB? also explains the various different solder jumper settings for the board.

Thanks @maxgerhardt .

Is there a way to do this using arduino framework?

The only way I’ve seen people do this with the Arduino framework is to simple copy the source files of the ESP-IDF usb_host_msc library (as linked above) into their sketch folder, so their sketch can use it. See for example

https://github.com/nathalislight/esp32s3_USB_Drive

and compare against https://github.com/espressif/esp-usb/tree/master/host/class/msc/usb_host_msc/src.

Thanks @maxgerhardt . I tried the second way where i included all the necessary files in sketch itself in Platformio and tried to build , but build is failing.

Platformio.ini code

; PlatformIO Project Configuration File
[env:esp32-s3-usb]

platform = espressif32

board = esp32-s3-devkitc-1

framework = arduino

monitor_speed = 115200

Main.c file inside src

Compiler error

Archiving .pio\build\esp32-s3-usb\libFrameworkArduino.a
Linking .pio\build\esp32-s3-usb\firmware.elf
C:/Users-----/.platformio/packages/toolchain-xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/14.2.0/../../../../xtensa-esp-elf/bin/ld.exe: .pio/build/esp32-s3-usb/libFrameworkArduino.a(main.cpp.o): in function `app_main':
C:/Users/------/.platformio/packages/framework-arduinoespressif32@src-6738aaddd9fb901216d5f60e093380b6/cores/esp32/main.cpp:81: multiple definition of `app_main'; .pio/build/esp32-s3-usb/src/main.c.o:C:\Users\****\OneDrive\Documents\PlatformIO\Projects\S3-USB-READ/src/main.c:493: first defined here
collect2.exe: error: ld returned 1 exit status
*** [.pio\build\esp32-s3-usb\firmware.elf] Error 1
============================= [FAILED] Took 31.81 seconds =============================

Any help will be appreciated in fixing the issue.

You’re wildly mixing ESP-IDF examples with framework = arduino. In a framework = espidf firmware, you have to define app_main() as the main entry function of the firmware. So ESP-IDF examples provide that function. In framework = arduino, the Arduino core already implements the app_main() entry point, and sketches have to define the setup() and loop() function.

From the error message and platformio.ini you’ve shown, you have in all likelyhood copy-pasted an ESP-IDF example, which provides app_main(), into a framework = arduino project. This conflicts directly with the Arduino core. You need to change the framework to native ESP-IDF or rewrite the ESP-IDF example to do most of its work in setup(), where usually some FreeRTOS tasks are created to do the actual work, and loop().

Seems like there’s not a simple way to implement this. As i come from Arduino ide background hence all this confusion.