nRF5 SDK v15.2.0
USB MSC Example
This information applies to the nRF52840 SoC only.

This example uses the USB Mass Storage Class module. See the documentation of this module for links to relevant specification documents.

This example shows how to configure and use the USB Mass Storage Class. A development kit connected to a host will enumerate as a single Mass Storage Class with multiple logical units:

Every logical unit is a block device instance that describes the physical memories. To choose which block devices should be visible as an MSC logical unit, you must modify BLOCKDEV_LIST.

To enable SD card support, set USE_SD_CARD to 1. You must also provide correct SPI pin definitions:

This example allows you to manipulate the file system (on QSPI memory) only while USB is not connected. If USB is connected, access to the file system from a user application is not possible because MSC is not designed to allow access to the file system from multiple sources. To disable FatFS capabilities, set USE_FATFS_QSPI to 0.

Setup

You can find the source code and the project file of the example in the following folder: <InstallFolder>\examples\peripheral\usbd_msc

LED assignments:

Button assignments:

Testing

Test the USB MSC Example application by performing the following steps:

  1. Compile and program the application.
  2. Connect the development kit to the host computer through the J-Link port.
  3. Start a terminal emulator like PuTTY and connect to the used COM port with the following UART settings:
    • Baud rate: 115.200
    • 8 data bits
    • 1 stop bit
    • No parity
    • HW flow control: None
  4. Observe the debug output.
  5. Press the buttons on the development kit and observe the results on the host computer terminal.
  6. Connect the development kit to the host computer through the USB device port.
  7. Device will enumerate as a Mass Storage Class with multiple disk instances.
  8. Try pressing Button 1 to create a file. Manipulating the file system from the development kit will not be possible while USB is connected.
  9. Disconnect the USB cable (from the USB device port) and the development kit buttons will be functional again.

Performance testing with the dd command

On Unix platforms, you can use the dd command to test the performance of the USB connection. You must execute the command as a root user.

Warning
Be careful when choosing the file block device (sdX). If you select the system disk for the write test, all data on the system partition will be erased irreversibly (MBR and file system metadata).
dd if=/dev/zero of=/dev/sdX bs=1M count=8 status=progress

Documentation feedback | Developer Zone | Subscribe | Updated