Files
tinyusb/examples/device/mtp
hathach 4b1c8d16f7 docs: add build-doc tooling and a README for every example
Documentation tooling:
- Add the `build-doc` skill and `tools/build_doc.py` wrapper for local
  Sphinx builds (clean / -W / open).
- Enable Markdown (MyST) in conf.py and auto-collect
  examples/{device,host,dual}/*/README.md into a 3-level Examples nav
  (Examples > Device/Host/Dual > example), noting each page's source
  location and normalizing headings to a single H1.
- Remove the stale `.claude/commands/build-doc.md`; point the AGENTS.md
  Documentation section at the skill.

Example docs:
- Add a README.md for every device/host/dual example: what it does, USB
  interface table, notable tusb_config.h settings, generic CMake + Make
  build steps, and how to try it.
- Fold each *_freertos variant into its base README, noting the FreeRTOS
  source path and any RTOS-specific behavior.

Generated docs/examples/ output is git-ignored. Builds clean with
`sphinx-build -W`.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-29 10:16:25 +07:00
..
2026-05-13 22:27:57 +02:00
2025-08-06 06:14:13 +02:00
2025-10-14 17:53:55 +07:00
2025-08-06 06:14:13 +02:00
2025-09-26 12:50:30 +07:00

MTP

A USB Media Transfer Protocol device backed by a small in-RAM filesystem that the host can browse, read from and write to.

What it does

  • Presents a single MTP storage preloaded with two read-only objects: readme.txt and tinyusb.png.
  • Supports core MTP operations: get device info, open/close session, get storage IDs and storage info, enumerate object handles, get object info, get object and get partial object, and a device property (device friendly name).
  • Lets the host upload one additional object (SendObjectInfo / SendObject) into a 4 KB RAM buffer and delete objects (unless built read-only).
  • Handles MTP class control requests: cancel, device reset and get device status.
  • LED blink rate indicates bus state (not mounted / mounted / suspended).

USB Descriptors

Interface Class driver
0 MTP

Configuration

Notable tusb_config.h settings:

#define CFG_TUD_MTP                     1
#define CFG_TUD_MTP_EP_BUFSIZE          512
#define CFG_TUD_MTP_EP_CONTROL_BUFSIZE  16 // should be enough to hold data in MTP control request

// MTP device info
#define CFG_TUD_MTP_DEVICEINFO_EXTENSIONS   "microsoft.com: 1.0; "
#define CFG_TUD_MTP_DEVICEINFO_SUPPORTED_OPERATIONS \
   MTP_OP_GET_DEVICE_INFO, \
   MTP_OP_OPEN_SESSION, \
   MTP_OP_CLOSE_SESSION, \
   MTP_OP_GET_STORAGE_IDS, \
   MTP_OP_GET_STORAGE_INFO, \
   MTP_OP_GET_OBJECT_HANDLES, \
   MTP_OP_GET_OBJECT_INFO, \
   MTP_OP_GET_OBJECT, \
   MTP_OP_GET_PARTIAL_OBJECT, \
   MTP_OP_DELETE_OBJECT, \
   MTP_OP_SEND_OBJECT_INFO, \
   MTP_OP_SEND_OBJECT, \
   MTP_OP_RESET_DEVICE, \
   MTP_OP_GET_DEVICE_PROP_DESC, \
   MTP_OP_GET_DEVICE_PROP_VALUE, \
   MTP_OP_SET_DEVICE_PROP_VALUE

#define CFG_TUD_MTP_DEVICEINFO_SUPPORTED_EVENTS \
    MTP_EVENT_OBJECT_ADDED

#define CFG_TUD_MTP_DEVICEINFO_SUPPORTED_DEVICE_PROPERTIES  \
    MTP_DEV_PROP_DEVICE_FRIENDLY_NAME

#define CFG_TUD_MTP_DEVICEINFO_CAPTURE_FORMATS \
    MTP_OBJ_FORMAT_UNDEFINED, \
    MTP_OBJ_FORMAT_ASSOCIATION, \
    MTP_OBJ_FORMAT_TEXT, \
    MTP_OBJ_FORMAT_PNG

#define CFG_TUD_MTP_DEVICEINFO_PLAYBACK_FORMATS \
    MTP_OBJ_FORMAT_UNDEFINED, \
    MTP_OBJ_FORMAT_ASSOCIATION, \
    MTP_OBJ_FORMAT_TEXT, \
    MTP_OBJ_FORMAT_PNG

Building

CMake:

mkdir build && cd build
cmake -DBOARD=raspberry_pi_pico ..
cmake --build .

Make:

make BOARD=raspberry_pi_pico all

Try it

The device enumerates as an MTP device and shows up in a file browser (e.g. the Files/Explorer app, or mtp-detect / mtp-files from libmtp). You should see readme.txt and tinyusb.png; you can copy a small file onto the device and delete files.