🛠 Using USB OTG as Mass Storage

HPMicro HPM5100: 400 MHz RISC-V MCU with Integrated Analog Peripherals · debutant · Apprenez à configurer le HPM5100 pour qu'il soit reconnu comme une clé USB par votre ordinateur.

Objectives

This tutorial guides you through transforming your HPM5100 board into a USB mass storage device. Although the chip integrates 1 MB of flash and 416 KB of SRAM, we will simulate a storage space accessible via the USB 2.0 OTG interface. This is an ideal introduction to understanding USB communication and the TinyUSB peripheral included in the HPMicro SDK. You will learn to initialize the USB controller and handle simple data exchanges.

Required Hardware

Steps

  1. Environment Preparation: Install the HPMicro SDK and configure your build tool (Make or CMake). Ensure the environment variable points to the SDK root directory.
  1. Access the Example: Navigate to the USB examples folder in the SDK. The mass storage example is usually located in examples/usb/device/msc. Open the main file main.c to understand the structure.
  1. Code Configuration: In the configuration file, enable the USB Device interface. The HPM5100 has an integrated USB PHY, so no external components are required for the physical layer. Define the size of the virtual 'disk'. For example, use a portion of SRAM or a static memory buffer to simulate storage.
  1. Compilation: Run the compilation with the following command:
make BOARD=hpm5100evk

If using CMake:

cmake -B build -DBOARD=hpm5100evk
make -C build
  1. Flashing: Connect the board to the computer via USB. Use the SDK flashing tool (often hpm_manufactory or via GDB) to load the binary onto the chip.
./tools/openocd/openocd -f board/hpm5100.cfg -c "program build/hpm5100evk.elf verify reset exit"
  1. Test: Unplug and replug the USB cable. Your computer should detect a new removable storage device.

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials