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)
4
4
find_package (Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE} )
5
5
project (testusb )
6
6
7
+ include (${ZEPHYR_BASE} /samples/subsys/usb/common/common.cmake )
7
8
FILE (GLOB app_sources src/*.c )
8
9
target_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 1
1
.. 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
4
4
5
5
Test USB device drivers using a loopback function.
6
6
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
2
4
3
- #USB related configs
4
- CONFIG_USB_DEVICE_STACK=y
5
- CONFIG_USB_DEVICE_PRODUCT="Zephyr testusb sample"
6
- CONFIG_USB_DEVICE_PID=0x0009
7
5
CONFIG_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 1
1
sample :
2
- name : USB loopback sample
2
+ name : USB device loopback sample
3
3
tests :
4
- sample.usb .loopback :
5
- depends_on : usb_device
4
+ sample.usbd .loopback :
5
+ depends_on : usbd
6
6
tags : usb
7
- harness : button
7
+ harness : TBD
Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright (c) 2018 Phytec Messtechnik GmbH
2
+ * Copyright (c) 2025 Nordic Semiconductor ASA
3
3
*
4
4
* SPDX-License-Identifier: Apache-2.0
5
5
*/
6
6
7
- #include <zephyr/kernel.h>
7
+ #include <sample_usbd.h>
8
+ #include <zephyr/usb/usbd.h>
9
+
8
10
#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 );
11
12
12
13
int main (void )
13
14
{
15
+ struct usbd_context * sample_usbd ;
14
16
int ret ;
15
17
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 ;
20
34
}
21
35
22
- LOG_INF ("entered main." );
23
36
return 0 ;
24
37
}
You can’t perform that action at this time.
0 commit comments