How to Implement an USB 2.0 / USB 3.0 Mass Storage Gadget

This document demonstrates how to implement an USB 2.0 / USB 3.0 mass storage gadget on SP7350 platforms.

 

Table of Contents

Kernel Setup

Enter the kernel configuration by running the following command in the top directory of project.

# make kconfig

 

  1. Select submenus for USB 2.0 controller : Device Drivers > USB support > USB Gadget Support > USB Peripheral Controller. Select <*> for “Sunplus USB 2.0 Device Controller“.

image-20240708-071332.png

 

  1. Select submenus for USB OTG Transceive driver : Device Drivers > USB support > USB Physical Layer drivers. Select <*> for “Sunplus USB OTG Transceive driver“.

image-20240708-071051.png
  1. Select submenus for USB 3.0 controller : Device Drivers > USB support. Select <*> for “DesignWare USB3 DRD Core Support“ and select “Dual Role mode“ for “Deware USB3 DRD Core Support“.

 

  1. Select submenus for USB Gadget configfs : Device Drivers > USB support > USB Gadget Support. Select <M> for “USB Gadget functions configurable through configfs“ and [*] for “Mass storage“.

 

  1. Execute the make command to build the Linux image.

Create a backing storage file

The backing storage file must be prepared before the gadget uses it.

  1. Use the following command to create 32MB files (backing_file_u2 and backing_file_u3) filled with zeros.

# dd bs=1M count=32 if=/dev/zero of=/backing_file_u2 32+0 records in 32+0 records out 33554432 bytes (34 MB, 32 MiB) copied, 0.0850515 s, 395 MB/s # dd bs=1M count=32 if=/dev/zero of=/backing_file_u3 32+0 records in 32+0 records out 33554432 bytes (34 MB, 32 MiB) copied, 0.0836486 s, 401 MB/s

 

  1. Use the following command to create the FAT file system in backing_file_u2 and backing_file_u3.

# mkfs.fat /backing_file_u2 mkfs.fat 4.1 (2017-01-24) # mkfs.fat /backing_file_u3 mkfs.fat 4.1 (2017-01-24)

 

ConfigFS

Configure mass storage gadget through configfs saved as a file named usb_mass_storage.

 

Implementation

After updating the image to the SP7350 platform, booting the system and copying backing_file_u2 and backing_file_u3 to it, use sh usb_mass_storage command to configure USB 2.0 and USB 3.0 as mass storage devices.

 

After connecting the mass storage gadget to a Windows PC through an USB cable, “E:\” and “F:\”will show up in “Portable Devices” of “Device Manager” and 2 “USB Mass Storage Device“ in “Universal Serial Bus controllers“.