Very often, electronics projects require some means of accessing internal files with a PC. When such projects are somewhat comprehensive, such files are usually stored on a small SPI-based flash with FAT12 or FAT16 filesystem or on a removable SD card with FAT32 or exFAT filesystems. And since many projects also employ USB connectivity, or can have it added at marginal cost, it makes sense to provide a means for such file access via that USB connection.

Mass Storage Class:

A commonly used solution for file access via USB is the mass storage protocol. This exposes the devices flashdisk as a sector-based disk drive, exactly the same as a normal USB flashdrive. However, this has a serious side-effect. Namely that FAT has no provisions for dual access. So the MSC access via USB can only be used safely when the device has unmounted the storage medium, otherwise you risk corruption of the filesystem. Also, the host PC could be used to format the drive with an incompatible filesystem, rendering the device unusable.

Media Transfer Protocol:

The MTP class provides an object oriented access mechanism to the files on the device. With this mechanism, the PC does not interact with the sectors of a flash drive. Instead it only interacts with lists of objects, for example storage device, each having a list of files with various properties. The actual interaction with the file on the flash disk is handled by the device itself, thus eliminating the dual-access problem of the MSC approach. This protocol is well-known from Android and other portable devices. Also most digital cameras and video devices use this for their USB connectivity.


Our implementation was first developed for the TweakLite light therapy device. For this project, MTP was abandoned because of limited MTP support on Mac OSX. Later we used this implementation with the Offgrid System, the Infrared LED strobe and with the CAN-bus system & it's derivates.

The protocol is provided as an extra class implementation for the "STM32_USB_Device_Library" stack from ST. Typically, we use this in a FreeRTOS environment, although that is not strictly necessary. The underlying file system is provided by FatFS and a custom flash translation layer (FTL) to map the 512-byte based FAT to the 4kB sectors of the SPI flash device. Of course the standard drivers from ST/CubeMX to use SD card or USB flashdrives can be used also.

Evaluation of our MTP implementation is possible by downloading the demo binary onto a 32L476GDISCOVERY board. This demo formats the 16MB QSPI flash device with an FAT16 filesystem and generates some files on it. Upon plugging the board into a PC, those files are accessible from the PC.

ARM Cortex M3


Item: Description: Status: Price: Action:Preloader
83-110-100Media Transfer Protocol source license for single product typeIn stock€ 1750 ex VAT
83-110-101Media Transfer Protocol license for additional productIn stock€ 750 ex VAT
83-110-102Media Transfer Protocol license for unlimited productsIn stock€ 3000 ex VAT