Commit Graph

594 Commits

Author SHA1 Message Date
Daniel DeGrasse e36c31a001 usb: dfu: Enable progressive erase for MCUX FlexSPI flash
Devices using the MCUX FlexSPI flash driver erase their flash too
slowly, causing the usb stack to freeze, and USB DFU utilities to
report a timeout. Enable IMG_ERASE_PROGRESSIVELY for SOCs using the
MCUX FlexSPI driver to prevent this error.

Fixes #45359

Signed-off-by: Daniel DeGrasse <daniel.degrasse@nxp.com>
2022-05-09 08:54:30 -05:00
Gerard Marull-Paretas 5113c1418d subsystems: migrate includes to <zephyr/...>
In order to bring consistency in-tree, migrate all subsystems code to
the new prefix <zephyr/...>. Note that the conversion has been scripted,
refer to zephyrproject-rtos#45388 for more details.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-05-09 12:07:35 +02:00
Yuval Peress 53ef68d459 include: Prefix includes to use a scope
Move include paths and add new target_include_directories to support
backwards compatibility:
* /include -> /include/zephyr
  example: <irq.h> -> <zephyr/irq.h>

Issue #41543

Signed-off-by: Yuval Peress <peress@google.com>
2022-04-08 19:03:32 +02:00
Johann Fischer 6be45c2a18 usb: move USB device stack code to own directory
Until now the whole USB device stack code is located
in the top subsys/usb directory. Move it to own directory
in preparation for upcoming extension and rework of USB support.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2022-03-31 18:30:14 +02:00
Martijn Stommels 49cb6537be usb: dfu: add permanent download and automatic reboot
This commit adds the USB_DFU_PERMANENT_DOWNLOAD and USB_DFU_REBOOT and
symbols.When the permanent download symbol is enabled, slot 1 will be
marked as confirmed. With the reboot symbol enabled, the devices
automatically reboots after the download is completed.

The functionality is split into two symbols to allow the automatic
reboot without confirming the image. This enables image confirmation via
another channel. For example via the shell’s Mcuboot commands.

This functionality allows downloading an image to the device without the
user having to interact with the device. It is useful in cases where
ease of use is more important then safety. For example  when using USB
download for daily development. This is especially applicable for
devices with a closed case.

The changes were tested on an nrf52840dk. The following line can be used
to build the USB DFU example with the symbols enabled.

west build -b nrf52840dk_nrf52840 zephyr/samples/subsys/usb/dfu \
-d build-dfu -- -DCONFIG_BOOTLOADER_MCUBOOT=y \
-DOVERLAY_CONFIG=overlay-reboot-permanent.conf \
-DCONFIG_MCUBOOT_SIGNATURE_KEY_FILE\
=\"bootloader/mcuboot/root-rsa-2048.pem\"

Fixes #41921

Signed-off-by: Martijn Stommels <martijn@martijnpc.nl>
2022-03-31 15:33:16 +02:00
Nazar Kazakov f483b1bc4c everywhere: fix typos
Fix a lot of typos

Signed-off-by: Nazar Kazakov <nazar.kazakov.work@gmail.com>
2022-03-18 13:24:08 -04:00
Gerard Marull-Paretas 95fb0ded6b kconfig: remove Enable from boolean prompts
According to Kconfig guidelines, boolean prompts must not start with
"Enable...". The following command has been used to automate the changes
in this patch:

sed -i "s/bool \"[Ee]nables\? \(\w\)/bool \"\U\1/g" **/Kconfig*

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-03-09 15:35:54 +01:00
Krzysztof Chruscinski 47ae656cc1 all: Deprecate UTIL_LISTIFY and replace with LISTIFY
UTIL_LISTIFY is deprecated. Replacing it with LISTIFY.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2022-03-08 11:03:30 +01:00
Johann Fischer 3b7807cc9b usb: dfu: disable USB DFU uploading by default
Firmware uploading to the host may not always be desired,
disable it by default.

