Skip to content

Commit 7ed9888

Browse files
committed
Polishing
- Add support for read-only flag - Cleanup LOGs - forward declaration of static functions - Sample: Updated README, kconfig and prj
1 parent 89cd694 commit 7ed9888

File tree

7 files changed

+117
-102
lines changed

7 files changed

+117
-102
lines changed

samples/subsys/usb/mtp/README.rst

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
:name: USB MTP
33
:relevant-api: usbd_api _usb_device_core_api file_system_api
44

5-
Use USB MTP driver which implement a Media Transfer Protocol device.
5+
Expose the selected storage partition(s) as USB Media device using Media Transfer Protocol driver.
66

77
Overview
88
********
@@ -17,13 +17,14 @@ Zephyr project tree.
1717
Requirements
1818
************
1919

20-
This project requires:
2120
- USB device driver support
2221
- Storage media with Littlefs/FAT filesystem support
2322

2423
Building and Running
2524
********************
2625

26+
This sample can be built for multiple boards which can support at least one storage parition.
27+
2728
Reel Board
2829
===========
2930

@@ -68,12 +69,12 @@ If the device is not recognized properly:
6869
1. Ensure the storage medium is properly initialized
6970
2. Check that the filesystem is mounted correctly
7071
3. Verify USB configuration is correct for your board
71-
4. Some systems may require additional MTP device support to be installed
72+
4. Enable DEBUG logs on USB MTP driver to get more information
7273

7374
For debugging purposes, you can enable USB debug logs by setting the following
7475
in your project's configuration:
7576

7677
.. code-block:: none
7778
7879
CONFIG_USB_DEVICE_LOG_LEVEL_DBG=y
79-
CONFIG_USB_MTP_LOG_LEVEL_DBG=y
80+
CONFIG_USB_MTP_LOG_LEVEL_DBG=y

samples/subsys/usb/mtp/prj.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,4 @@ CONFIG_OUTPUT_DISASSEMBLY_WITH_SOURCE=y
3838
CONFIG_FLASH_SHELL=y
3939
CONFIG_HWINFO_SHELL=y
4040
CONFIG_LOG_CMDS=y
41-
CONFIG_USBD_MTP_LOG_LEVEL_DBG=y
41+
CONFIG_USBD_MTP_LOG_LEVEL_DBG=y

samples/subsys/usb/mtp/src/main.c

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,25 @@
11
/*
22
* Copyright (c) 2019 Intel Corporation
3+
* Copyright (c) 2025 Mohamed ElShahawi (extremegtx@hotmail.com)
34
*
45
* SPDX-License-Identifier: Apache-2.0
56
*/
67

78
/**
89
* @file
9-
* @brief Sample echo app for MTP class
10+
* @brief Sample app app for MTP class
1011
*
11-
* Sample app for USB MTP class driver.
12+
* Sample app for USB MTP class driver. By default MTP class driver will expose
13+
* all storage parititions which has the flag `mtp-enabled`
1214
*/
1315

1416
#include <sample_usbd.h>
1517

16-
#include <stdio.h>
17-
#include <string.h>
18-
#include <zephyr/device.h>
1918
#include <zephyr/kernel.h>
20-
2119
#include <zephyr/usb/usb_device.h>
2220
#include <zephyr/usb/usbd.h>
2321
#include <zephyr/logging/log.h>
24-
LOG_MODULE_REGISTER(main, LOG_LEVEL_DBG);
22+
LOG_MODULE_REGISTER(usb_mtp_sample, LOG_LEVEL_INF);
2523

2624
static struct usbd_context *sample_usbd;
2725

@@ -67,12 +65,13 @@ static int enable_usb_device_next(void)
6765
return 0;
6866
}
6967

70-
7168
int main(void)
7269
{
7370
int ret;
74-
71+
#if defined(CONFIG_USB_DEVICE_STACK_NEXT)
7572
ret = enable_usb_device_next();
76-
73+
#else
74+
#error "Only Device next is supported"
75+
#endif
7776
return 0;
7877
}

subsys/usb/device_next/class/Kconfig.mtp

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ if USBD_MTP_CLASS
1212

1313
config USBD_MTP_ALLOW_WRITE
1414
bool "MTP Allow write"
15+
default y
1516
help
1617
Allow writing to the storage exposed over MTP.
1718
storage protection level has precedence over this config
@@ -23,16 +24,6 @@ config USBD_MTP_MAX_HANDLES
2324
Maximum number of objects to be handled by MTP, including
2425
stored, removed and added objects.
2526

26-
config USBD_MTP_ALLOW_MOVING_OBJECTS
27-
bool "MTP Allow move"
28-
help
29-
Enable moving objects within the exposed storage without relying on the host.
30-
31-
config USBD_MTP_ALLOW_COPYING_OBJECTS
32-
bool "MTP Allow copy"
33-
help
34-
Enable copying objects within the exposed storage without relying on the host.
35-
3627
module = USBD_MTP
3728
module-str = usbd mtp
3829
default-count = 1

subsys/usb/device_next/class/usbd_mtp.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,6 @@ static int usbd_mtp_request_handler(struct usbd_class_data *c_data, struct net_b
237237
LOG_INF(BOLDWHITE
238238
"\n=============[Host ACK handling END]=============\n" RESET);
239239
} else {
240-
LOG_ERR("SHOULDN'T BE HERE! buf->len: %u", buf->len);
241240
__ASSERT(0, "Invalid endpoint %x", bi->ep);
242241
}
243242

0 commit comments

Comments
 (0)