|
| 1 | +.. zephyr:code-sample:: usb-mtp |
| 2 | + :name: USB MTP |
| 3 | + :relevant-api: usbd_api _usb_device_core_api file_system_api |
| 4 | + |
| 5 | + Expose the selected storage partition(s) as USB Media device using Media Transfer Protocol driver. |
| 6 | + |
| 7 | +Overview |
| 8 | +******** |
| 9 | + |
| 10 | +This sample app demonstrates the use of USB Media Transfer Protocol (MTP) |
| 11 | +driver provided by the Zephyr project. It allows the device to be mounted |
| 12 | +as a media device on the host system, enabling file transfers between the |
| 13 | +host and device. |
| 14 | +This sample can be found under :zephyr_file:`samples/subsys/usb/mtp` in the |
| 15 | +Zephyr project tree. |
| 16 | + |
| 17 | +Requirements |
| 18 | +************ |
| 19 | + |
| 20 | +- USB device driver support. |
| 21 | +- Storage media with Littlefs/FAT filesystem support. |
| 22 | +- Partitions must be mounted before connecting the board to Host. |
| 23 | + |
| 24 | +Building and Running |
| 25 | +******************** |
| 26 | + |
| 27 | +This sample can be built for multiple boards which can support at least one storage parition, |
| 28 | +in this example we will build it for the stm32f769i_disco board: |
| 29 | + |
| 30 | +.. zephyr-app-commands:: |
| 31 | + :zephyr-app: samples/subsys/usb/mtp |
| 32 | + :board: stm32f769i_disco |
| 33 | + :goals: flash |
| 34 | + :compact: |
| 35 | + |
| 36 | +Running |
| 37 | +======= |
| 38 | + |
| 39 | +Plug the board into a host device, for example, a PC running Linux. |
| 40 | +The board will be detected as shown by the Linux dmesg command: |
| 41 | + |
| 42 | +.. code-block:: console |
| 43 | +
|
| 44 | + usb 9-1: new full-speed USB device number 112 using uhci_hcd |
| 45 | + usb 9-1: New USB device found, idVendor=8086, idProduct=f8a1 |
| 46 | + usb 9-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3 |
| 47 | + usb 9-1: Product: Zephyr MTP |
| 48 | + usb 9-1: Manufacturer: ZEPHYR |
| 49 | + usb 9-1: SerialNumber: 0123456789AB |
| 50 | +
|
| 51 | +Once connected, the device should appear as a media device on your host system. |
| 52 | +You can then: |
| 53 | +- Browse the device storage |
| 54 | +- Transfer files to/from the device |
| 55 | +- Create/delete directories |
| 56 | + |
| 57 | +The storage contents will persist across device reboots as long as the |
| 58 | +filesystem is properly unmounted before disconnecting or resetting the device. |
| 59 | + |
| 60 | +.. note:: |
| 61 | + |
| 62 | + Not All MTP Features are implemented, for example you can't move/copy |
| 63 | + files from within the device, it must be done via Host. |
| 64 | + |
| 65 | +Troubleshooting |
| 66 | +=============== |
| 67 | + |
| 68 | +If the device is not recognized properly: |
| 69 | + |
| 70 | +1. Ensure the storage medium is properly initialized |
| 71 | +2. Check that the filesystem is mounted correctly |
| 72 | +3. Verify USB configuration is correct for your board |
| 73 | +4. Enable DEBUG logs on USB MTP driver to get more information |
| 74 | + |
| 75 | +For debugging purposes, you can enable USB debug logs by setting the following |
| 76 | +in your project's configuration: |
| 77 | + |
| 78 | +.. code-block:: none |
| 79 | +
|
| 80 | + CONFIG_USB_DEVICE_LOG_LEVEL_DBG=y |
| 81 | + CONFIG_USB_MTP_LOG_LEVEL_DBG=y |
0 commit comments