Skip to content

Commit 077cbc1

Browse files
nordic-baminordic-piks
authored andcommitted
tests: susbsys: Add USB device negotiated speed test
Assess the USB device negotiated speed (nrf54h and nrf54lm20) Device should attach with High Speed Signed-off-by: Bartosz Miller <[email protected]>
1 parent bc5b776 commit 077cbc1

File tree

8 files changed

+202
-0
lines changed

8 files changed

+202
-0
lines changed

CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -959,6 +959,7 @@
959959
/tests/zephyr/drivers/uart/ @nrfconnect/ncs-low-level-test
960960
/tests/zephyr/drivers/watchdog/ @nrfconnect/ncs-low-level-test
961961
/tests/zephyr/kernel/timer/timer_behavior/ @nrfconnect/ncs-low-level-test
962+
/tests/subsys/usb/negotiated_speed/ @nrfconnect/ncs-low-level-test
962963
/tests/zephyr/subsys/settings/performance/ @nrfconnect/ncs-pluto @rghaddab
963964

964965
/tests/benchmarks/multicore/idle/*.rst @nrfconnect/ncs-si-bluebagel-doc

scripts/ci/tags.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1505,6 +1505,7 @@ ci_samples_zephyr_subsys_usb:
15051505
files:
15061506
- nrf/samples/zephyr/subsys/usb/
15071507
- zephyr/samples/subsys/usb/
1508+
- nrf/tests/subsys/usb/
15081509

15091510
ci_tests_zephyr_drivers_uart:
15101511
files:
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
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 ${ZEPHYR_BASE}/samples/subsys/usb/mass/src/main.c)
9+
target_sources(app PRIVATE ${app_sources})
10+
11+
if(CONFIG_BUILD_WITH_TFM)
12+
target_include_directories(app PRIVATE
13+
$<TARGET_PROPERTY:tfm,TFM_BINARY_DIR>/api_ns/interface/include
14+
)
15+
endif()
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# Copyright (c) 2025 Nordic Semiconductor ASA
2+
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
3+
4+
menu "MSC sample options"
5+
6+
config APP_WIPE_STORAGE
7+
bool "Option to clear the flash area before mounting"
8+
help
9+
Use this to force an existing file system to be created.
10+
11+
choice
12+
prompt "Storage and file system type used by the application"
13+
default APP_MSC_STORAGE_NONE
14+
help
15+
Specify the type of storage and file system.
16+
17+
config APP_MSC_STORAGE_NONE
18+
bool "Use RAM disk as block device"
19+
20+
config APP_MSC_STORAGE_RAM
21+
bool "Use RAM disk and FAT file system"
22+
imply FILE_SYSTEM
23+
imply FAT_FILESYSTEM_ELM
24+
25+
config APP_MSC_STORAGE_FLASH_FATFS
26+
bool "Use FLASH disk and FAT file system"
27+
imply DISK_DRIVER_FLASH
28+
imply FILE_SYSTEM
29+
imply FAT_FILESYSTEM_ELM
30+
31+
config APP_MSC_STORAGE_FLASH_LITTLEFS
32+
bool "Use FLASH disk and LittleFS"
33+
imply DISK_DRIVER_FLASH
34+
imply FILE_SYSTEM
35+
imply FILE_SYSTEM_LITTLEFS
36+
37+
config APP_MSC_STORAGE_SDCARD
38+
bool "Use SDHC and FAT file system"
39+
imply DISK_DRIVER_SDMMC
40+
imply FILE_SYSTEM
41+
imply FAT_FILESYSTEM_ELM
42+
43+
endchoice
44+
45+
config MASS_STORAGE_DISK_NAME
46+
default "NAND" if DISK_DRIVER_FLASH
47+
default "RAM" if DISK_DRIVER_RAM
48+
default "SD" if DISK_DRIVER_SDMMC
49+
50+
if DISK_DRIVER_FLASH
51+
52+
config FLASH_MAP
53+
default y
54+
55+
config FLASH_PAGE_LAYOUT
56+
default y
57+
58+
config FLASH_LOG_LEVEL
59+
default 3
60+
61+
if NORDIC_QSPI_NOR
62+
63+
config NORDIC_QSPI_NOR_FLASH_LAYOUT_PAGE_SIZE
64+
default 4096
65+
66+
endif # NORDIC_QSPI_NOR
67+
68+
endif # DISK_DRIVER_FLASH
69+
70+
endmenu
71+
72+
source "samples/subsys/usb/common/Kconfig.sample_usbd"
73+
74+
source "Kconfig.zephyr"
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
* Copyright (c) 2025 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
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: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
CONFIG_USB_DEVICE_STACK_NEXT=y
2+
3+
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
8+
9+
CONFIG_LOG=y
10+
CONFIG_USBD_LOG_LEVEL_WRN=y
11+
CONFIG_UDC_DRIVER_LOG_LEVEL_WRN=y
12+
13+
CONFIG_SAMPLE_USBD_PID=0x0008
14+
CONFIG_SAMPLE_USBD_PRODUCT="USBD MSC sample"
15+
CONFIG_MAIN_STACK_SIZE=2048
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Copyright (c) 2025 Nordic Semiconductor ASA
2+
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
3+
4+
import logging
5+
import os
6+
import subprocess
7+
import sys
8+
from typing import Dict
9+
10+
USB_SAMPLE_ID: str = "NordicSemiconductor USBD MSC sample"
11+
packet_size_vs_speed: Dict[int, str] = {
12+
64: "Full Speed",
13+
512: "High Speed",
14+
1024: "Super Speed",
15+
}
16+
17+
logger = logging.getLogger("usb_negotiated_speed")
18+
logger.setLevel(logging.DEBUG)
19+
20+
21+
def excute_command(
22+
command: str,
23+
) -> str:
24+
"""
25+
Execute the command in subprocess.check_output()
26+
:return: command standard output
27+
"""
28+
logger.debug(command)
29+
return subprocess.check_output(
30+
command.split(" "),
31+
env=os.environ.copy(),
32+
).decode(sys.getdefaultencoding())
33+
34+
35+
def test_usb_negotaited_speed():
36+
"""
37+
Test the USB device negotiated speed
38+
The nrf54h20 and nrf54lm20 devices
39+
must attach as High Speed USB device
40+
"""
41+
usb_devices: str = excute_command("lsusb")
42+
logger.info(usb_devices)
43+
44+
failure_info: str = f"{USB_SAMPLE_ID} not found in the USB devices"
45+
46+
assert USB_SAMPLE_ID in usb_devices, failure_info
47+
48+
vendor_and_dev_id: str = (
49+
usb_devices.split(USB_SAMPLE_ID)[0].split("ID ")[-1].strip(" ")
50+
)
51+
usb_device_info: str = excute_command(f"lsusb -d {vendor_and_dev_id} -v")
52+
max_packet_size: int = int(
53+
usb_device_info.split("wMaxPacketSize")[-1]
54+
.split("bytes")[0]
55+
.split("1x ")[-1]
56+
.strip(" ")
57+
)
58+
negotiated_speed: str = packet_size_vs_speed[max_packet_size]
59+
60+
logger.info(f"Negotiated speed: {negotiated_speed}")
61+
62+
failure_info = "Negotiated USB device speed is not 'High Speed'"
63+
assert negotiated_speed == "High Speed", failure_info
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
common:
2+
tags:
3+
- usb
4+
- ci_samples_zephyr_subsys_usb
5+
harness: pytest
6+
7+
tests:
8+
usb.negotiated_speed:
9+
min_ram: 128
10+
depends_on: usbd
11+
integration_platforms:
12+
- nrf54h20dk/nrf54h20/cpuapp
13+
platform_allow:
14+
- nrf54h20dk/nrf54h20/cpuapp
15+
- nrf54lm20apdk/nrf54lm20a/cpuapp
16+
- [email protected]/nrf54lm20a/cpuapp
17+
extra_configs:
18+
- CONFIG_LOG_DEFAULT_LEVEL=3
19+
- CONFIG_APP_MSC_STORAGE_RAM=y

0 commit comments

Comments
 (0)