It might happens that DT(_INST)_PROP_OR is used with boolean properties.
For instance:
.single_wire = DT_INST_PROP_OR(index, single_wire, false), \
.tx_rx_swap = DT_INST_PROP_OR(index, tx_rx_swap, false), \
This is not required as boolean properties are generated with false
value when not present, so the _OR macro extension is superflous
and the above code can be replaced by:
.single_wire = DT_INST_PROP(index, single_wire), \
.tx_rx_swap = DT_INST_PROP(index, tx_rx_swap), \
Signed-off-by: Roman Studenikin <srv@meta.com>
audio_receive_cb is only used by headphones and headset, it is unused in
microphone-only configurations. Gate compilation based on the device
tree.
Signed-off-by: James Zipperer <jzipperer@fb.com>
Queue characters in TX ring buffer regardless of interface state. This
allows simple applications that print basic output to CDC ACM port to
not care about connection or DTR state. Note that depending on actual
application requirements it might be still wise to wait for DTR before
trying to send data.
Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
Prevent ECHO on Linux by arming IN endpoint with ZLP when interface is
configured and making sure that actual payload is only sent after
initialization timeout. The ZLP is not visible to host side applications
because the applications are really accessing tty buffer and received
ZLP does not modify tty buffer in any way.
Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
Rename local usbd copy from nrfx_usbd to nrf_usbd_common and use it in
both USB stacks. Renaming header to nrf_usbd_common.h allows breaking
changes in exposed interface. Mark all doxygen comments as internal
because local usbd copy should not be treated as public interface
because we are under refactoring process that aims to arrive at native
driver and therefore drop nrf_usbd_common in the future.
Use Zephyr constructs directly instead of nrfx glue macros.
No functional changes.
Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
ZLP packet has to be read and acknowledged by host just like any other
DATA packet. Do not end transfer until the host actually acknowledged
the trailing ZLP. This fixes the race condition between host and Zephyr
application where the next transfer could be lost if host did not issue
IN token (that would read read ZLP) before the application tried to
start new transfer.
Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
According to the UART API documentation, implementation must block when
the transceiver is full. For CDC ACM UART, TX ringbuffer can be
considered as transceiver buffer/FIFO. Blocking when the USB subsystem
is not ready is considered highly undesirable behavior. Blocking may
also be undesirable when CDC ACM UART is used as a logging backend.
Change the behavior of CDC ACM poll out to:
- Block if the TX ring buffer is full, hw_flow_control property is
enabled, and called from a non-ISR context.
- Do not block if the USB subsystem is not ready, poll out
implementation is called from an ISR context, or hw_flow_control
property is disabled.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
When a usb_transfer is cancelled, the callback is finally invoked.
Silly, there is no transfer status passed, and in the callback we can
only check the size and device status.
Reported-by: Alex Kaiser
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Fix few instances of delayable work handlers using the k_work pointer
directly in a CONTAINER_OF pointing to a k_work_delayable.
This is harmless since the k_work is the first element in
k_work_delayable, but using k_work_delayable_from_work is the right way
of handling it.
Change a couple of explicit CONTAINER_OF doing the same work as the
macro in the process.
Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
CONFIG_COVERAGE has been incorrectly used to
change other kconfig options (stack sizes, etc)
code defaults, as well as some samples behaviour,
which should not have dependend on it.
Instead those should have depended on COVERAGE_GCOV,
which, being the one which adds special code and
temporary RAM storage for embedded targets,
require changes to many features.
When building for the native targets, all this was
unnecessary.
=> Fix the dependency.
Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
Log transfer status and release transfer semaphore regardless if user
provided transfer completion callback or not. This fixes transfer slot
leak when transfer without callback completes.
Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
The usb_msc.h header does not provide any API. The content is only
used by the MSC implementation for the current USB device stack and
is not required for any use of MSC by the application.
The content has no proper namespace and must not be reused for
anything else in (new) USB support.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Effectively, this option changes code triple in device descriptor.
Although the name is misleading, renaming it would again lead
to negative user experiences. Instead, clarify what the option does
and always select it where it is required.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Every USB device must buffer isochronous data for at least 1 frame in
order to remove packet jitter within a frame. USB Specification Revision
2.0 describes necessary buffering in 5.12.5 Data Prebuffering. USB Audio
1.0 specification mentions buffering in 3.4 Inter Channel Synchronization.
Set bDelay to 1 instead of 0, because bDelay 1 is both the minimum
allowed value and matches the actual device behavior.
Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
Instead of assuming pointers are 32bits wide,
cast them to the appropriate pointer arithmetic type.
Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
Prevent potential buffer overflow when encapsulated response is more
than CONFIG_USB_REQUEST_BUFFER_SIZE. Log error and truncate response if
USB control transfer request buffer is not large enough.
Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
Until now iterable sections APIs have been part of the toolchain
(common) headers. They are not strictly related to a toolchain, they
just rely on linker providing support for sections. Most files relied on
indirect includes to access the API, now, it is included as needed.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
The possible control endpoint MPS for USB 2.0 FS devices is
8, 16, 32, or 64 bytes. Typically, USB2.0 compliant devices support MPS
up to 64 bytes, and we have not had the need to support other MPS.
This patch implements a mechanism to fall back to the minimum allowed
MPS when a controller is likely a USB 1.1 compliant device and does
not support control endpoint MPS of 64 bytes.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
This reverts commit cd7461495f,
introduced to fix possible deadlock as result of changes in
commit f206170c65
("usb: device: Do not call callback when transfer is cancelled")
which is now reverted.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
This reverts commit f206170c65
introduced as workaround for nRF USBD device controller in PR
https://github.com/zephyrproject-rtos/zephyr/pull/16193.
This commit may be reverted due to changes made in
commit e326c58399
("usb: device: Do not cancel transfers on suspend").
Signed-off-by: Nickolas Lapp <nickolaslapp@gmail.com>
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
The init infrastructure, found in `init.h`, is currently used by:
- `SYS_INIT`: to call functions before `main`
- `DEVICE_*`: to initialize devices
They are all sorted according to an initialization level + a priority.
`SYS_INIT` calls are really orthogonal to devices, however, the required
function signature requires a `const struct device *dev` as a first
argument. The only reason for that is because the same init machinery is
used by devices, so we have something like:
```c
struct init_entry {
int (*init)(const struct device *dev);
/* only set by DEVICE_*, otherwise NULL */
const struct device *dev;
}
```
As a result, we end up with such weird/ugly pattern:
```c
static int my_init(const struct device *dev)
{
/* always NULL! add ARG_UNUSED to avoid compiler warning */
ARG_UNUSED(dev);
...
}
```
This is really a result of poor internals isolation. This patch proposes
a to make init entries more flexible so that they can accept sytem
initialization calls like this:
```c
static int my_init(void)
{
...
}
```
This is achieved using a union:
```c
union init_function {
/* for SYS_INIT, used when init_entry.dev == NULL */
int (*sys)(void);
/* for DEVICE*, used when init_entry.dev != NULL */
int (*dev)(const struct device *dev);
};
struct init_entry {
/* stores init function (either for SYS_INIT or DEVICE*)
union init_function init_fn;
/* stores device pointer for DEVICE*, NULL for SYS_INIT. Allows
* to know which union entry to call.
*/
const struct device *dev;
}
```
This solution **does not increase ROM usage**, and allows to offer clean
public APIs for both SYS_INIT and DEVICE*. Note that however, init
machinery keeps a coupling with devices.
**NOTE**: This is a breaking change! All `SYS_INIT` functions will need
to be converted to the new signature. See the script offered in the
following commit.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
init: convert SYS_INIT functions to the new signature
Conversion scripted using scripts/utils/migrate_sys_init.py.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
manifest: update projects for SYS_INIT changes
Update modules with updated SYS_INIT calls:
- hal_ti
- lvgl
- sof
- TraceRecorderSource
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
tests: devicetree: devices: adjust test
Adjust test according to the recently introduced SYS_INIT
infrastructure.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
tests: kernel: threads: adjust SYS_INIT call
Adjust to the new signature: int (*init_fn)(void);
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
Track LBA rather than byte offset in order to simplify the code and
support devices larger than 4GiB.
Signed-off-by: JP Sugarbroad <jpsugar@amazon.com>
set_device can be called in interrupt context at least with
stm32u5 soc. Calling k_usleep from there causes the isr
to run forever.
Signed-off-by: Miika Karanki <miika.karanki@vaisala.com>
Changed incrementing `for` loop counters to `size_t` from `int` to
eliminate warning, "warning: comparison of integer expressions of
different signedness: 'uint32_t' {aka 'unsigned int'} and 'int'
[-Wsign-compare]"
Signed-off-by: Zachary J. Fields <zachary_fields@yahoo.com>
Allows receive packets that are bigger than
CONFIG_RNDIS_BULK_EP_MPS.
Considering:
* MaxPacketsPerTransfer is 1
* MaxTransferSize is 1558
* PacketAlignmentFactor is 0 (20=1)
The rndis_bulk_out shall be able to receive transfer
up to 1558 bytes (inclusive).
Signed-off-by: Georgij Cernysiov <geo.cgv@gmail.com>
Cancelling transfers on suspend contradicts Universal Serial Bus
Specification Revision 2.0, 9.1.1.6 Suspended:
* When suspended, the USB device maintains any internal status,
including its address and configuration.
The internal status definitely includes any pending USB transfers.
If there is a class that wants to cancel transfer on suspend, then the
cancel should be initiated by the class, not the device stack itself.
Update hal_nordic to a version that does not abort all endpoints at
suspend. It seems that aborting endpoints on suspend in nrfx driver was
the actual reason why transfers were canceled on suspend.
Remove transfer retriggering on resume from CDC ACM and Bluetooth class
implementations because transfers are no longer cancelled on suspend.
Other classes do not have any suspend related workarounds implemented.
Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
USB_TRANS_NO_ZLP flag has no meaning for usb_transfer() in
host-to-device direction (USB_TRANS_READ).
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Use k_work_delayable instead of k_timer in order to execute timeout in
USB workqueue context instead of ISR context. This fixes Will-Detach on
targets where usb_dc_detach() uses functions not allowed in ISR context,
e.g. nrfx usb_dc_detach() acquires mutex.
Fixes: c27d48c89a ("usb: dfu: Support DFU with WinUSB on Windows")
Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
bcdHID is intended for the spec version of USB HID. It was pointing to the
v1.1 bcdUSB define which happens to be the same value for the v1.10 hid
spec version. This corrects it to use the v1.11 HID spec.
Signed-off-by: Ryan McClelland <ryanmcclelland@meta.com>
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>
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>
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>
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>
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>
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>
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>