Enable it for existing USB DFU sample to keep
the usual behavior, add note about new option to README.rst.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2022-02-18 09:32:22 -08:00
Johann Fischer 09f48c9a4f usb: dfu: rename FLASH_AREA_ID macro
Rename confusing UPLOAD_FLASH_AREA_ID to DOWNLOAD_FLASH_AREA_ID
as it is area where firmware image is downloaded.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2022-02-18 09:32:22 -08:00
Johann Fischer c51cfee4bf usb: do not add ZLP if lenght to be transmitted is just zero
It is possible that the actual data stage length of
the control transfer is zero, in that case we do not
need an additional ZLP packet.

This fixes a problem with USB DFU, where after an upload
the device is no longer responsive if upload size is
multiple of control endpoint MPS.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2022-02-18 09:32:22 -08:00
Johann Fischer 1e3f7ca433 usb: add option to initialize USB device support at boot
Possibility to initialize USB device support is useful when
only CDC ACM class is enabled and CDC ACM UART is used as
backend for console, shell, or logging.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2022-02-07 13:06:35 +01:00
Jacob Caughfield 2abc8cf3b2 usb: Handle USB_DC_RESET event notifications
This patch fixes an issue where mcux usb devices may stop
functioning after a reset event, because they do not
provide a USB_DC_DISCONNECTED event and USB_DC_RESET
events were not handled by the forward status callback.

Signed-off-by: Jacob Caughfield <mlsvrts@protonmail.com>
2022-02-04 22:58:06 +01:00
Alexander Mihajlovic bd4ddec0c8 usb: Add macro for user defined string descriptors
The new macro USBD_STRING_DESCR_USER_DEFINE works like
USBD_STRING_DESCR_DEFINE with the exception of being
ordered strictly after it. The new macro is needed to
ensures that user defined string descriptors can be added
without disturbing the order of string descriptors
defined by the usb subsystem.

Signed-off-by: Alexander Mihajlovic <a@abxy.se>
2022-02-03 14:57:42 +01:00
Johann Fischer 388001456c usb: bluetooth: check buffer tailroom before copying
If HCI packet length is greater than endpoint MPS or currently
received data block (over USB), next block could be larger
than allocated net_buf buffer.

Check buffer tailroom before copying data using net_buf_add_mem().

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2022-01-26 11:54:31 +01:00
Johann Fischer 0be729de8a bluetooth: hci_raw: avoid possible memory overflow in bt_buf_get_tx()
Function bt_buf_get_tx(), which is used to allocate buffer from
fixed-size pool, does not check size argument before copying
the data with the length size into fixed-size buffer, wich may
not be large enough.

Check immediately before copying if the tailroom of the buffer
is large enough.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2022-01-26 11:54:31 +01:00
Gerard Marull-Paretas 22a7a5badf usb: class: drop DEV_DATA/DEV_CFG usage
Stop using redundant DEV_DATA/DEV_CFG macros and use dev->data and
dev->config instead.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-01-19 18:16:02 +01:00
Daniel Leung c955a44f13 usb: remove @return doc for void functions
For functions returning nothing, there is no need to document
with @return, as Doxgen complains about "documented empty
return type of ...".

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2022-01-12 16:02:16 -05:00
Johann Fischer 9bf4fcb673 usb: bluetooth: do not start transfers when USB bus is suspended
Rework suspended to be a shared atomic variable between
bluetooth_status_cb() and hci_tx_thread().
If the bus is suspended, initiate remote-wakeup and
wait until the bus is operational.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-12-14 09:08:58 -05:00
Johann Fischer 5296339fde usb: rework to use macro STRUCT_SECTION_FOREACH
Replace deprecated macro USBD_CFG_DATA_DEFINE by
USBD_DEFINE_CFG_DATA which places usb_cfg_data structures
in specific iterable section.

Replace __usb_data_start, __usb_data_end usage patterns
  size_t size = (__usb_data_end - __usb_data_start);
  for (size_t i = 0; i < size; i++) {...}
