nRF5 SDK v14.1.0
USB Mass Storage Class module
This information applies to the nRF52840 SoC only.

This module covers basic implementation of the USB Mass Storage Class that has been defined in the following specification documents:

Usage

You can use this module to create many instances of the Mass Storage Class. Every instance of the class can handle up to 16 disks. Every disk has a unique LUN (Logical Unit Number) associated with it. Access to every LUN is provided by the block device API. The following figure shows basic flow of data between USB Mass Storage, the block device, and drivers:

usb_msc_flow.svg
Data flow between USB Mass Storage, block device, and drivers

The block device can be one of the two types:

USB Mass Storage Class provides a unified block device event handler. This event handler must be assigned to every block device. The following is an example of correct block device initialization for an empty block device:

static const nrf_block_dev_empty_config_t m_block_dev_empty_config = {
.block_size = 512,
.block_count = 1024 * 1024,
};
NRF_BLOCK_DEV_EMPTY_DEFINE(m_block_dev_empty,
&m_block_dev_empty_config,
app_usbd_msc_blockdev_ev_handler);

Host-to-device communication

To create an instance of the USB Mass Storage Class, use the APP_USBD_MSC_GLOBAL_DEF macro. The following example shows correct initialization of a Mass Storage Class instance that handles two block devices as separate logical units:

#define BLOCKDEV_LIST() ( \
&m_block_dev_ram, \
&m_block_dev_empty \
)
#define ENDPOINT_LIST() APP_USBD_MSC_ENDPOINT_LIST(1, 1)
APP_USBD_MSC_GLOBAL_DEF(m_app_msc, 0, msc_user_ev_handler, ENDPOINT_LIST(), BLOCKDEV_LIST(), 512);

The following example shows how to register an instance of the Mass Storage Class:

ret = app_usbd_init();
ASSERT(ret == NRF_SUCCESS);
app_usbd_class_inst_t const * class_inst_msc = app_usbd_msc_class_inst_get(&m_app_msc);
ret = app_usbd_controller_class_append(class_inst_msc);
ASSERT(ret == NRF_SUCCESS);

Host-to-device communication

The host uses Mass Storage Class Bulk Only Transport to communicate with the device. The figure shows how a single command is executed:

usb_msc_command.svg
Command execution between the host and the device

Documentation feedback | Developer Zone | Subscribe | Updated