File tree Expand file tree Collapse file tree 6 files changed +47
-24
lines changed
samples/subsys/usb/testusb Expand file tree Collapse file tree 6 files changed +47
-24
lines changed Original file line number Diff line number Diff line change @@ -4,5 +4,6 @@ cmake_minimum_required(VERSION 3.20.0)
44find_package (Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE} )
55project (testusb)
66
7+ include (${ZEPHYR_BASE} /samples/subsys/usb/common/common.cmake)
78FILE (GLOB app_sources src/*.c)
89target_sources (app PRIVATE ${app_sources} )
Original file line number Diff line number Diff line change 1+ # Copyright (c) 2023 Nordic Semiconductor ASA
2+ # SPDX-License-Identifier: Apache-2.0
3+
4+ # Source common USB sample options used to initialize new experimental USB
5+ # device stack. The scope of these options is limited to USB samples in project
6+ # tree, you cannot use them in your own application.
7+ source "samples/subsys/usb/common/Kconfig.sample_usbd"
8+
9+ source "Kconfig.zephyr"
Original file line number Diff line number Diff line change 11.. zephyr :code-sample :: testusb-app
2- :name: USB testing application
3- :relevant-api: _usb_device_core_api
2+ :name: USB device testing application
3+ :relevant-api: usbd_api
44
55 Test USB device drivers using a loopback function.
66
Original file line number Diff line number Diff line change 1- CONFIG_STDOUT_CONSOLE=y
1+ CONFIG_USB_DEVICE_STACK_NEXT=y
2+ CONFIG_USBD_LOOPBACK_CLASS=y
3+ CONFIG_UDC_BUF_POOL_SIZE=4096
24
3- #USB related configs
4- CONFIG_USB_DEVICE_STACK=y
5- CONFIG_USB_DEVICE_PRODUCT="Zephyr testusb sample"
6- CONFIG_USB_DEVICE_PID=0x0009
75CONFIG_LOG=y
8- CONFIG_USB_DRIVER_LOG_LEVEL_ERR=y
9- CONFIG_USB_DEVICE_LOOPBACK=y
10- CONFIG_USB_DEVICE_LOG_LEVEL_ERR=y
11- CONFIG_USB_DEVICE_INITIALIZE_AT_BOOT=n
6+ CONFIG_USBD_LOG_LEVEL_ERR=y
7+ CONFIG_UDC_DRIVER_LOG_LEVEL_ERR=y
8+ CONFIG_USBD_LOOPBACK_LOG_LEVEL_ERR=y
9+
10+ CONFIG_SAMPLE_USBD_PID=0x0009
11+ CONFIG_SAMPLE_USBD_PRODUCT="Zephyr testusb sample"
Original file line number Diff line number Diff line change 11sample :
2- name : USB loopback sample
2+ name : USB device loopback sample
33tests :
4- sample.usb .loopback :
5- depends_on : usb_device
4+ sample.usbd .loopback :
5+ depends_on : usbd
66 tags : usb
7- harness : button
7+ harness : TBD
Original file line number Diff line number Diff line change 11/*
2- * Copyright (c) 2018 Phytec Messtechnik GmbH
2+ * Copyright (c) 2025 Nordic Semiconductor ASA
33 *
44 * SPDX-License-Identifier: Apache-2.0
55 */
66
7- #include <zephyr/kernel.h>
7+ #include <sample_usbd.h>
8+ #include <zephyr/usb/usbd.h>
9+
810#include <zephyr/logging/log.h>
9- #include <zephyr/usb/usb_device.h>
10- LOG_MODULE_REGISTER (main );
11+ LOG_MODULE_REGISTER (main , LOG_LEVEL_INF );
1112
1213int main (void )
1314{
15+ struct usbd_context * sample_usbd ;
1416 int ret ;
1517
16- ret = usb_enable (NULL );
17- if (ret != 0 ) {
18- LOG_ERR ("Failed to enable USB" );
19- return 0 ;
18+ sample_usbd = sample_usbd_setup_device (NULL );
19+ if (sample_usbd == NULL ) {
20+ LOG_ERR ("Failed to setup USB device" );
21+ return - ENODEV ;
22+ }
23+
24+ ret = usbd_init (sample_usbd );
25+ if (ret ) {
26+ LOG_ERR ("Failed to initialize device support" );
27+ return ret ;
28+ }
29+
30+ ret = usbd_enable (sample_usbd );
31+ if (ret ) {
32+ LOG_ERR ("Failed to enable device support" );
33+ return ret ;
2034 }
2135
22- LOG_INF ("entered main." );
2336 return 0 ;
2437}
You can’t perform that action at this time.
0 commit comments