Add new USB device controller API and nRF USBD controller driver.
The new UDC API brings support for multiple instances and asynchronous
transfer model, transfers use net_buf and store methadata in the
user data area.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
There is no point in allowing endpoint disable only when device is
attached and ready. Remove the pointless check as it is actually harmful
and prevents endpoints disable on USB stack disable.
Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
In usb_dc_ep_disable() mark an endpoint as unoccupied in addition to
being disabled. This allows the endpoint to get enabled properly
with a subsequent call to usb_dc_ep_enable()
See: zephyrproject-rtos/zephyr#51685
Signed-off-by: Milind Paranjpe <mparanjpe@yahoo.com>
The buf_status register is 32 bit wide but was saved in a
uint8_t. This caused some buffers never to be handled which
results in the pico getting stuck in the interrupt handler.
Signed-off-by: Lukas Gehreke <lk.gehreke@gmail.com>
The USB device subsystem driver's set_interface() function calls
usb_dc_ep_configure() followed by usb_dc_ep_enable(). When
switching between alternate settings of a configuration's
interface, set_endpoint() can be followed by reset_endpoint() on
an endpoint. Some time later, set_endpoint() can be called again
on the same endpoint. This results in the HAL's
kUSB_DeviceControlEndpointInit function being called twice in a
row, which causes a memory allocation error. A simple solution is
to call the HAL's kUSB_DeviceControlEndpointDeinit function
before calling kUSB_DeviceControlEndpointInit. This overcomes the
memory allocation error.
Signed-off-by: Milind Paranjpe <mparanjpe@yahoo.com>
Change automated searching for files using "IRQ_CONNECT()" API not
including <zephyr/irq.h>.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
SAM V71 Xplained Ultra failed to re-enumerate on the bus after device
detach-attach sequence. The device was recognized by the host, but it
was not responding to control transfers, i.e. it was not acknowledging
SETUP data. Make device acknowledge SETUP data by reconfiguring EP0
when necessary.
Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
Device physically detaches when the DETACH bit is set. Fix the
assignment to actually set the bit instead of clearing it.
Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
Sometimes it is desired for the USB device to detach and reattach itself
to the host. USB device controller driver interface supports detach with
usb_dc_detach() function. Subsequently the device can be reattached to
the bus by calling usb_dc_attach().
USB device stack sets the control transfer callbacks in usb_enable().
Nordic usb_dc_detach() implementation inadvertedly overwrote registered
callbacks with zeroes by clearing endpoint configuration structure. This
lead to a NULL pointer dereference during enumeration after device has
reattached inself to the host.
Preserve the callbacks by removing the eps_ctx_uninit() function.
Endpoints runtime data is initialized in usb_dc_attach() so this should
pose no problems.
Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
The usb_dc_sam0 driver is leaking memory when the usb device is detached
using usb_disable().
When a device is detached, the driver does not reliably deallocate the
descriptor bank memory. Therefore, upon the next attach and configure,
another block of memory is allocated. After several connect /
disconnect sequences, the usb interface becomes unresponsive.
This commit adds a static function to release all memory allocated
to the ep descriptors when usb_dc_detach() is called. Since detach is
called from usb_disable(), this releases the memory when the
interface is disabled.
Avoid calling k_free() if buffer pointer is already
set to NULL.
Fixes#49177
Signed-off-by: Steven Slupsky <sslupsky@gmail.com>
Ensure that the FIFO of each endpoint is initialized during endpoint
configuration, to prevent a NULL FIFO from being encountered during the
first call to usb_dc_ep_write() for a given endpoint.
Signed-off-by: Nick Kraus <nick@nckraus.com>
1. Move the defines from usb_dc_mcux.h to usb_device_config.h
and fsl_os_abstraction.h. These headers are used by
the SDK USB driver. usb_dc_mcux.h header file is not longer
needed and hence deleted.
2. Delete the Zephyr implementation of the usb_device_struct
driver and use the one implemented inside the SDK USB
driver. This requires updating the references to
usb_device_struct inside the USB driver
3. Move defines and structures used by the driver
out of the header file that is included by the SDK and
into the MCUX USB driver.
4. Use end point defines provided by Zephyr instead of adding
them locally.
5. Add a Kconfig to set the thread stack size
6. Move code to enable interrupts back to usb_attach function.
Interrupts should be enabled after the init is successful,
else we see errors of the ISR getting called before the
init is complete causing Faults
6. Update west.yml to update the NXP HAL to get the updated
SDK USB driver.
Signed-off-by: Mahesh Mahadevan <mahesh.mahadevan@nxp.com>
So far thread was created as part of usb_dc_attach() by k_thread_create().
This means that if following function were executed:
* usb_enable()
* usb_disable()
* usb_enable()
then k_thread_create() was called second time. This results in undefined
behavior.
Fix above issue by moving k_thread_create() invocation to function called
during system initialization.
While at it, move IRQ_CONNECT() and irq_enable() invocations to init as
well.
Signed-off-by: Marcin Niestroj <m.niestroj@emb.dev>
So far thread was created as part of usb_dc_attach() by k_thread_create().
This means that if following function were executed:
* usb_enable()
* usb_disable()
* usb_enable()
then k_thread_create() was called second time. This results in undefined
behavior.
Fix above issue by moving k_thread_create() invocation to function called
during system initialization.
While at it, move IRQ_CONNECT() and irq_enable() invocations to init as
well.
Signed-off-by: Marcin Niestroj <m.niestroj@emb.dev>
So far thread was created as part of usb_dc_attach() by k_thread_create().
This means that if following function were executed:
* usb_enable()
* usb_disable()
* usb_enable()
then k_thread_create() was called second time. This results in undefined
behavior.
Fix above issue by moving k_thread_create() invocation to function called
during system initialization.
While at it, move IRQ_CONNECT() and irq_enable() invocations to init as
well.
Signed-off-by: Marcin Niestroj <m.niestroj@emb.dev>
Update usb device drivers to use DT_HAS_<compat>_ENABLED Kconfig symbol
to expose the driver and enable it by default based on devicetree.
We remove 'depend on' Kconfig for symbols that would be implied by
the devicetree node existing.
Signed-off-by: Kumar Gala <galak@kernel.org>
Many device pointers are initialized at compile and never changed. This
means that the device pointer can be constified (immutable).
Automated using:
```
perl -i -pe 's/const struct device \*(?!const)(.*)= DEVICE/const struct
device *const $1= DEVICE/g' **/*.c
```
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
Soft resetting a STM32 device currently does not reset the USB
connection, which causes a few problems: The endpoints do not respond
anymore, and within zephyr any kind of status information like
CDC_SET_CONTROL_LINE_STATE is also missing as they are not
re-negotiated.
This is fixed by stopping the USB device from zephyr side, right after
initialising the USB device.
Signed-off-by: David Jablonski <dayjaby@gmail.com>
MISRA C:2012 Rule 14.4 (The controlling expression of an if statement
and the controlling expression of an iteration-statement shall have
essentially Boolean type.)
Use `do { ... } while (false)' instead of `do { ... } while (0)'.
Use comparisons with zero instead of implicitly testing integers.
The commit is a subset of the original auditable-branch commit:
5d02614e34a86b549c7707d3d9f0984bc3a5f22a
Signed-off-by: Simon Hein <SHein@baumer.com>
- If the HAL headers expose the USBPRE flag, then we're probably
dealing with a F103 - using the same fundamental logic as the
code for the OTG models, set-up the USB Prescaler correctly.
- Fixes#47146
Signed-off-by: Chris Collins <chris@realsimgear.com>
On SoCs with two USB controller, Zephyr selects the FS one, and in that
case the ULPI clock needs to be disabled in sleep mode for the
controller to work.
On SoCs with a single USB HS controller, this operation is not needed.
Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
The ULPI clock uses slightly different names on STM32H7X as those
SoC can have more than one USB controller.
Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
On STM32H7X SoCs, both USB controllers are HS capable, however it is not
possible to connect an ULPI PHY to the USB2 one, which limit it to FS.
Therefore the ULPI clock in sleep mode has to be disabled for USB2 in
all cases. The ULPI clock for USB1 is already disabled when needed in
the usb_dc_stm32_clock_enable() function like for other SoCs.
Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
Do not manually enable the USB clock on STM32H7, as it is already done
in usb_dc_stm32_clock_enable() using the values in the device tree.
This partially fixes the build for STM32H7 devices with a single USB
controller.
Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
The ULPI clock is disabled by default in run mode, there is no need to
disable it again. It is however enabled by default in sleep/low power
mode, so it needs to be disabled.
Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
Adds few missing zephyr/ prefixes to leftover #include statements that
either got added recently or were using double quote format.
Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
For some reason, rather than testing for the presence of
disconnect-gpios in the devicetree, the STM32 USB Device driver was
relying on a hidden Kconfig flag to be set.
This patch removes the Kconfig option completely and simply tests for
the DT property - if it's set, you obviously know what you're doing and
obviously need the pull-up GPIO behaviour.
Signed-off-by: Chris Collins <chris@realsimgear.com>
Adding support for the GIC_V1 to the dc_dw USB driver
to be used by Cyclone V SoC FPGA Development Kit
Signed-off-by: Esteban Valverde <esteban.valverde.vega@intel.com>
In order to bring consistency in-tree, migrate all drivers to the new
prefix <zephyr/...>. Note that the conversion has been scripted, refer
to #45388 for more details.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
This add support to pinctrl at Atmel sam0 usb dc driver. It updates
all boards with new pinctrl groups format and drop pinmux entries.
Signed-off-by: Gerson Fernando Budke <nandojve@gmail.com>
This update Atmel sam usb drivers to use pinctrl driver and API. It
updates all boards with new pinctrl groups format.
Signed-off-by: Gerson Fernando Budke <nandojve@gmail.com>
Enable second usb EHCI if usb2 node has status="okay" Note that this
driver is still an single instance driver, this change simply enables
the driver to work with the usb2 peripheral if that one is enabled, and
usb1 is disabled.
Signed-off-by: Daniel DeGrasse <daniel.degrasse@nxp.com>
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>
MCUX usb ISR was making usb callbacks directly, which caused assertion
failures when a callback attempted to lock a mutex. Move USB callback
handler to separate thread, and make ISR notify thread via message
queue.
Fixes#40638
Signed-off-by: Daniel DeGrasse <daniel.degrasse@nxp.com>
The PINCTRL_DT_(INST_)DEFINE macros already defined the trailing ;,
making its usage inconsistent with other macros such as
DEVICE_DT_DEFINE.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
This flag may cause host to more ambitious power saving behavior,
not all Zephyr USB classes or applications may be ready for this
now. Allow to disable option USB_DEVICE_REMOTE_WAKEUP.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Use the new pinctrl API to configure pins.
Additionally, rename usb_pinctrl to usb_pcfg to better fit
new pinctrl API.
Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
Fill in received bytes in USBIP_RET_SUBMIT packet
Currently this field is unconditionally set to 0 and therefore not
filled in conveniently. This may mislead the USB host which is correctly
acknowledged that the transaction was sucessful but it cannot check the
actual received bytes.
Test application:
```python
import usb
data = (0xFF, 0xFF)
print("Opening loopback device")
device = usb.core.find(idVendor=0x2FE3, idProduct=0x0009)
print("Writing test data", data)
written = device.write(0x1, data)
print("Written", written, "bytes")
```
Before:
```
$ ./test_loopback.py
Opening loopback device
Writing test data (255, 255)
Written 0 bytes
```
After:
```
$ ./test_loopback.py
Opening loopback device
Writing test data (255, 255)
Written 2 bytes
```
Signed-off-by: Raúl Sánchez Siles <rsanchezs@k-lagan.com>
Use DT_INST_ENUM_IDX_OR and always default to full-speed
if CONFIG_USB_DC_HAS_HS_SUPPORT is not set or maximum-speed
property is not defined.
Remove low-speed setting since device stack does not support it.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
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>
Check return value from recv() passed by usbip_recv().
Fixes: #39849Fixes: #39869
Coverity-CID: 240221
Coverity-CID: 240244
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
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>
This commit enables the HSI48 clock for the stm32U5 soc family
to use the USB device peripheral.
Enable the VDD USB voltage supply.
Signed-off-by: Francois Ramu <francois.ramu@st.com>
Use of '__DEPRECATED_MACRO' was not compatible with the way macro
is used later in this driver.
Remove it and keep the warning as vector for deprecation information.
Additionally, replace DT_NODE_HAS_PROP with DT_INST_PROP as
using the former is not recommended with boolean properties.
Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
Add a Kconfig option, similar to the one that is already available
for nRF5340, that allows enabling the REG0 (VDDH) DC/DC converter
in nRF52840. Make use of this option in Nordic boards: nRF52840 DK
and nRF52840 Dongle.
Signed-off-by: Andrzej Głąbek <andrzej.glabek@nordicsemi.no>
This changes "__nocache K_HEAP_DEFINE()" to use the new
K_HEAP_DEFINE_NOCACHE() macro. This fixes a build error
as K_HEAP_DEFINE() is specifying its own linker section
so that it is no longer possible to specify another
linker section.
Fixes#38108
Signed-off-by: Daniel Leung <daniel.leung@intel.com>
Add logging for NRFX_USBD_EP_ABORTED event inside
control transfer events handling, otherwise "Unexpected event"
error message in this regard confuses the users.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Add sam4l full finite state machine based on Atmel Software Framework.
This allows driver detect protocol errors and sync all requests. This
version is compliance with Linux USB tests.
Note: Tests are timing sensitive and log may affect results.
Signed-off-by: Gerson Fernando Budke <nandojve@gmail.com>
1. Add support for NXP LPC USB controller
2. Do not check the return value from the
kUSB_DeviceControlRun command as not all SDK drivers
return a value
3. Use the kUSB_DeviceControlPreSetDeviceAddress
command to set device address
Signed-off-by: Mahesh Mahadevan <mahesh.mahadevan@nxp.com>
Instead of putting object files inside libzephyr.a,
simply build a separate static library as most other
driver types are doing this already.
Signed-off-by: Daniel Leung <daniel.leung@intel.com>
The USB configuration option is actually a global switch
to enable USB drivers in general, but currently only
the device controller drivers are meant.
USB device controller drivers also have USB_DEVICE_DRIVER option.
Thus the option USB is actually redundant and can be replaced
by the self-explanatory option USB_DEVICE_DRIVER.
The name USB itself is not unique and should not be used as an
configuration option.
With these changes the option USB_DEVICE_DRIVER generally
enables USB device controller drivers. The option USB_DEVICE_STACK
enables USB device support. It is sufficient to enable only option
USB_DEVICE_STACK because it selects USB_DEVICE_DRIVER.
CONFIG_USB Kconfig option is temporary added to subsys/usb/Kconfig.
This is necessary to pass CI and will be removed again
when the USB configuration has been adapted in modules.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Use macros and types from usb/usb_ch9.h header where it
is possible. This patch also adds local macros, USB_REQTYPE_GET_DIR
and USB_REQTYPE_GET_TYPE, which is an intermediate solution and
these will be removed later.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
This is called in ISR context and timeout must be set
to K_NO_WAIT.
Reported-by: Pieter De Gendt <pieter.degendt@basalte.be>
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
The SoC driver name is 'USB High-Speed Interface (USBHS)'. This rename
from usb_dc_sam to usb_dc_sam_usbhs allowing add others SoC drivers
like 'USB Device Port (UDP)' that is found at SAM4S/E variations.
Signed-off-by: Gerson Fernando Budke <nandojve@gmail.com>
Since we removed various series headers, move stm32 driver
under main driver/pinmux folder.
Take this change into account into various drivers.
Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
Add configurable attached event delay. Delay can be used to give
USB Charging Controller time for initialization.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
To allow transition to device tree based clock configuration on
stm32 targets, rework clock_control driver to use intermediate
STM32_ macros initially defined as the equivalent Kconfig macros
for now.
Propagate the change in all code using these macros.
The reason to introduce these new macros instead of configuring
Kconfig flags using dt kconfigfunctions is that we'll need
to be able to inform users that Kconfig flags are deprecated
once the whole family conversion is done, to encourage
out of tree users to adopt this new configuration scheme.
Note: For now STM32H7 series and code is excluded.
This is the same for some series specific code such as
PLL mul/div for L0/L1 and XTRE prescaler on F1 series.
Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
If a loaded endpoint was disabled and then reconfigured,
it is not possible to start an IN transfer and
usb_dc_ep_write() returns -EAGAIN.
Call ep_ctx_reset() to clear endpoint operations flags
and reset buffer after endpoint is disabled.
Signed-off-by: Johann Fischer <johann.fischer@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>
* Assumes that the USB2_OTG peripheral is being used in FS mode, as on
the NUCLEO-H743/753.
* Disable ULPI on USB2_OTFG, enable FS clk.
* Enable USB voltage detect and disable USB reg, per STM app notes.
Signed-off-by: Jeremy Wood <jeremy@bcdevices.com>
Use ep_idx in usbip_send_common() instead of endpoint address
and get direction from endpoint address.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
USB setup packet is a part of USBIP_CMD_SUBMIT, but missing
in struct usbip_submit. This patch fixes it and removes
usbip_skip_setup() and adds an additional integrity check
in handle_usb_control().
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
The transfer length is not stored and processed properly.
Use struct usb_ep_ctrl_prv, which we already have, to store
the transfer length and data. Move usbip_recv() to
handle_usb_control() and handle_usb_data(),
and explicitly copy USB setup packet.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Call the IN callback only if data in usb_dc_ep_write()
is actually written to the intermediate buffer and sent.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Use pointer to struct usb_ep_ctrl_prv, which allows to remove
a few variables and simplifies subsequent improvements.
Use consistently ep_idx in handle_usb_control() instead of
ntohl(hdr->common.ep).
Revise logging so that it is clearer what event is being processed.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
The comments at the beginning of the file are not quite correct
and instructions regarding configuration are not necessary at all.
Also remove the redundant first line.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Convert from device_get_binding to DEVICE_DT_GET. In doing this we
no longer need the label in the devicetree node so we remove that.
Removed all __ASSERT_NO_MSG(clk) since we'll get a build error if
DEVICE_DT_GET cant be satisfied, and the clock control api's will
handle reporting if the device_is_ready.
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
For historical reasons, the maximum speed of the Atmel SAM USB
controller is done by comparing the maximum-speed property string from
the DT using strncmp at runtime.
Now that the DT_ENUM_IDX macro exists, we can use it to get the
maximum-speed property at build time and without string comparison.
Unsupported speed can also be reported at build time.
Note that the default speed in case the optional maximum-speed property
isn't present in the DT is changed from full-speed to high-speed to
match the property description. This is a no-op in practice as this
properties is defined at the soc level.
Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
The STM32F105xx USB clock goes through a prescaler either PLL1 x2 /2
or PLL1 x2 /3, the output of this must be 48 MHz. As such, the output
of PLL1 must be 48 MHz or 72 MHz.
NOTE: This requires that the system is running from PLL1 (PLLCLK).
Support for running from PLL2 will be implemented in the future.
Signed-off-by: Attie Grande <attie.grande@argentum-systems.co.uk>
Change switches to using static memory for out endpoints. Using
heap is not necessary, because number of out endpoints is defined
in DTS.
Signed-off-by: Marek Pieta <Marek.Pieta@nordicsemi.no>
Use the core k_heap API pervasively within our tree instead of the
z_mem_pool wrapper that provided compatibility with the older mempool
implementation.
Almost all of this is straightforward swapping of one alloc/free call
for another. In a few cases where code was holding onto an old-style
"mem_block" a local compatibility struct with a single field has been
swapped in to keep the invasiveness of the changes down.
Note that not all the relevant changes in this patch have in-tree test
coverage, though I validated that it all builds.
Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
Mark all k_mem_pool APIs deprecated for future code. Remaining
internal usage now uses equivalent "z_mem_pool" symbols instead.
Fixes#24358
Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
Usage of mem_pool for all IN endpoints was removed in
commit b3c63425a0 ("usb: driver: Reduce Endpoint buffer pool.")
Remove also k_mem_pool_free for all IN endpoints.
Fixes: #30213
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
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>
This patch adds setup packet copy in the Nordic device
controller driver (ubs_dc_nrfx.c). This patch is required
for subsequent patch that fixes isssues with ZLP handling.
Signed-off-by: Emil Obalski <emil.obalski@nordicsemi.no>
IN Endpoints does not require to have initialized internal
buffer. The data send are not copied to the internal buffer
anymore. This patch reduces memory usage for IN Endpoints.
Signed-off-by: Emil Obalski <emil.obalski@nordicsemi.no>
Nordic device driver controller (usb_dc_nrfx.c) was fragmenting
IN transfers longer than wMaxPacketSize long using its
internal buffers. Buffers were reserved for each endpoint.
Because the Low level driver (nrfx) is capable of handling
fragmentation, there is no need to do it at the driver
controller level. Data pointer is used directly to create
the nrfx transfer. Endpoint buffers are not required anymore
and could be dropped.
This patch removes fragmentation of in transfers and omits
usage of internal endpoint buffers. Buffer could be later
freed by subsequent patches.
Nordic low level usbd driver is also capable of adding ZLP
if required however for consistance with the Zephyr USB device
stack ZLP must be triggered from stack level.
Signed-off-by: Emil Obalski <emil.obalski@nordicsemi.no>
Endpoint STALL should be cleared when Endpoint is enabled.
In particular when the HOST performs SetInterface requests
and Endpoints associated with that Interface are enabled
STALL should be cleared.
Signed-off-by: Emil Obalski <emil.obalski@nordicsemi.no>
This patch makes the initialization of workqueue earlier
for Nordic driver. Without this change Nordic devices
will fail tests/subsys/usb/device test as it is resetting
USB and by that will try to start already started workqueue
thread. This may lead to Zephyr fatal error.
Signed-off-by: Emil Obalski <emil.obalski@nordicsemi.no>
The initial configuration provided for the nrfx_power driver cannot
contain just default values, as that mean that DC/DC converters are
to be disabled, while those converters may be (and they actually are
by default for many boards) enabled through Kconfig.
Signed-off-by: Andrzej Głąbek <andrzej.glabek@nordicsemi.no>
Isochronous transactions do not support handshake phase
so in particular the ISO endpoint cannot be STALLed.
Isochronous transactions do no support data toggle sequencing
and should only send DATA0 PID.
Taking into consideration those requirements do not try to
clear dtoggle or STALL an ISO Endpoint in nRF USBD driver.
Signed-off-by: Emil Obalski <emil.obalski@nordicsemi.no>
When getting a hfxo manager for USB sybsystem incorrect symbol
was checked. This lead to always enabling HFCLK, even for nRF5340
which needs HFCLK192M.
Signed-off-by: Emil Obalski <emil.obalski@nordicsemi.no>
MCUX EHCI USB device controller supports a specific
number of bidirectional endpoints. Bidirectional means
that an endpoint object is represented to the outside
as an OUT and an IN Eindpoint with its own buffers
and control structures.
ep_abs_idx index refers to the corresponding control
structure, for example:
EP addr | ep_idx | ep_abs_idx
-------------------------------
0x00 | 0x00 | 0x00
0x80 | 0x00 | 0x01
0x01 | 0x01 | 0x02
0x81 | 0x01 | 0x03
.... | .... | ....
The NUM_OF_EP_MAX (and number of s_ep_ctrl) should be double
of num_bidir_endpoints. There is also no need to reserve
endpoint addresses for this controller type.
Signed-off-by: Johann Fischer <j.fischer@phytec.de>
This is a follow-up to commit 701e9befe4.
The NRFX_POWER Kconfig option should be enabled together with USB_NRFX,
not with CLOCK_CONTROL_NRF, as the USB driver is the actual user of
the nrfx POWER driver.
This patch adds also missing initialization of the nrfx POWER driver
and refactors a bit the usb_init() function introduced in the commit
mentioned above, so that it does not redefine the DT_DRV_COMPAT macro
and uses for conditional compilation the same Kconfig option that is
the dependency of NRFX_USBREG.
Signed-off-by: Andrzej Głąbek <andrzej.glabek@nordicsemi.no>
Due to HSEM implementation #24862, USB CLK48 lock implementation
#25850 should be reworked.
And by the way, implement the same in entropy which is using the
same clock.
Signed-off-by: Alexandre Bourdiol <alexandre.bourdiol@st.com>
Now that device_api attribute is unmodified at runtime, as well as all
the other attributes, it is possible to switch all device driver
instance to be constant.
A coccinelle rule is used for this:
@r_const_dev_1
disable optional_qualifier
@
@@
-struct device *
+const struct device *
@r_const_dev_2
disable optional_qualifier
@
@@
-struct device * const
+const struct device *
Fixes#27399
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Removed all nrf_power/USB related stuff from clock control
driver to USB driver.
Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
Short explanation of remote wake up:
The device has a possibility to wake up the HOST by sending
the wake up request. The request must be previously
explicitly enabled by the HOST just before the SUSPEND.
The HOST enables the remote wake up functionality by sending
SET_FEATURE request with remote wake up flag set to 1.
This ususally happens just before the device is suspended.
About this PR:
When the device decides to wake up the HOST it sends proper request.
Nordic USB HW is creating an event when the request has been sent.
The Zephyr USB device stack must proerly react to this event and
change the state of the device from SUSPENDED. For example if the
device was previously in CONFIGURED state it will remain CONFIGURED.
For state changes refer to Chapter 9.1.1 form USB 2.0 specification.
Signed-off-by: Emil Obalski <emil.obalski@nordicsemi.no>
ep_idx is common used designator for endpoint index,
rename ep_num to ep_idx in usb_dc_sam0 driver.
Signed-off-by: Johann Fischer <j.fischer@phytec.de>
The driver was returning zero due to accessing the, say, 0x81'th
endpoint instead of the 0x01'th endpoint.
Signed-off-by: Michael Hope <mlhx@google.com>
The driver currently blindly copies all of the outgoing bytes into the
endpoint. Instead, calculate the endpoint size and copy up to that
amount instead.
Signed-off-by: Michael Hope <mlhx@google.com>
Nordic driver must allow read from control OUT endpoint by
itself. For data stage transactions with length > MPS (64Bytes)
this must be performed for each 64B + Residue data packet.
Residue - data packet with len < 64B.
The exact length of data transfer is known from wLength field
form setup packet in setup stage. Until now driver was incorrectly
initializing the length of the data stage and at some point will
not allow for next data stage.
This commit addresses the issue #23980.
Signed-off-by: Emil Obalski <emil.obalski@nordicsemi.no>
Change adds abort of ongoing write operation in ep_ctx_reset. This is
required to keep the state of Zephyr driver consistent with state of
nrfx driver. This fixes a bug where nrfx_usbd was stuck in busy state.
Signed-off-by: Marek Pieta <Marek.Pieta@nordicsemi.no>
Usually, we want to operate only on "available" device
nodes ("available" means "status is okay and a matching binding is
found"), but that's not true in all cases.
Sometimes we want to operate on special nodes without matching
bindings, such as those describing memory.
To handle the distinction, change various additional devicetree APIs
making it clear that they operate only on available device nodes,
adjusting gen_defines and devicetree.h implementation details
accordingly:
- emit macros for all existing nodes in gen_defines.py, regardless
of status or matching binding
- rename DT_NUM_INST to DT_NUM_INST_STATUS_OKAY
- rename DT_NODE_HAS_COMPAT to DT_NODE_HAS_COMPAT_STATUS_OKAY
- rename DT_INST_FOREACH to DT_INST_FOREACH_STATUS_OKAY
- rename DT_ANY_INST_ON_BUS to DT_ANY_INST_ON_BUS_STATUS_OKAY
- rewrite DT_HAS_NODE_STATUS_OKAY in terms of a new DT_NODE_HAS_STATUS
- resurrect DT_HAS_NODE in the form of DT_NODE_EXISTS
- remove DT_COMPAT_ON_BUS as a public API
- use the new default_prop_types edtlib parameter
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
This commit adds support for receiveing data from ISO OUT endpoint
for NRF devices. NRF USB IP core does not generate IRQ when
data are received on ISO OUT endpoint and it must be synchronized
with SOF event.
Enable SOF handling by default if usb audio is configured
with NRF devices.
Signed-off-by: Emil Obalski <emil.obalski@nordicsemi.no>
By this commit exception for ISO endpoints is made when it comes
to its size. ISO endpoint buffer size for nrf devices is 1023 and
may be configured with variable length size. NRFX checks is size
is chosen accordingly and it is no reason to do it in SHIM.
Signed-off-by: Emil Obalski <emil.obalski@nordicsemi.no>
* Define USB driver for base stm32wb device.
* Enable USB for the nucleo_wb55rg board.
* Properly initialize USB power + clock for the platform.
Signed-off-by: Pete Johanson <peter@peterjohanson.com>
We want to limit DT_ prefix to macros from devicetree.h and generation.
So rename DT_USB* to just USB*.
Also fixup how USB_MAXIMUM_SPEED was defined. We should only define it
if the property exists.
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
Convert driver to use new DT_INST macros throughout. We also remove
defines in dts_fixup.h as they are no longer needed.
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
Convert from using dts_fixup.h based macros to DT_INST macro. This
lets us remove the dependancy on dts_fixup.h for this driver.
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
Convert from using dts_fixup.h based macros to DT_INST macro. This lets
us remove the dependancy on dts_fixup.h for this driver.
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
Convert older DT_INST_ macro use in atmel sam0 drivers to the new
include/devicetree.h DT_INST macro APIs.
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
Convert older DT_INST_ macro use in STM32 drivers to the new
include/devicetree.h DT_INST macro APIs.
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
The new Atmel DFP USBHS component headers provide mode-specific
interrupt register field definitions that replace the generic
definitions (e.g. `USBHS_DEVEPTISR_RXSTPI` for a control endpoint is
now `USBHS_DEVEPTISR_CTRL_RXSTPI`).
This commit updates the Zephyr SAM USBHS driver to use the new
mode-specific interrupt register field definitions.
In addition, it maps the generic definitions to the mode-specific
definitions, as the revision A variant headers (e.g. same70a) in the
latest DFPs, at the time of writing, still provide only the generic
definitions.
Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
Convert usb_stm32 driver to use of DT_INST macros.
Since driver is compatible with 3 different dt compatibles and
compatible string is included in DT_INST macros, I've kept the
DT_USB_ compatible agnostic macros based on DT_INST ones, which
allowed to remove fixup definitions.
Use of DT_USB symbols is now limited to usb_dc_stm32.
Additionally, compatible "st,stm32-otgfs" is removed from list
of compatibles for usbotg_hs ips.
Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
Previously, endpoint configuration would reserve memory in the packet
memory area which would never be reclaimed. After this patch, endpoints
will reuse previously allocated memory when possible. We still leak
memory when reconfiguration increases the max packet size for a given
endpoint number, but this fixes the common case.
Bug: https://github.com/zephyrproject-rtos/zephyr/issues/23178
Signed-off-by: Josh Gao <josh@jmgao.dev>
Rework USB_DeviceNotificationTrigger(). Fix style.
Drop messages from USB_DeviceEhciCancel().
MCUX EHCI driver notifies about canceled transfers,
but there is no specific code for this event in
usb_device_callback_message_struct_t, the only way to
recognize it is to check the length value.
Signed-off-by: Johann Fischer <j.fischer@phytec.de>
Data toggle should be reset after SetConfiguration or
SetInterface request.
Always reset data toggle in usb_dc_ep_enable.
Signed-off-by: Johann Fischer <j.fischer@phytec.de>
USB Host expects dtoggle to be cleared after ClearFeature(Halt):
"[...] clearing the Halt feature via a ClearFeature(ENDPOINT_HALT)
request results in the endpoint no longer returning a STALL.
For endpoints using data toggle, regardless of whether an endpoint
has the Halt feature set, a ClearFeature(ENDPOINT_HALT) request always
results in the data toggle being reinitialized to DATA0."
- Subsection 9.4.5 of usb 2.0 spec (usb_20.pdf)
Signed-off-by: Audun Korneliussen <audun.korneliussen@nordicsemi.no>
On stm32f302/3 series, USB and CAN_1 share same IRQ lines.
To use USB and CAN_1 together, USB IRQ could be remap to other
line numbers, on which there is no conflict.
Remap the USB IRQ lines by default:
-Assign remap number in matching dtsi files
-Perform remap before usb driver init
Additionally, fix compilation issue in usb driver.
Fixes#22343
Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
Signed-off-by: Yannis Damigos <giannis.damigos@gmail.com>
Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
setting/resetting endpoints is required when switching to alternate
interfaces. This is a common operation for usb audio class.
When audio device is enumerated host invokes set_interface request
to alternate with 0 endpoints associated. That operation lead to
disable never enabled endpoints. With previous solution error message
will appear.
This commit limits error messages to be present only if endpoint
was configured/enabled before and there was a problem when trying
to configure/enable it for the first time.
* Kinetis driver was updated with return error value when ep was
already configured/enabled.
* nxp driver updated with return error value when ep was already
enabled
* sam0 driver updated with return codes instead of magic numbers.
This is fix patch to #21741
Signed-off-by: Emil Obalski <emil.obalski@nordicsemi.no>
Lots of style mess in this driver:
- 80 chars limit not followed
- variable allocation and if condition on it should be coalesced
- etc...
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
The build infrastructure should not be adding the drivers subdirectory
to the include path. Fix the legacy uses that depended on that
addition.
Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
The build infrastructure should not be adding the drivers subdirectory
to the include path. Fix the legacy uses that depended on that
addition.
Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
Following update of STM32Cube packages for series F0/L0/F3,
a new file ll_usb.h is now available for these series.
As a consequence, specific hanlding is no more requested for this
series is stm32 usb_device driver.
Fixes#21962
Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
Low frequency and high frequency clocks had separate devices
while they are actually handled by single peripheral with single
interrupt. The split was done probably because opaque subsys
argument in the API was used for other purposes and there was
no way to pass the information which clock should be controlled.
Implementation changes some time ago and subsys parameter was
no longer used. It now can be used to indicate which clock should
be controlled.
Change become necessary when nrf5340 is taken into account where
there are more clocks and current approach would lead to create
multiple devices - mess.
Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
Remove leading/trailing blank lines in .c, .h, .py, .rst, .yml, and
.yaml files.
Will avoid failures with the new CI test in
https://github.com/zephyrproject-rtos/ci-tools/pull/112, though it only
checks changed files.
Move the 'target-notes' target in boards/xtensa/odroid_go/doc/index.rst
to get rid of the trailing blank line there. It was probably misplaced.
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
Newer SoCs like SAME54 provide dedicated registers to store
the USB trim configuration.
Use those registers if they are defined in ASF to access the
calibration data.
Signed-off-by: Benjamin Valentin <benpicco@googlemail.com>
On newer sam0 SoCs peripherals are enabled through the MCLK
instead of the PM register.
Use the MCLK register if it's availiable.
Signed-off-by: Benjamin Valentin <benpicco@googlemail.com>
Newer SoCs like SAME54 have multiple IRQs for the USB peripheral.
Automatically enable all IRQs configured in the DTS.
Signed-off-by: Benjamin Valentin <benpicco@googlemail.com>
Some of defines are present in several header files.
Those defines are the same with value but with different naming.
Common defines are brought to usb_common.h
Signed-off-by: Emil Obalski <emil.obalski@nordicsemi.no>
Previously, if a control transfer had data, it would be unhandled and
left in the usbip socket to be interpreted as the next usbip packet,
leading to explosions.
Signed-off-by: Josh Gao <josh@jmgao.dev>
When both buffer and max data to read are zero return
the available data in buffer.
Fixes#20838
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
By adding new SoC to Zephyr drivers has to be updated.
Commit affects:
- USB driver
- support for nRF52833 added.
- support for USB_DEVICE_REMOTE_WAKEUP in hid-mouse added.
- SPI
- IEEE 802.15.4
- CLOCK CONTROL
Signed-off-by: Emil Obalski <emil.obalski@nordicsemi.no>
Update calls to nrfx HAL functions to reflect API changes introduced in
nrfx 2.0.0. All these functions are now called with the first parameter
pointing to the structure of registers of the relevant peripheral.
Also a few functions got renamed:
- nrf_gpiote_int_is_enabled to nrf_gpiote_int_enable_check
- nrf_gpiote_event_is_set to nrf_gpiote_event_check
- nrf_rng_event_get to nrf_rng_event_check
- nrf_rng_int_get to nrf_rng_int_enable_check
- nrf_rtc_event_pending to nrf_rtc_event_check
- nrf_rtc_int_is_enabled to nrf_rtc_int_enable_check
- nrf_timer_cc_read to nrf_timer_cc_get
- nrf_timer_cc_write to nrf_timer_cc_set
Default configuration values were removed from nrfx_config files,
so the drivers pwm_nrfx and spi_nrfx_spis no longer can use those.
Function nrfx_pwm_init() now takes one more parameter - context pointer
that is passed to the event handler, not used in the pwm_nrfx driver.
HALs for UART and UARTE now allow configuration of the parity type
and the number of stop bits, for SoCs that provide the corresponding
registers.
Signed-off-by: Karol Lasończyk <karol.lasonczyk@nordicsemi.no>
Signed-off-by: Andrzej Głąbek <andrzej.glabek@nordicsemi.no>
Use this short header style in all Kconfig files:
# <description>
# <copyright>
# <license>
...
Also change all <description>s from
# Kconfig[.extension] - Foo-related options
to just
# Foo-related options
It's clear enough that it's about Kconfig.
The <description> cleanup was done with this command, along with some
manual cleanup (big letter at the start, etc.)
git ls-files '*Kconfig*' | \
xargs sed -i -E '1 s/#\s*Kconfig[\w.-]*\s*-\s*/# /'
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
Re-run with updated script to convert integer literal delay arguments to
k_sleep to use the standard timeout macros.
Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
Use the int_literal_to_timeout Coccinelle script to convert literal
integer arguments for kernel API timeout parameters to the standard
timeout value representations.
Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
'enable-pin-remap' is defined as 'type: boolean' in
dts/bindings/usb/st,stm32-usb.yaml, so it generates either
#define DT_USB_ENABLE_PIN_REMAP 1
or
#define DT_USB_ENABLE_PIN_REMAP 0
depending on if 'enable-pin-remap;' appears on the node or not.
Since a macro is always generated, #ifdef won't work. The test needs to
be this instead:
#if DT_USB_ENABLE_PIN_REMAP == 1
(Should be careful with '#if HMZ == 0' though, because it's true even if
HMZ is undefined.)
This behavior was inherited from the old scripts, and some things depend
on it, e.g. by expanding macros in initializers.
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>