by
  STRUCT_SECTION_FOREACH(usb_cfg_data, ...) {...}

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-12-10 07:22:15 -06:00
Jordan Yates df327eeb58 net: buf: `POOL_FIXED_DEFINE` explicit user data
Update the macro prototype to explicitly require the length of the
desired user data. Update all in-tree usage of this macro.

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
2021-11-24 16:04:50 +02:00
Johann Fischer cf8d7764da usb: fix bulk endpoint configuration for high-speed capable device
In the current USB device support, the sizes of bulk endpoint
are mostly configure through Kconfig and do not care if a device
is high-speed capable. The information if a USB device controller
supports high-speed comes from devicetree. Add a Kconfig option to
map this information and configure bulk endpoint sizes
accordingly.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-11-24 12:28:02 +01:00
Johann Fischer 4151f42710 usb: cdc_acm: use same init level and priority as serial drivers
Use same init level and priority as serial drivers.
Align priority to the changes in
commit ad1450510a ("drivers: serial: Refactor drivers
to use shared init priority Kconfig")

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-11-18 14:29:18 +01:00
Christopher Friedt 3e86c627f7 kernel: atomics: update print specifiers for atomic_t
The print specifier for `atomic_t` should be updated
to `%ld`, `%lu`, or `%lx` to account for the type
change of `atomic_t` to `long`.

Signed-off-by: Christopher Friedt <chrisfriedt@gmail.com>
2021-11-15 09:59:01 -05:00
Emil Gydesen 12decc70d0 Bluetooth: ISO: Add bitmask for retrieving iso header lenght
Add a macro to retrieve the iso data load length (the
length stored in the iso header) with a bit mask that
ensures that we only take the first 14 bits.

This is to remove any RFU bits that may have been set.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-11-12 14:52:33 +01:00
Emil Gydesen 08b1dfb4a2 Bluetooth: ISO: Fix incorrect struct for ISO hdr data
There were a few cases where bt_hci_iso_data_hdr was used
instead of the proper struct bt_hci_iso_hdr.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2021-11-12 14:52:33 +01:00
Emil Obalski 75c0f52cca usb: Add API for getting status of remote wakeup
This change adds a posibility to check the status of
remote wakeup feature.

Signed-off-by: Emil Obalski <emil.obalski@nordicsemi.no>
2021-11-09 13:50:03 +01:00
Johann Fischer 02c32d4474 usb: move USB_DEVICE_REMOTE_WAKEUP option to drivers
Kconfig USB_DEVICE_REMOTE_WAKEUP option depends only on
USB device controller capability, but is not controlled
by the USB device controller drivers configuration.
Move USB_DEVICE_REMOTE_WAKEUP option to drivers and
make it promptless.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-11-08 17:01:32 +01:00
Johann Fischer 14c28c45f1 usb: remove USB_SCD_ATTRIBUTES macro
USB_SCD_ATTRIBUTES is a configuration dependent macro
that does not map any part of the spec and does not
belong to usb_ch9 header.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-11-08 17:01:32 +01:00
Johann Fischer b92ce9a6c1 usb: function_rndis: do not force USB_COMPOSITE_DEVICE for IAD
Just always prove interface association descriptor for RNDIS
function instead of forcing it via Kconfig USB_COMPOSITE_DEVICE
option.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-10-27 11:56:00 +02:00
Johann Fischer 70c25119d1 usb: function_rndis: align rndis_cmd_pool to request buffer size
Set reasonable range for the request buffer in case RNDIS
function is used. Align net_buf size from rndis_cmd_pool to
request buffer size since request is copied there before
it is queued.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-10-27 11:56:00 +02:00
Kumar Gala a3480cf87c usb: Fix building error in usb_descriptor with misra test
When we build tests/kernel/common/kernel.common.misra on
bl654_usb we get the following error:

subsys/usb/usb_descriptor.c:313:2: error: ISO C90 forbids array
'hwid' whose size cannot be evaluated [-Werror=vla]

Fix by removing use of usblen variable in array.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2021-09-01 12:34:01 -05:00
Eric Johnson 20b710a78e usb: class: cdc_acm: Add check for tx_irq_ena in tx_ready function
cdc_acm_irq_tx_ready was not checking if its interrupt was enabled.
This causes spurious tx irq handler calls.

Signed-off-by: Eric Johnson <eric@liveathos.com>
2021-09-01 11:50:59 +02:00
Johann Fischer 797d8d6a44 usb: dfu: add __fallghrough to DFU_UPLOAD/dfuIDLE case
Add __fallghrough to DFU_UPLOAD/dfuIDLE case.

Coverity-CID: 239607

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-08-30 13:40:46 -04:00
Johann Fischer 9d45581735 usb: cdc_acm: prefix ringbuffers with cdc_acm
Prefix ringbuffers with cdc_acm because it is not possible
to use static specifier with RING_BUF_*_DECLARE_* macros
to avoid conflicts.

Fixes: #36608

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-08-30 09:33:09 -04:00
Grixa Yrev 6a8abcb225 usb: cdc_acm: trigger TX IRQ when CDC ACM class is ready
Before commit 4f2682bd79
("usb: cdc_acm: avoid spurious interrupt on configured or resume
events") spurious rx-interrupt provided start to read shell tx ring
buffer by CDC ACM UART. Now shell log backend not transmit data,
until CDC ACM UART received data from host.

This PR added invoking interrupt callback if tx interrupt is enable,
when CDC ACM class go to configured state, and flag tx_ready go to true.

Signed-off-by: Grixa Yrev <GrixaYrev@yandex.ru>
2021-08-26 09:13:42 -04:00
Johann Fischer 1de84d2208 usb: cdc_acm: configure CDC ACM UART instances using devicetree only
Remove the possibility to configure number of CDC ACM UART
instances in Kconfig.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-08-23 18:53:47 -04:00
Johann Fischer 5e3319f091 usb: cdc_acm: allow to configure CDC ACM UART device from devicetree
Add hidden Kconfig option to Kconfig.cdc and allow
to configure CDC ACM UART device from devicetree.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-08-23 18:53:47 -04:00
Johann Fischer eb4b9b9cbd usb: finally remove Kconfig option CONFIG_USB
After the modules are adapted for the revised
USB device stack configuration, and it seems that
it was only necessary for MCUboot, we can finally
remove Kconfig option CONFIG_USB.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-08-17 16:58:58 +02:00
Johann Fischer 4f2682bd79 usb: cdc_acm: avoid spurious interrupt on configured or resume events
Do not submit k_work on on configured or resume events and
avoid spurious interrupt.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-08-12 16:57:12 -04:00
Johann Fischer 37f4d9ba63 usb: cdc_acm: rework cdc_acm_poll_out to non-blocking
Change cdc_acm_poll_out to do the best to mimic behavior
of a hardware UART controller without flow control.

With this patch, if the USB subsystem is not ready,
no data is transfered to the buffer, that is, new character
is dropped. If the USB subsystem is ready and the buffer is full,
the first character from the tx_ringbuf is removed to
make room for the new character.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-08-12 16:57:12 -04:00
Johann Fischer 5a35745b44 usb: fix SetInterface handling for interfaces without any endpoints
With the last changes in USB device stack it was unfortunately
not considered that an interface can have no endpoints.
This caused the USB DFU class to stop working in DFU mode.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-08-05 16:13:10 +02:00
Johann Fischer 3aa48613b1 usb: cdc_acm: add support for poll in to UART driver
Use cdc_acm_fifo_read() to support poll in.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-08-05 16:08:39 +02:00
Johann Fischer 9973314ea2 usb: cdc_acm: fix CDC ACM IAD initialization
CONFIG_CDC_ACM_IAD option should also be considered.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-08-05 16:08:39 +02:00
Johann Fischer ef18329051 usb: cdc_acm: rework descriptors, config, and data definitions macros
Simplify and rearrange the macros, remove unnecessary arguments.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-08-05 16:08:39 +02:00
Johann Fischer 4b79912dc7 usb: check request direction in request handlers
Check request direction in standard device,
interface, and endpoint request handlers.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-08-03 19:05:44 -04:00
Johann Fischer af3e1096f5 usb: cleanup standard interfave request handler
Cleanup standard device request handler.
Pass pointer to setup packet as argument where
it is reasonable.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-08-03 19:05:44 -04:00
Johann Fischer 49745250e4 usb: cleanup standard endpoing request handler
Cleanup standard endpoint request handler.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-08-03 19:05:44 -04:00
Johann Fischer d2ff6f4fdc usb: cleanup standard device request handler
Cleanup standard device request handler.
Pass pointer to setup packet as argument where
it is reasonable.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-08-03 19:05:44 -04:00
Johann Fischer 961d4a63fd usb: hid: obtain the requested length from wLength
Obtain the requested length from wLength and assign the
possible length to len argument.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-08-03 19:05:44 -04:00