Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

usb: add new (experimental) USB device support #38679

Merged
merged 15 commits into from
Dec 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions MAINTAINERS.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2152,6 +2152,7 @@ USB:
- samples/subsys/usb/
- subsys/usb/
- tests/subsys/usb/
- tests/drivers/udc/
labels:
- "area: USB"

Expand Down
8 changes: 8 additions & 0 deletions doc/services/usb/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,11 @@ USB device support
uds_testing.rst
hid.rst
uds_cdc_acm.rst

New USB device support
######################

.. toctree::
:maxdepth: 1

uds_next.rst
35 changes: 35 additions & 0 deletions doc/services/usb/uds_next.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
.. _uds_next:

USB device core support
#######################

The new USB device support is experimental and under development. It consists
of low level USB device controller (UDC) driver API, USB device stack (core)
and different functions implementing specific classes. The device stack and
driver API bring multiple device support for the (rare) case that a board has
multiple USB device controllers. Device stack has support for multiple
configurations and a class instance can be added or removed at runtime to a
configuration. The stack provides a specific API for implementing the
functions (classes). This takes over the configuration of the class interfaces
and endpoints, and also the communication with the stack and driver API.
The stack can be enabled by the :kconfig:option:`CONFIG_USB_DEVICE_STACK_NEXT`.

The first time there will be only one sample for the new USB support,
:ref:`usb_shell-app`, with all available USB support shell commands.
The sample is mainly to help test the capabilities of the stack and correct
implementation of the USB controller drivers.

USB device stack core API reference
***********************************

.. doxygengroup:: usbd_api

UDC driver API reference
************************

The new USB device controller (UDC) driver API implements the low level layer
to interface with USB device controller.
UDC driver API is experimental and is subject to change without notice, it
is described in :zephyr_file:`include/drivers/usb/udc.h`.

.. doxygengroup:: udc_api
1 change: 1 addition & 0 deletions drivers/usb/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# SPDX-License-Identifier: Apache-2.0

add_subdirectory_ifdef(CONFIG_UDC_DRIVER udc)
add_subdirectory_ifdef(CONFIG_USB_DEVICE_DRIVER device)
1 change: 1 addition & 0 deletions drivers/usb/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
# Copyright (c) 2016 Wind River Systems, Inc.
# SPDX-License-Identifier: Apache-2.0

source "drivers/usb/udc/Kconfig"
source "drivers/usb/device/Kconfig"
8 changes: 8 additions & 0 deletions drivers/usb/udc/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Copyright (c) 2021 Nordic Semiconductor ASA
# SPDX-License-Identifier: Apache-2.0

zephyr_library()

zephyr_library_sources(udc_common.c)
zephyr_library_sources_ifdef(CONFIG_UDC_NRF udc_nrf.c)
zephyr_library_sources_ifdef(CONFIG_UDC_KINETIS udc_kinetis.c)
53 changes: 53 additions & 0 deletions drivers/usb/udc/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Copyright (c) 2021-2022 Nordic Semiconductor ASA
# SPDX-License-Identifier: Apache-2.0


menuconfig UDC_DRIVER
bool "USB device controller driver [EXPERIMENTAL]"
select EXPERIMENTAL
select NET_BUF
help
USB device controller driver.

if UDC_DRIVER

config UDC_BUF_COUNT
int "Number of buffers in the pool"
range 16 256
default 16
help
Number of UDC request buffers in the pool.

config UDC_BUF_POOL_SIZE
int "Memory available for requests"
range 64 32768
default 1024
help
Total amount of memory available for UDC requests.

config UDC_WORKQUEUE
bool "Use a dedicate work queue for UDC drivers"
help
This option provides a dedicated work queue for UDC drivers.

config UDC_WORKQUEUE_STACK_SIZE
int "UDC workqueue stack size"
depends on UDC_WORKQUEUE
default 512

config UDC_WORKQUEUE_PRIORITY
int "UDC workqueue priority"
depends on UDC_WORKQUEUE
default SYSTEM_WORKQUEUE_PRIORITY
help
By default, UDC work queue priority is the same as
System workqueue priority.

module = UDC_DRIVER
module-str = usb drv
source "subsys/logging/Kconfig.template.log_config"

source "drivers/usb/udc/Kconfig.nrf"
source "drivers/usb/udc/Kconfig.kinetis"

endif # UDC_DRIVER
18 changes: 18 additions & 0 deletions drivers/usb/udc/Kconfig.kinetis
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright (c) 2022 Nordic Semiconductor ASA
# SPDX-License-Identifier: Apache-2.0

config UDC_KINETIS
bool "Kinetis USB device controller driver"
imply UDC_WORKQUEUE
default y
depends on DT_HAS_NXP_KINETIS_USBD_ENABLED
help
Kinetis USB device controller criver.

config UDC_KINETIS_EVENT_COUNT
int "Number or blocks in event slab"
depends on UDC_KINETIS
range 4 16
default 4
help
Number of blocks in slab for internal endpoint events.
28 changes: 28 additions & 0 deletions drivers/usb/udc/Kconfig.nrf
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copyright (c) 2021 Nordic Semiconductor ASA
# SPDX-License-Identifier: Apache-2.0

config UDC_NRF
bool "Nordic Semiconductor USB device controller driver"
default y
depends on DT_HAS_NORDIC_NRF_USBD_ENABLED
select NRFX_USBD
select NRFX_POWER
help
nRF USB device controller driver.

if UDC_NRF

config UDC_NRF_THREAD_STACK_SIZE
int "nRF UDC driver internal thread stack size"
default 512
help
Size of the stack used in the driver for nRF USBD ISR event handling.

config UDC_NRF_MAX_QMESSAGES
int "nRF UDC driver maximum number of ISR event messages"
range 4 64
default 8
help
Maximum number of messages for handling of nRF USBD ISR events.

endif # UDC_NRF
Loading