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})
|
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
|
||||||
project(testusb)
|
project(testusb)
|
||||||
|
|
||||||
|
include(${ZEPHYR_BASE}/samples/subsys/usb/common/common.cmake)
|
||||||
FILE(GLOB app_sources src/*.c)
|
FILE(GLOB app_sources src/*.c)
|
||||||
target_sources(app PRIVATE ${app_sources})
|
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
|
.. zephyr:code-sample:: testusb-app
|
||||||
:name: USB testing application
|
:name: USB device testing application
|
||||||
:relevant-api: _usb_device_core_api
|
:relevant-api: usbd_api
|
||||||
|
|
||||||
Test USB device drivers using a loopback function.
|
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_LOG=y
|
||||||
CONFIG_USB_DRIVER_LOG_LEVEL_ERR=y
|
CONFIG_USBD_LOG_LEVEL_ERR=y
|
||||||
CONFIG_USB_DEVICE_LOOPBACK=y
|
CONFIG_UDC_DRIVER_LOG_LEVEL_ERR=y
|
||||||
CONFIG_USB_DEVICE_LOG_LEVEL_ERR=y
|
CONFIG_USBD_LOOPBACK_LOG_LEVEL_ERR=y
|
||||||
CONFIG_USB_DEVICE_INITIALIZE_AT_BOOT=n
|
|
||||||
|
CONFIG_SAMPLE_USBD_PID=0x0009
|
||||||
|
CONFIG_SAMPLE_USBD_PRODUCT="Zephyr testusb sample"
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
sample:
|
sample:
|
||||||
name: USB loopback sample
|
name: USB device loopback sample
|
||||||
tests:
|
tests:
|
||||||
sample.usb.loopback:
|
sample.usbd.loopback:
|
||||||
depends_on: usb_device
|
depends_on: usbd
|
||||||
|
build_only: true
|
||||||
tags: usb
|
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
|
* 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/logging/log.h>
|
||||||
#include <zephyr/usb/usb_device.h>
|
LOG_MODULE_REGISTER(main, LOG_LEVEL_INF);
|
||||||
LOG_MODULE_REGISTER(main);
|
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
|
struct usbd_context *sample_usbd;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
ret = usb_enable(NULL);
|
sample_usbd = sample_usbd_setup_device(NULL);
|
||||||
if (ret != 0) {
|
if (sample_usbd == NULL) {
|
||||||
LOG_ERR("Failed to enable USB");
|
LOG_ERR("Failed to setup USB device");
|
||||||
return 0;
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue