🛠 Using the USB-A Host Port to Read a USB Drive

Adafruit Metro ESP32-P4 Hydra · intermediaire · Ce tutoriel explique comment activer et utiliser le port USB-A High-Speed 480 Mbps de la carte Adafruit Metro ESP32-P4 Hydra pour lire des fichiers depuis une clé USB standard.

Objectifs

This tutorial guides you through configuring the High-Speed USB-A Host port on the Adafruit Metro ESP32-P4 Hydra board. Unlike other boards that require an external hub, this port allows direct connection of standard USB peripherals such as storage drives. You will learn how to manage the software control of the port power and mount the filesystem to read data.

Matériel nécessaire

Étapes

  1. Environment Preparation: Ensure your development environment is configured to target the ESP32-P4 chip. Managing the USB Host port requires enabling specific components in the project configuration menu (menuconfig). Enable the USB Host Mass Storage Class option and ensure High-Speed mode is selected.
  1. Power Management: The board schematic indicates that the USB-A port power is logically controlled. Before physically connecting your drive, you must initialize the USB Host controller. In your code, call the USB Host driver initialization function. Note that the board has a software control circuit for USB-A port power; without this initialization step, the port remains off to save energy.
  1. Physical Connection: Insert your FAT32 USB drive into the female USB-A port on the board. Ensure the drive is properly inserted. The USB-C connector remains connected to your computer to allow debugging messages to be displayed on the serial monitor.
  1. Mounting the Filesystem: Once the driver is initialized, the system detects the mass storage device. Use a filesystem library (like LittleFS or FatFS integrated into ESP-IDF) to mount the drive's filesystem. You will need to allocate sufficient memory buffer, as the 16 MB of PSRAM is available for storing temporary data during reading.
  1. Reading Data: Browse the root directory of the USB drive. Open a simple text file present on the drive, read its content into a buffer, and display it on the serial console via the USB-C interface. Remember to cleanly unmount the filesystem before unplugging the drive to avoid data corruption.

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials