Commit graph

79 commits

Author SHA1 Message Date
Erwan Gouriou 66d4c64966 all: Fix "#if IS_ENABLED(CONFIG_FOO)" occurrences
Clean up occurrences of "#if IS_ENABLED(CONFIG_FOO)" an replace
with classical "#if defined(CONFIG_FOO)".

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2022-12-21 10:09:23 +01:00
Tomasz Moń 21975231e2 usb: device: cdc_acm: Prevent recursive logging loop
Allow enabling CDC ACM logging only if CDC ACM is not used as logging
backend. This prevents endless recursive logging loop, especially
visible when minimal footprint logging is enabled.

Fixes: #52981

Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
2022-12-15 14:54:24 +01:00
Tomasz Moń fed6bde788 usb: device: cdc_acm: send more than 1 byte in poll out
Schedule CDC ACM tx work to happen 1 ms after first unprocessed data
write. This gives enough leeway for the task writing to the queue to
write more than 1 byte before USB workqueue preempts and schedules IN
transfer. Sending more than 1 byte at a time increases data throughput
because transaction overhead remains the same regardless of packet size.

Prior to this change, virtually every IN transaction carried only one
character when CDC ACM was used as a console.

Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
2022-12-14 12:07:33 +01:00
Witold Lukasik c7acd98bf4 usb: device: update logging module registration
Update logging module registration and remove LOG_LEVEL macro
for USB device classes.

Signed-off-by: Witold Lukasik <witold.lukasik@nordicsemi.no>
2022-12-12 15:57:35 +01:00
Tomasz Moń f8ac6b6d66 usb: device: Disable all endpoints on stack disable
Disable all enabled endpoints on stack disable to allow re-enabling USB
device stack.

Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
2022-11-25 20:02:42 +01:00
Milind Paranjpe cf91f1873b usb: disable previously enabled endpoint before re-enabling
When switching between alternate settings of an interface, it is
currently possible to call set_endpoint() multiple times on an endpoint
without first calling reset_endpoint(). For these situations, it is
beneficial to track endpoints for which set_endpoint() has previously
been called, and then reset them to properly terminate any transfers,
and to return the HAL to the correct state

Signed-off-by: Milind Paranjpe <mparanjpe@yahoo.com>
2022-11-23 12:59:40 +01:00
Johann Fischer 1c4011ff6e usb: remove usb_pid.Kconfig file
Remove Kconfig file samples/subsys/usb/usb_pid.Kconfig added in
the commit e5cbe6a9e7 ("usb: cdc: Add unique PIDs for each sample")
with the motivation to have a separate ID for each sample supposedly
to be recognizable by the host.

The new USB support does not use the options, VID/PID is set
directly in the application. As a note, it is not necessary to have
unique PID for each sample, especially for the well known USB classes.

Replace the individual Kconfig options in the documentation
by a table with the references to the samples and PIDs.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2022-11-22 11:09:21 +01:00
Tomasz Moń a9bfe0a423 usb: dfu: Reduce default bwPollTimeout value
The bwPollTimeout name is somewhat confusing as it refers to minimum
polling period. The bwPollTImeout is essentially a mechanism allowing
device to ratelimit DFU_GETSTATUS requests from host.

Setting bwPollTimeout to relatively high values effectively slows down
DFU download process. The slowdown is not observed if the time between
DFU_DNLOAD and DFU_GETSTATUS is enough for the device to process the
write. That is, the bwPollTimeout does not effect DFU download if the
first DFU_GETSTATUS after DFU_DNLOAD reports dfuDNLOAD-IDLE state.
Otherwise the host must wait bwPollTimeout ms before issuing next
DFU_GETSTATUS, which slows the communicaiton to not more than 1 download
block (CONFIG_USB_REQUEST_BUFFER_SIZE) every bwPollTimeout ms.

The bwPollTimeout ideally should report an estimate how much longer the
download operation will take. Zephyr does not have such estimate and
therefore defaults to using fixed value. Reduce default bwPollTimeout
from 256 to 8 ms to allow significantly faster DFU downloads on devices
where the time between DFU_DNLOAD and DFU_GETSTATUS is too short to
process download block at the expense of unnecessary bus traffic if
processing download block takes longer than 8 ms.

Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
2022-11-22 13:03:11 +09:00
Chun-Chieh Li 59f3316d33 usb: audio: do not discard usb_transfer result in usb_audio_send()
Pass result of usb_transfer() as return value to the user,
and allow user to react accordingly, e.g. release net_buf on error.

Signed-off-by: Chun-Chieh Li <ccli8@nuvoton.com>
2022-11-21 20:11:24 +01:00
Tomasz Moń 04059ec8a7 usb: device: msc: synchronize cache after writes
Flush disk cache when write command finishes.

Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
2022-11-02 10:31:58 +01:00
Robert Lubos 942800784c net: netusb: Align netusb driver with iface state upgrade
Align netusb driver with interface state handling update. Instead of
bringing the interface up/down from the driver level, use carrier on/off
notification to update the inteface state.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-10-20 10:00:31 +02:00
Gerard Marull-Paretas b959ab25a9 include: add missing sys/slist.h include
Some headers makes use of slists w/o including sys/slist.h

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-10-11 18:05:17 +02:00
Tomasz Moń c27d48c89a usb: dfu: Support DFU with WinUSB on Windows
DFU on Windows with WinUSB driver failed with "Lost device after RESET?"
error because WinUSB does not support host initiated resets. USB Device
Firmware Upgrade Specification Revision 1.1 attribute bitWillDetach can
be used to overcome WinUSB reset limitation. When bitWillDetach is set,
it is the device responsibility to detach and reattach itself to the bus
after receiving DFU_DETACH request.

