Skip to content

Commit 375e8e6

Browse files
jfischer-nocfriedt
authored andcommitted
samples: usb: move the legacy code out of the USB MSC sample
Move the legacy code from the USB MSC sample to a separate sample in the legacy directory. Make legacy sample very simple and drop all filesystem dependencies. Signed-off-by: Johann Fischer <[email protected]>
1 parent 1e50aaa commit 375e8e6

File tree

11 files changed

+153
-149
lines changed

11 files changed

+153
-149
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
cmake_minimum_required(VERSION 3.20.0)
4+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
5+
project(mass)
6+
7+
include(${ZEPHYR_BASE}/samples/subsys/usb/common/common.cmake)
8+
FILE(GLOB app_sources src/*.c)
9+
target_sources(app PRIVATE ${app_sources})
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
.. zephyr:code-sample:: legacy-usb-mass
2+
:name: Legacy USB Mass Storage
3+
:relevant-api: _usb_device_core_api
4+
5+
Expose board's RAM as a USB disk using USB Mass Storage driver.
6+
7+
Overview
8+
********
9+
10+
This sample app demonstrates use of a USB Mass Storage driver by the Zephyr
11+
project. This very simple driver enumerates a board with RAM disk into an USB
12+
disk. This sample can be found under
13+
:zephyr_file:`samples/subsys/usb/legacy/mass` in the Zephyr project tree.
14+
15+
.. note::
16+
This samples demonstrate deprecated :ref:`usb_device_stack`.
17+
18+
Requirements
19+
************
20+
21+
This project requires a USB device driver, and either 96KiB of RAM or a FLASH device.
22+
23+
Building and Running
24+
********************
25+
26+
The configurations selects RAM-based disk without any file system.
27+
28+
.. zephyr-app-commands::
29+
:zephyr-app: samples/subsys/usb/legacy/mass
30+
:board: reel_board
31+
:goals: build
32+
:compact:
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
* Copyright (c) 2023 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/ {
8+
ramdisk0 {
9+
compatible = "zephyr,ram-disk";
10+
disk-name = "RAM";
11+
sector-size = <512>;
12+
sector-count = <192>;
13+
};
14+
};
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
CONFIG_STDOUT_CONSOLE=y
2+
3+
#USB related configs
4+
CONFIG_USB_DEVICE_STACK=y
5+
CONFIG_USB_DEVICE_PRODUCT="Zephyr MSC sample"
6+
CONFIG_USB_DEVICE_PID=0x0008
7+
CONFIG_LOG=y
8+
CONFIG_USB_DRIVER_LOG_LEVEL_ERR=y
9+
CONFIG_USB_MASS_STORAGE=y
10+
CONFIG_USB_DEVICE_LOG_LEVEL_ERR=y
11+
CONFIG_USB_MASS_STORAGE_LOG_LEVEL_ERR=y
12+
CONFIG_USB_DEVICE_INITIALIZE_AT_BOOT=n
13+
14+
CONFIG_MAIN_STACK_SIZE=1536
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
sample:
2+
name: Mass Storage
3+
tests:
4+
sample.usb.legacy.mass_ram_none:
5+
min_ram: 128
6+
depends_on: usb_device
7+
build_only: true
8+
arch_exclude: posix
9+
tags:
10+
- usb
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright (c) 2016 Intel Corporation.
3+
* Copyright (c) 2019-2020 Nordic Semiconductor ASA
4+
*
5+
* SPDX-License-Identifier: Apache-2.0
6+
*/
7+
8+
#include <zephyr/kernel.h>
9+
#include <zephyr/usb/usb_device.h>
10+
11+
#include <zephyr/logging/log.h>
12+
LOG_MODULE_REGISTER(main, LOG_LEVEL_INF);
13+
14+
int main(void)
15+
{
16+
int ret;
17+
18+
ret = usb_enable(NULL);
19+
if (ret != 0) {
20+
LOG_ERR("Failed to enable USB");
21+
return 0;
22+
}
23+
24+
LOG_INF("The device is put in USB mass storage mode");
25+
26+
return 0;
27+
}

samples/subsys/usb/mass/README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.. zephyr:code-sample:: usb-mass
22
:name: USB Mass Storage
3-
:relevant-api: usbd_api usbd_msc_device _usb_device_core_api file_system_api
3+
:relevant-api: usbd_api usbd_msc_device file_system_api
44

55
Expose board's RAM or FLASH as a USB disk using USB Mass Storage driver.
66

samples/subsys/usb/mass/prj.conf

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1+
CONFIG_USB_DEVICE_STACK_NEXT=y
2+
13
CONFIG_STDOUT_CONSOLE=y
4+
CONFIG_SERIAL=y
5+
CONFIG_UART_LINE_CTRL=y
6+
CONFIG_USBD_MSC_CLASS=y
7+
CONFIG_USBD_MSC_LUNS_PER_INSTANCE=3
28

3-
#USB related configs
4-
CONFIG_USB_DEVICE_STACK=y
5-
CONFIG_USB_DEVICE_PRODUCT="Zephyr MSC sample"
6-
CONFIG_USB_DEVICE_PID=0x0008
79
CONFIG_LOG=y
8-
CONFIG_USB_DRIVER_LOG_LEVEL_ERR=y
9-
CONFIG_USB_MASS_STORAGE=y
10-
CONFIG_USB_DEVICE_LOG_LEVEL_ERR=y
11-
CONFIG_USB_MASS_STORAGE_LOG_LEVEL_ERR=y
12-
CONFIG_USB_DEVICE_INITIALIZE_AT_BOOT=n
10+
CONFIG_USBD_LOG_LEVEL_WRN=y
11+
CONFIG_UDC_DRIVER_LOG_LEVEL_WRN=y
1312

14-
CONFIG_MAIN_STACK_SIZE=1536
13+
CONFIG_SAMPLE_USBD_PID=0x0008
14+
CONFIG_SAMPLE_USBD_PRODUCT="USBD MSC sample"
15+
CONFIG_MAIN_STACK_SIZE=2048

samples/subsys/usb/mass/sample.yaml

Lines changed: 20 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,7 @@
11
sample:
22
name: Mass Storage
33
tests:
4-
sample.usb.mass_ram_none:
5-
min_ram: 128
6-
depends_on: usb_device
7-
arch_exclude: posix
8-
extra_args:
9-
- EXTRA_DTC_OVERLAY_FILE="ramdisk.overlay"
10-
extra_configs:
11-
- CONFIG_LOG_DEFAULT_LEVEL=3
12-
tags:
13-
- msd
14-
- usb
15-
harness: console
16-
harness_config:
17-
type: multi_line
18-
ordered: true
19-
regex:
20-
- "No file system selected"
21-
- "The device is put in USB mass storage mode."
22-
sample.usb_device_next.mass_ram_none:
4+
sample.usbd.mass_ram_none:
235
min_ram: 128
246
depends_on: usbd
257
integration_platforms:
@@ -32,65 +14,41 @@ tests:
3214
- mimxrt1060_evk/mimxrt1062/qspi
3315
- max32690evkit/max32690/m4
3416
extra_args:
35-
- CONF_FILE="usbd_next_prj.conf"
3617
- EXTRA_DTC_OVERLAY_FILE="ramdisk.overlay"
37-
extra_configs:
38-
- CONFIG_LOG_DEFAULT_LEVEL=3
3918
tags:
40-
- msd
4119
- usb
4220
harness: console
4321
harness_config:
4422
type: multi_line
4523
ordered: true
4624
regex:
4725
- "No file system selected"
48-
- "The device is put in USB mass storage mode."
49-
sample.usb.mass_ram_fat:
26+
- "The device is put in USB mass storage mode"
27+
sample.usbd.mass_ram_fat:
5028
min_ram: 128
51-
depends_on: usb_device
52-
arch_exclude: posix
29+
depends_on: usbd
30+
integration_platforms:
31+
- nrf52840dk/nrf52840
32+
- nrf54h20dk/nrf54h20/cpuapp
33+
- frdm_k64f
34+
- stm32f723e_disco
35+
- nucleo_f413zh
36+
- mimxrt685_evk/mimxrt685s/cm33
37+
- mimxrt1060_evk/mimxrt1062/qspi
5338
extra_args:
5439
- EXTRA_DTC_OVERLAY_FILE="ramdisk.overlay"
5540
extra_configs:
56-
- CONFIG_LOG_DEFAULT_LEVEL=3
5741
- CONFIG_APP_MSC_STORAGE_RAM=y
5842
tags:
59-
- msd
60-
- usb
61-
harness: console
62-
harness_config:
63-
type: multi_line
64-
ordered: true
65-
regex:
66-
- "End of files"
67-
- "The device is put in USB mass storage mode."
68-
sample.usb.mass_flash_fatfs:
69-
min_ram: 32
70-
modules:
71-
- fatfs
72-
depends_on: usb_device
73-
filter: dt_compat_enabled("nordic,qspi-nor")
74-
platform_allow:
75-
- nrf52840dk/nrf52840
76-
- nrf5340dk/nrf5340/cpuapp
77-
- adafruit_feather_nrf52840/nrf52840/sense
78-
integration_platforms:
79-
- nrf52840dk/nrf52840
80-
extra_configs:
81-
- CONFIG_LOG_DEFAULT_LEVEL=3
82-
- CONFIG_APP_MSC_STORAGE_FLASH_FATFS=y
83-
tags:
84-
- msd
8543
- usb
8644
harness: console
8745
harness_config:
8846
type: multi_line
8947
ordered: true
9048
regex:
9149
- "End of files"
92-
- "The device is put in USB mass storage mode."
93-
sample.usb_device_next.mass_flash_fatfs:
50+
- "The device is put in USB mass storage mode"
51+
sample.usbd.mass_flash_fatfs:
9452
min_ram: 32
9553
modules:
9654
- fatfs
@@ -102,43 +60,18 @@ tests:
10260
- adafruit_feather_nrf52840/nrf52840/sense
10361
integration_platforms:
10462
- nrf52840dk/nrf52840
105-
extra_args: CONF_FILE="usbd_next_prj.conf"
10663
extra_configs:
107-
- CONFIG_LOG_DEFAULT_LEVEL=3
10864
- CONFIG_APP_MSC_STORAGE_FLASH_FATFS=y
10965
tags:
110-
- msd
111-
- usb
112-
harness: console
113-
harness_config:
114-
type: multi_line
115-
ordered: true
116-
regex:
117-
- "End of files"
118-
- "The device is put in USB mass storage mode."
119-
sample.usb.mass_sdhc_fatfs:
120-
min_ram: 32
121-
filter: dt_compat_enabled("zephyr,sdmmc-disk")
122-
modules:
123-
- fatfs
124-
depends_on:
125-
- usb_device
126-
- sdhc
127-
extra_configs:
128-
- CONFIG_LOG_DEFAULT_LEVEL=3
129-
- CONFIG_APP_MSC_STORAGE_SDCARD=y
130-
tags:
131-
- msd
13266
- usb
13367
harness: console
13468
harness_config:
135-
fixture: fixture_sdcard
13669
type: multi_line
13770
ordered: true
13871
regex:
13972
- "End of files"
140-
- "The device is put in USB mass storage mode."
141-
sample.usb_device_next.mass_sdhc_fatfs:
73+
- "The device is put in USB mass storage mode"
74+
sample.usbd.mass_sdhc_fatfs:
14275
min_ram: 32
14376
filter: dt_compat_enabled("zephyr,sdmmc-disk")
14477
modules:
@@ -147,11 +80,8 @@ tests:
14780
- usbd
14881
- sdhc
14982
extra_configs:
150-
- CONFIG_LOG_DEFAULT_LEVEL=3
15183
- CONFIG_APP_MSC_STORAGE_SDCARD=y
152-
extra_args: CONF_FILE="usbd_next_prj.conf"
15384
tags:
154-
- msd
15585
- usb
15686
harness: console
15787
harness_config:
@@ -160,12 +90,12 @@ tests:
16090
ordered: true
16191
regex:
16292
- "End of files"
163-
- "The device is put in USB mass storage mode."
164-
sample.usb.mass_flash_littlefs:
93+
- "The device is put in USB mass storage mode"
94+
sample.usbd.mass_flash_littlefs:
16595
modules:
16696
- littlefs
16797
min_ram: 32
168-
depends_on: usb_device
98+
depends_on: usbd
16999
filter: dt_compat_enabled("nordic,qspi-nor")
170100
platform_allow:
171101
- nrf52840dk/nrf52840
@@ -174,15 +104,13 @@ tests:
174104
integration_platforms:
175105
- nrf52840dk/nrf52840
176106
extra_configs:
177-
- CONFIG_LOG_DEFAULT_LEVEL=3
178107
- CONFIG_APP_MSC_STORAGE_FLASH_LITTLEFS=y
179108
tags:
180-
- msd
181109
- usb
182110
harness: console
183111
harness_config:
184112
type: multi_line
185113
ordered: true
186114
regex:
187115
- "End of files"
188-
- "The device is put in USB mass storage mode."
116+
- "The device is put in USB mass storage mode"

0 commit comments

Comments
 (0)