The protocol is provided as an extra class implementation for the "STM32_USB_Device_Library" stack from ST. The underlying file system is provided by FatFS.

MTP Events are not yet supported, but will be added shortly.

Execution context:

This class should not be used in the interrupt context which is how ST's implementation of the USB device library runs by default. That's because MTP requires lots of interaction with FatFS, which uses mutex locks. Since waiting inside an IRQ is typically not allowed, this makes the MTP processing rather unpredictable. This limitation is easily fixed by putting the entire interrupt handler in a (high priority) RTOS task and signalling the hardware IRQ via a semaphore. This principle applies equally well to non-OS implementations.


The MTP class has compatibility defines to work with the following versions of the FatFS filesystem:
_FATFS == 32020, _FATFS == 68300, FF_DEFINED == 89352.

We require FatFS to be configured with the following options:

  • FF_FS_MINIMIZE == 0 we need f_stat, f_getfree among others
  • FF_VOLUMES <= 8 because the class uses 3 bits for storage ID
  • FF_STR_VOLUME_ID == 1 gives decent storage labels in MTP


The MTP Class for STM32 takes about 10kB of ROM (code + data) and 1kB of static allocated RAM. In addition it uses 'FILINFO' and 'FF_MAX_LFN' working buffers according to the FF_LFN setting for the duration of the MTP session. And it can require up to TBD bytes of stack.


  • STM32_USB_Device_Library version V2.4.1, ...
  • FatFS version R0.11 or R0.13a
  • libc: memset, memcpy, sniprintf, swprintf (for unicode)

The class comes with it's own char/unicode handing functions to deal with the FatFS 'TCHAR' type which give a compile-time equivalents of strrchr/wcsrchr, strcat/wcscat and strcasecmp/wcscasecmp. Conveniently named tcsrchr, tcscat and tcscasecmp.

ARM Cortex M3