Add and enable by default USB_DFU_WILL_DETACH configuration option,
because it is the only way to support WinUSB driver. WinUSB driver is
preferable because it can be automatically installed on Windows 8 and
later if USB device implements WCID descriptors.

Fixes: #49821

Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
2022-10-06 09:12:34 +00:00
Dominik Ermel f762fc7a2c usb: dfu: Switch from FLASH_AREA_ to FIXED_PARTITION_
The commit switches flash area access from FLASH_AREA_ macros
to FIXED_PARTITION_ macros and to usage of DTS node labels,
to identify partitions, instead of label property.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-09-06 09:56:37 +02:00
Gerard Marull-Paretas 79e6b0e0f6 includes: prefer <zephyr/kernel.h> over <zephyr/zephyr.h>
As of today <zephyr/zephyr.h> is 100% equivalent to <zephyr/kernel.h>.
This patch proposes to then include <zephyr/kernel.h> instead of
<zephyr/zephyr.h> since it is more clear that you are including the
Kernel APIs and (probably) nothing else. <zephyr/zephyr.h> sounds like a
catch-all header that may be confusing. Most applications need to
include a bunch of other things to compile, e.g. driver headers or
subsystem headers like BT, logging, etc.

The idea of a catch-all header in Zephyr is probably not feasible
anyway. Reason is that Zephyr is not a library, like it could be for
example `libpython`. Zephyr provides many utilities nowadays: a kernel,
drivers, subsystems, etc and things will likely grow. A catch-all header
would be massive, difficult to keep up-to-date. It is also likely that
an application will only build a small subset. Note that subsystem-level
headers may use a catch-all approach to make things easier, though.

NOTE: This patch is **NOT** removing the header, just removing its usage
in-tree. I'd advocate for its deprecation (add a #warning on it), but I
understand many people will have concerns.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-09-05 16:31:47 +02:00
Kumar Gala a96eaf25f9 usb: device: cdc: Update Kconfig
Utilize DT_HAS_<COMPAT>_ENABLED for devicetree based driver

Signed-off-by: Kumar Gala <galak@kernel.org>
2022-09-02 10:59:32 +00:00
Daniel DeGrasse 575a8e116c usb: Increase mass storage stack size when SD stack is enabled
SD stack requires a larger stack size than the default value for the
mass storage stack thread. Increase the default stack size to 768 when
the SD stack is enabled.

Fixes #49057

Signed-off-by: Daniel DeGrasse <daniel.degrasse@nxp.com>
2022-08-17 12:09:17 +02:00
Johann Fischer 6130417212 usb: device: add dummy configure API
We cannot implement configure API because there is
no notification of configuration changes provided
for the Abstract Control Model and the UART controller
is only emulated.
However, it allows us to use CDC ACM UART together with
subsystems like Modbus which require configure API for
real controllers.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2022-07-13 11:36:59 +02:00
Pawel Osypiuk 7fcfd54423 usb: device: cdc_acm: suspend transfers when RX path runs out of buffer
Suspend CDC ACM class OUT transfers when RX path runs out
of ring buffer.

Signed-off-by: Pawel Osypiuk <pawelosyp@gmail.com>
2022-07-11 10:31:12 +02:00
Aurelien Jarno 77ef1b715a usb: cdc_acm: implement uart_config_get() API
Implement the uart_config_get() API by converting the existing
line coding structure to the struct uart_config format.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2022-07-05 18:00:24 +02:00
Kumar Gala c880dc908f usb: device: Update to use gpio_dt_spec
Move to use gpio_dt_spec for GPIO access.

Signed-off-by: Kumar Gala <galak@kernel.org>
2022-07-04 15:34:13 +02:00
Corey Wharton 4a87ae07bf netusb: allocate packets from RX pool for incoming frames
Allocate packets and buffers from the RX slab/pool when handling
incoming frames.

Signed-off-by: Corey Wharton <xodus7@cwharton.com>
2022-07-01 16:26:13 +00:00
Julien D'Ascenzio fdf5dc384d usb: cdc_acm: fix bug on transmission
In the function tx_work_handler, a pointer to ring buffer data is given
to usb_transfer then the ring_buf_get_finish is called. So, the data is
mark as read (by ring_buf_get_finish) while the data are not yet
transferred to usb. If later a user send data, the pointer hold by usb
stack could be rewrite.

Signed-off-by: Julien D'Ascenzio <julien.dascenzio@paratronic.fr>
2022-06-28 16:58:51 +02:00
Rubin Gerritsen 77b8252da6 usb: bt_h4: Set stack sizes using Kconfig
The previously used stack sizes where in many cases too small.

Signed-off-by: Rubin Gerritsen <rubin.gerritsen@nordicsemi.no>
2022-06-23 14:40:01 +02:00
Keith Packard abac6ccfaf subsys/usb: Fix use of 'abs' in computing when to report on_idle
idle_rate is uint8_t, sof_cnt is uint32_t. The result is uint32_t, which
is the wrong type for 'abs'. Explicitly cast idle_rate to uint32_t,
subtract sof_cnt and then explicitly cast to int32_t and then use abs,
storing the result in another int32_t which matches the return type for
abs.

This quiets clang warnings about passing unsigned values to abs.

Signed-off-by: Keith Packard <keithp@keithp.com>
2022-06-14 01:50:36 +09:00
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