samples: usb: testusb: use new USB device stack
Rework sample to use new USB device stack. Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
This commit is contained in:
parent
5fb47cd97f
commit
5b385493b3
6 changed files with 47 additions and 24 deletions
|
@ -4,5 +4,6 @@ cmake_minimum_required(VERSION 3.20.0)
|
|||
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
|
||||
project(testusb)
|
||||
|
||||
include(${ZEPHYR_BASE}/samples/subsys/usb/common/common.cmake)
|
||||
FILE(GLOB app_sources src/*.c)
|
||||
target_sources(app PRIVATE ${app_sources})
|
||||
|
|
9
samples/subsys/usb/testusb/Kconfig
Normal file
9
samples/subsys/usb/testusb/Kconfig
Normal file
|
@ -0,0 +1,9 @@
|
|||
# Copyright (c) 2023 Nordic Semiconductor ASA
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
# Source common USB sample options used to initialize new experimental USB
|
||||
# device stack. The scope of these options is limited to USB samples in project
|
||||
# tree, you cannot use them in your own application.
|
||||
source "samples/subsys/usb/common/Kconfig.sample_usbd"
|
||||
|
||||
source "Kconfig.zephyr"
|
|
@ -1,6 +1,6 @@
|
|||
.. zephyr:code-sample:: testusb-app
|
||||
:name: USB testing application
|
||||
:relevant-api: _usb_device_core_api
|
||||
:name: USB device testing application
|
||||
:relevant-api: usbd_api
|
||||
|
||||
Test USB device drivers using a loopback function.
|
||||
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
CONFIG_STDOUT_CONSOLE=y
|
||||
CONFIG_USB_DEVICE_STACK_NEXT=y
|
||||
CONFIG_USBD_LOOPBACK_CLASS=y
|
||||
CONFIG_UDC_BUF_POOL_SIZE=4096
|
||||
|
||||
#USB related configs
|
||||
CONFIG_USB_DEVICE_STACK=y
|
||||
CONFIG_USB_DEVICE_PRODUCT="Zephyr testusb sample"
|
||||
CONFIG_USB_DEVICE_PID=0x0009
|
||||
CONFIG_LOG=y
|
||||
CONFIG_USB_DRIVER_LOG_LEVEL_ERR=y
|
||||
CONFIG_USB_DEVICE_LOOPBACK=y
|
||||
CONFIG_USB_DEVICE_LOG_LEVEL_ERR=y
|
||||
CONFIG_USB_DEVICE_INITIALIZE_AT_BOOT=n
|
||||
CONFIG_USBD_LOG_LEVEL_ERR=y
|
||||
CONFIG_UDC_DRIVER_LOG_LEVEL_ERR=y
|
||||
CONFIG_USBD_LOOPBACK_LOG_LEVEL_ERR=y
|
||||
|
||||
CONFIG_SAMPLE_USBD_PID=0x0009
|
||||
CONFIG_SAMPLE_USBD_PRODUCT="Zephyr testusb sample"
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
sample:
|
||||
name: USB loopback sample
|
||||
name: USB device loopback sample
|
||||
tests:
|
||||
sample.usb.loopback:
|
||||
depends_on: usb_device
|
||||
sample.usbd.loopback:
|
||||
depends_on: usbd
|
||||
build_only: true
|
||||
tags: usb
|
||||
harness: button
|
||||
|
|
|
@ -1,24 +1,37 @@
|
|||
/*
|
||||
* Copyright (c) 2018 Phytec Messtechnik GmbH
|
||||
* Copyright (c) 2025 Nordic Semiconductor ASA
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <zephyr/kernel.h>
|
||||
#include <sample_usbd.h>
|
||||
#include <zephyr/usb/usbd.h>
|
||||
|
||||
#include <zephyr/logging/log.h>
|
||||
#include <zephyr/usb/usb_device.h>
|
||||
LOG_MODULE_REGISTER(main);
|
||||
LOG_MODULE_REGISTER(main, LOG_LEVEL_INF);
|
||||
|
||||
int main(void)
|
||||
{
|
||||
struct usbd_context *sample_usbd;
|
||||
int ret;
|
||||
|
||||
ret = usb_enable(NULL);
|
||||
if (ret != 0) {
|
||||
LOG_ERR("Failed to enable USB");
|
||||
return 0;
|
||||
sample_usbd = sample_usbd_setup_device(NULL);
|
||||
if (sample_usbd == NULL) {
|
||||
LOG_ERR("Failed to setup USB device");
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
ret = usbd_init(sample_usbd);
|
||||
if (ret) {
|
||||
LOG_ERR("Failed to initialize device support");
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = usbd_enable(sample_usbd);
|
||||
if (ret) {
|
||||
LOG_ERR("Failed to enable device support");
|
||||
return ret;
|
||||
}
|
||||
|
||||
LOG_INF("entered main.");
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue