set_endpoint() and reset_endpoint() were missing final
else statement in the if else if construct. This commit
adds a final else {} with assert to comply with coding
guideline 15.7.
Signed-off-by: Jennifer Williams <jennifer.m.williams@intel.com>
The z_timeout_end_calc function was replaced by
sys_clock_timeout_end_calc in #33302. A reference to the old function
snuck into master through #30015.
Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
Replace all existing deprecated API with the recommended alternative.
Be aware that this does not address architectural errors in the use
of the work API.
Fixes#34092
Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Instead of defining the string, that will be reported by DFU
as a name for DFU target, in code, pick it from the DTS label that
will be the DFU target.
Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
Alternative settings are determined by number of flash partitions
available for DFU from DTS.
Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
Zephyr already has a directory for storage API relevant headers.
Move disk_access.h header to include/storage where it fits better
structurally.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Allow callers to wait for an arbitrary amount of time, instead of always
waiting for a compile-time fixed period.
Signed-off-by: Josh Gao <josh@jmgao.dev>
Kconfig option USB_HID_PROTOCOL_CODE does not allow to set
boot interface protocol code for specific HID device but
only to set the same value for all device.
Add new API function to allow the application to set
Protocol Code per device. Deprecate USB_HID_PROTOCOL_CODE option.
Fixes: #32778
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
HID core implementation has support for Get/Set Idle requests and
on idle report processing. Basically it has little use.
Also, it has no users in the tree except samples/subsys/usb/hid,
which does not have it turned on.
There are several issues with the idle report implementation:
- Core calls hid_ops.on_idle callback with Report ID 0,
but this ID is reserved and should not be used.
Report descriptors do not use Report ID index zero.
- Calling hid_ops.on_idle with Report ID 0 cann only
be turned off by calling SetIdle(Duration = 0, Report ID = 0),
but not by SetIdle with Report ID not equal zero.
- GetIdle with Report Id not equal zero returns wrong
value after SetIdle(Duration = n, Report ID = 0)
- It may happen that hid_ops.on_idle is called for
different Report ID during one and the same SoF event.
But there can be only one hid_int_ep_write() during a frame.
This patch fixes listed issues and revises Get/Set Idle request,
and hid_sof_handler() implementation.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Currently there is no way to distinguish between a caller
explicitly asking for a semaphore with a limit that
happens to be `UINT_MAX` and a semaphore that just
has a limit "as large as possible".
Add `K_SEM_MAX_LIMIT`, currently defined to `UINT_MAX`, and akin
to `K_FOREVER` versus just passing some very large wait time.
In addition, the `k_sem_*` APIs were type-confused, where
the internal data structure was `uint32_t`, but the APIs took
and returned `unsigned int`. This changes the underlying data
structure to also use `unsigned int`, as changing the APIs
would be a (potentially) breaking change.
These changes are backwards-compatible, but it is strongly suggested
to take a quick scan for `k_sem_init` and `K_SEM_DEFINE` calls with
`UINT_MAX` (or `UINT32_MAX`) and replace them with `K_SEM_MAX_LIMIT`
where appropriate.
Signed-off-by: James Harris <james.harris@intel.com>
usb_hid_descriptor struct is only used internally and
is not intended to be used by the USB HID device application.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Move USB MSC configuration to its own Kconfig file.
Align with other class designations and rename
mass_storage.c to msc.c
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
acl_read_cb does not handle incoming (ACL) data
if BT_CTLR_TX_BUFFER_SIZE is greater than
USB_MAX_FS_BULK_MPS - BT_HCI_ACL_HDR_SIZE.
Since the host adjusts the data according to
the BT_CTLR_TX_BUFFER_SIZE and does not use ZLP
we cannot start usb_transfer over the possible length of
the whole packet, with or without USB_TRANS_NO_ZLP flag.
But we can read the packet length from the header and
call net_buf_put() when the whole packet is received.
Fixes: #31922
Reported-by: Matias Karhumaa <matias.karhumaa@gmail.com>
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Use BOS header structure directly we have access to
instead of casting extern const pointers.
Fixes: #30330
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Syncing here is done with a semaphore declared on a function stack
and released in a callback. In case of a cancelled transfer (eg.
cable disconnect) the callback is never called.
The fix introduces a periodic check if a transfer is still valid.
Signed-off-by: Jan Pohanka <xhpohanka@gmail.com>
Parallel transfer to same endpoint is not supported and
may cause a deadlock. Adding a check to prevent starting
the transfer if tranfer is already ongoing on same endpoint.
Transfer status was not checked when accessing to transfer
from endpoint callback. Adding status check, to prevent
a double completion.
Fixes#30736
Signed-off-by: Kari Hulkko <kari.m.hulkko@gmail.com>
If UART_INTERRUPT_DRIVEN isn't selected the CDC ACM class driver won't
build. Don't require the user's intervention to avoid this.
Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
Refactor the file structure for USB DFU class to facilitate
separate PID for USB DFU when in DFU mode. As required by USB DFU
1.1 Section 2, the PID in the USB device descriptor must be
different between the Run-time and DFU mode device descriptor to
avoid problems caused by the host OS caching the remaining
descriptors when switching to DFU mode, thus hiding the new
interface descriptors from applications on the host and reporting
the Run-time descriptors when the device is in DFU mode.
To avoid adding too much clutter to the root USB class Kconfig and
CMakeLists files, move the DFU class files into their own directory
with dedicated Kconfig and CMakeLists.txt.
Signed-off-by: Michael Rosen <michael.r.rosen@intel.com>
The USB device descriptors for DFU mode should only change after a
USB reset, not in appDETACH as the device is still in run-time mode
until reset; thus should still return the run-time descriptors when
requested.
Signed-off-by: Michael Rosen <michael.r.rosen@intel.com>
In accordance with USB DFU 1.1 Section 5.1, a device should only
stay in appDETACH for a given period of time, either from the
DFU_DETACH request (wValue ms) or from the wDetachTimeout property,
after which the device should return to appIDLE.
Signed-off-by: Michael Rosen <michael.r.rosen@intel.com>
Convert drivers to DEVICE_DEFINE instead of DEVICE_AND_API_INIT
so we can deprecate DEVICE_AND_API_INIT in the future.
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
ZLP - zero length packet is used to indicate that the device
has no more data to send. If the Host asks for more data that the
device can provide and the data size is mutliplication of Endpoint
wMaxPacketSize then the device must terminate the data transfer
with ZLP.
Until this patch Nordic device driver controller was not aware of
the requested data length and could not determine when the ZLP was
required.
This patch introduces a fix that prevents the driver from starting
setup stage before the ZLP is being send.
For consistance with the Zephyr USB stack sending ZLP must be
issued from the stack level. Making trans_zlp flag true results
in blocking the driver from starting setup stage without required
ZLP.
After the data transfer finishes the driver will be prepared for ZLP
and will call back the stack to start writing ZLP. After the ZLP
is being send the driver will automatically start status stage and
end the Control Transfer.
This patch also removes CONFIG_USB_DEVICE_DISABLE_ZLP_EPIN_HANDLING
and aligns Nordic driver with others.
Without this patch the issue could occur when handling get requests.
Typical case is string descriptor of length equal to wMaxPacketSize.
Hosts usually asks for wLength = 255 Bytes when string descriptors
are being requested. In that case to successfully finish the data
stage of the Control transfer the device must send wMacPacketSize
Bytes of actual string descriptor and then ZLP to indicate that no
more data are present. After ZLP the status stage may start and the
request is finished successfully.
Without this patch the driver will not send ZLP making it unable
to end the Control Request successful - this may lead to failing
'Device Descriptor Test' from USB3CV test tool.
Signed-off-by: Emil Obalski <emil.obalski@nordicsemi.no>
Kconfig USB_DFU_WAIT_DELAY_MS was hidden.
Added prompt for it so it can be configured.
Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
It is possible that USB DFU class is used by MCUBoot
itself while it has enabled CONFIG_SINGLE_APPLICATIO_SLOT.
In this mode only application slot is the primary slot.
Adapted DFU class descriptor and services to optionally
serve only for one image.
Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
End of DFU operation was signaled after the last usb dfu request was
received. Therefeore wait_for_usb_dfu() terminated so fast that
dfu_work_handler() was not called by k_work_queue befor.
wait_for_usb_dfu() should terminate after DFU operation was completed.
For fix that k_poll_signal_raise() was moved after the flash write
operation.
fixes#29611
Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
Status callback was logging whenever some statuses where
present. Those are not used by HCI class so drop them
and do not LOG if not necessary.
Signed-off-by: Emil Obalski <emil.obalski@nordicsemi.no>
USB bus might be suspended to save power. After the device
is Resumed from Suspended state there is a need to restart
OUT transfers for Endpoints used by HCI class. The transfers
shall be restarted only if the device was Resumed after Suspend
from Configured state. This patch applies the fix.
Signed-off-by: Emil Obalski <emil.obalski@nordicsemi.no>
Add prompt to USB_DEVICE_NETWORK_ECM_MAC Kconfig option to allow
users to change it. The current default value is assigned for
documentation purposes in RFC 7042.
Signed-off-by: Joakim Algrøy <joakimalgroy@gmail.com>
The existing calculation of the BULK_EP size can sometimes result in a
bulk EP size that is not spec-compliant. The accepted BULK_EP sizes are
8, 16, 32 or 64 bytes.
Additionally, the INT_EP size is always set to the max EP size since
BT_BUF_RX_SIZE is always greater than that (min. 73 in Kconfig).
This commit sets the BULK and INT endpoint sizes to their maximum
supported values.
Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
Both operands of an operator in the arithmetic conversions
performed shall have the same essential type category.
Changes are related to converting the integer constants to the
unsigned integer constants
Signed-off-by: Aastha Grover <aastha.grover@intel.com>
Depending on the Bluetooth features enabled, the HCI
packets can be 264 Bytes long. For HCI over USB the HCI packet
is handled in data stage of USB transfer. Buffer for the data
stage was too short and USB driver was STALLing the data stage
making it unable to complete. Extend the data stage buffer
to 266 Bytes if HCI USB is selected and BT_RX_BUF_LEN > 127
indicating that longer HCI packets are needed.
Signed-off-by: Emil Obalski <emil.obalski@nordicsemi.no>
The USB infrastructure currently uses the system work queue for
offloading transfers, CDC-ACM UART transmission/reception, and device
firmware activities. This causes problems when the system work queue
is also used to initiate some activities (such as UART) that normally
complete without requiring an external thread: in that case the USB
infrastructure is prevented from making progress because the system
work queue is blocked waiting for the USB infrastructure to provide
data.
Break the dependency by allowing the USB infrastructure to use a
dedicated work queue which doesn't depend on availability of the
system work queue.
Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
The z length modifier must be applied to avoid build errors when the
format is verified by the compiler on systems where size_t is larger
than int.
Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
Both tx_irq_ena and rx_irq_ena flags shall be updated only
by using UART API. Those flags are used to let the device
start sending or receiving data. Changing those flags without
awareness of the user may lead to errors.
Signed-off-by: Emil Obalski <emil.obalski@nordicsemi.no>
Usage of `pool_wait_sem` was incorrect. The semaphore shall be
dependent on context it was called for. In case of many CDC_ACM
devices one could possibly block others. This fixes an issue by
making semaphore a part of the internal CDC_ACM device structure.
Signed-off-by: Emil Obalski <emil.obalski@nordicsemi.no>
is_ep_valid() function was incorrectly searching through
all used endpoints. All endpoints for class must be checked
if they match requested endpoint.
Signed-off-by: Emil Obalski <emil.obalski@nordicsemi.no>