Commit graph

582 commits

Author SHA1 Message Date
Johann Fischer 26f2e33227 drivers: usb_dc_nrfx: add attached event delay
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>
2021-04-29 09:55:28 -04:00
Erwan Gouriou 2691541ad2 drivers/clock_controller: stm32: Prepare for dts based configuration
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>
2021-04-27 11:53:37 +02:00
Johann Fischer 583334b606 drivers: usb_dc_nrfx: clear endpoint flags during ep_disable()
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>
2021-04-20 15:04:47 +02:00
Peter Bigot 2ac596b91a usb: conversion of k_work API
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>
2021-04-15 12:29:34 -04:00
Jeremy Wood 5164d65269 drivers: usb: device: Add support for USB FS on STM32H7.
* 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>
2021-03-29 13:42:46 -04:00
Johann Fischer 63ca48a7a9 drivers: usb_dc_native_posix: use ep_dir and ep_idx in usbip_send_common
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>
2021-03-24 15:02:49 +01:00
Johann Fischer 735ba17cad drivers: usb_dc_native_posix: read setup packet as part of submit struct
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>
2021-03-24 15:02:49 +01:00
Johann Fischer 6c214f796e drivers: usb_dc_native_posix: rework how OUT endpoint data is passed
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>
2021-03-24 15:02:49 +01:00
Johann Fischer 77c2c1230b drivers: usb_dc_native_posix: do not use IN callback without reason
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>
2021-03-24 15:02:49 +01:00
Johann Fischer 16cd3be690 drivers: usb_dc_native_posix: rework handle_usb_control/handle_usb_data
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>
2021-03-24 15:02:49 +01:00
Johann Fischer 627c04f962 drivers: usb_dc_stm32: remove confusing comments
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>
2021-02-24 12:01:50 +01:00
Kumar Gala b275fec8c4 soc: stm32: convert to use DEVICE_DT_GET for clocks
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>
2021-02-16 17:01:37 -06:00
Jacob Siverskog 6e0ef1cdd9 drivers: usb: stm32: fix potential null pointer dereference
perform null pointer check before dereferencing.

Signed-off-by: Jacob Siverskog <jacob@teenage.engineering>
2021-02-16 15:27:59 +03:00
Aurelien Jarno 35adb6e2c4 drivers: usb_dc_sam: get the maximum speed from DT as enum
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>
2021-01-10 18:11:37 -05:00
Attie Grande 78627a5feb usb: stm32: added support for USB Device mode on STM32F105xx parts
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>
2021-01-10 12:42:40 -05:00
Marek Pieta f5a38cb5be drivers: usb_dc_nrfx: Use mem_slab for fifo elements
mem_slab can be used instead of heap, because all allocated
elements have the same size.

Signed-off-by: Marek Pieta <Marek.Pieta@nordicsemi.no>
2021-01-04 16:26:02 +01:00
Marek Pieta 5dbca81f1a drivers: usb_dc_nrfx: Use static memory for out endpoints
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>
2021-01-04 16:26:02 +01:00
Andy Ross fcd392f6ce kernel: subsys: lib: drivers: Use k_heap instead of z_mem_pool wrappers
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>
2020-12-07 21:50:14 -05:00
Andy Ross 6965cf526d kernel: Deprecate k_mem_pool APIs
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>
2020-12-07 21:50:14 -05:00
Martin Jäger 0636b42c81 drivers: usb: stm32: use generic LL headers
Use generic LL headers instead of depending on soc.h.

Signed-off-by: Martin Jäger <martin@libre.solar>
2020-11-30 15:50:03 +01:00
Johann Fischer 5cd66c69c6 drivers: usb_dc_nrfx: remove k_mem_pool_free for IN endpoints
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>
2020-11-25 14:23:48 +02:00
Emil Obalski 773f02e6e9 usb: drivers: Fix ZLP handling for Nordic driver.
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>
2020-11-17 18:06:26 +01:00
Emil Obalski 2eb2bc325e usb: drivers: Save setup packet in the driver structure.
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>
2020-11-17 18:06:26 +01:00
Emil Obalski b3c63425a0 usb: driver: Reduce Endpoint buffer pool.
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>
2020-11-17 18:06:26 +01:00
Emil Obalski 8dacb99e5e usb: drivers: Do not fragment IN transfers for Nordic.
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>
2020-11-17 18:06:26 +01:00
Emil Obalski 1ebe1573da usb: nordic: Clear STALL when Endpoint is enabled.
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>
2020-11-12 08:59:08 -06:00
Emil Obalski 33fdaac74d drivers: usb: Start Nordic driver workqueue at USB init.
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>
2020-10-28 17:02:22 +01:00
Erwan Gouriou a1cb59398b drivers/usb: stm32: Add support for pinctrl configuration
Enable configuration of USB signals in stm32 driver.

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2020-10-22 10:34:14 -05:00
Erwan Gouriou 5a9eff1e1a drivers/usb: stm32: Clean up related to DT api usage
Few adjustments made to make the code a bit more readable.

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2020-10-22 10:34:14 -05:00
Andrzej Głąbek a97611a399 drivers: usb_dc_nrfx: Correct the nrfx_power driver configuration
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>
2020-10-22 14:08:13 +02:00
Emil Obalski dc79b37167 usb: nrf: Do not allow to clear STALL or dtoggle for ISO ep.
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>
2020-09-15 10:15:20 +02:00
Emil Obalski 613726728f usb: clock_control: Fix symbol when getting mgr for HFCLK
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>
2020-09-07 16:47:02 +02:00
Johann Fischer 362d8b27a7 drivers: usb_dc_mcux_ehci: fix endpoints index assignment
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>
2020-09-05 10:49:37 -05:00
Krzysztof Chruscinski 8f2754e027 drivers: usb: device: nrf: Add support for hf192m clock
Added support for nrf53 where hf192m clock must be used.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2020-09-04 16:36:05 +02:00
Andrzej Głąbek 460a97d378 drivers: usb_dc_nrfx: Enable and properly initialize nrfx POWER driver
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>
2020-09-03 21:52:52 +02:00
Alexandre Bourdiol 5deb8ffe0c drivers: STM32: Rework CLK48 HSEM protection
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>
2020-09-02 14:13:49 +02:00
Tomasz Bursztyka 4dcfb5531c isr: Normalize usage of device instance through ISR
The goal of this patch is to replace the 'void *' parameter by 'struct
device *' if they use such variable or just 'const void *' on all
relevant ISRs

This will avoid not-so-nice const qualifier tweaks when device instances
will be constant.

Note that only the ISR passed to IRQ_CONNECT are of interest here.

In order to do so, the script fix_isr.py below is necessary:

from pathlib import Path
import subprocess
import pickle
import mmap
import sys
import re
import os

cocci_template = """
@r_fix_isr_0
@
type ret_type;
identifier P;
identifier D;
@@
-ret_type <!fn!>(void *P)
+ret_type <!fn!>(const struct device *P)
{
 ...
(
 const struct device *D = (const struct device *)P;
|
 const struct device *D = P;
)
 ...
}

@r_fix_isr_1
@
type ret_type;
identifier P;
identifier D;
@@
-ret_type <!fn!>(void *P)
+ret_type <!fn!>(const struct device *P)
{
 ...
 const struct device *D;
 ...
(
 D = (const struct device *)P;
|
 D = P;
)
 ...
}

@r_fix_isr_2
@
type ret_type;
identifier A;
@@
-ret_type <!fn!>(void *A)
+ret_type <!fn!>(const void *A)
{
 ...
}

@r_fix_isr_3
@
const struct device *D;
@@
-<!fn!>((void *)D);
+<!fn!>(D);

@r_fix_isr_4
@
type ret_type;
identifier D;
identifier P;
@@
-ret_type <!fn!>(const struct device *P)
+ret_type <!fn!>(const struct device *D)
{
 ...
(
-const struct device *D = (const struct device *)P;
|
-const struct device *D = P;
)
 ...
}

@r_fix_isr_5
@
type ret_type;
identifier D;
identifier P;
@@
-ret_type <!fn!>(const struct device *P)
+ret_type <!fn!>(const struct device *D)
{
 ...
-const struct device *D;
...
(
-D = (const struct device *)P;
|
-D = P;
)
 ...
}
"""

def find_isr(fn):
    db = []
    data = None
    start = 0

    try:
        with open(fn, 'r+') as f:
            data = str(mmap.mmap(f.fileno(), 0).read())
    except Exception as e:
        return db

    while True:
        isr = ""
        irq = data.find('IRQ_CONNECT', start)
        while irq > -1:
            p = 1
            arg = 1
            p_o = data.find('(', irq)
            if p_o < 0:
                irq = -1
                break;

            pos = p_o + 1

            while p > 0:
                if data[pos] == ')':
                    p -= 1
                elif data[pos] == '(':
                    p += 1
                elif data[pos] == ',' and p == 1:
                    arg += 1

                if arg == 3:
                    isr += data[pos]

                pos += 1

            isr = isr.strip(',\\n\\t ')
            if isr not in db and len(isr) > 0:
                db.append(isr)

            start = pos
            break

        if irq < 0:
            break

    return db

def patch_isr(fn, isr_list):
    if len(isr_list) <= 0:
        return

    for isr in isr_list:
        tmplt = cocci_template.replace('<!fn!>', isr)
        with open('/tmp/isr_fix.cocci', 'w') as f:
            f.write(tmplt)

        cmd = ['spatch', '--sp-file', '/tmp/isr_fix.cocci', '--in-place', fn]

        subprocess.run(cmd)

def process_files(path):
    if path.is_file() and path.suffix in ['.h', '.c']:
        p = str(path.parent) + '/' + path.name
        isr_list = find_isr(p)
        patch_isr(p, isr_list)
    elif path.is_dir():
        for p in path.iterdir():
            process_files(p)

if len(sys.argv) < 2:
    print("You need to provide a dir/file path")
    sys.exit(1)

process_files(Path(sys.argv[1]))

And is run: ./fix_isr.py <zephyr root directory>

Finally, some files needed manual fixes such.

Fixes #27399

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2020-09-02 13:48:13 +02:00
Tomasz Bursztyka e18fcbba5a device: Const-ify all device driver instance pointers
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>
2020-09-02 13:48:13 +02:00
Krzysztof Chruscinski 701e9befe4 drivers: clock_control: nrf: Move USB part to the USB driver
Removed all nrf_power/USB related stuff from clock control
driver to USB driver.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2020-08-31 12:40:47 +02:00
Emil Obalski 0042e1e95f usb: nrf: Fix for remote wake up request.
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>
2020-08-17 13:41:35 -04:00
Andrew Boie 7d920ba39b drivers: use K_KERNEL_STACK macros
None of these threads run in user mode and we can save some
memory.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-08-04 12:16:43 -04:00
Krzysztof Chruscinski 9e546fdf7e drivers: usb: device: nrf: Adapt to control clock using onoff
Change to use onoff service when controlling HFXO.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2020-07-20 16:22:21 +02:00
Johann Fischer 6d76bd8a9f drivers: usb_dc_sam0: rename ep_num to common ep_idx
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>
2020-07-10 11:45:46 +02:00
Johann Fischer b95558dd9f drivers: usb: unify endpoint helper macros
Unify endpoint index and direction helper macros
across all usb device drivers.

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2020-07-10 11:45:46 +02:00
Michael Hope dcf64c93e3 drivers: usb: switch the SAM0 driver from a custom allocator to the heap
Also automatically enable the heap if the USB device is selected.

Part of #23178

Signed-off-by: Michael Hope <mlhx@google.com>
2020-07-06 09:58:20 -04:00
Michael Hope ad7ea0d498 drivers: usb: fix usb_dc_ep_mps() for the SAM0 for IN endpoints
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>
2020-06-24 21:00:59 +02:00
Michael Hope 18d3499dba drivers: usb: fix a buffer overflow in usb_sam0.c
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>
2020-06-15 16:56:05 +02:00
Michael Hope fe35269d12 drivers: usb: handle a null output arg on SAM0
The output parameter `ret_bytes` is optional and may be NULL.

Signed-off-by: Michael Hope <mlhx@google.com>
2020-06-15 16:55:52 +02:00
Kumar Gala a1b77fd589 zephyr: replace zephyr integer types with C99 types
git grep -l 'u\(8\|16\|32\|64\)_t' | \
		xargs sed -i "s/u\(8\|16\|32\|64\)_t/uint\1_t/g"
	git grep -l 's\(8\|16\|32\|64\)_t' | \
		xargs sed -i "s/s\(8\|16\|32\|64\)_t/int\1_t/g"

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-06-08 08:23:57 -05:00
Pete Johanson f525a4b25a usb: stm32wb: Properly lock Sem5 before initializing USB.
* AN5289 notes that Sem5 should be held before configuring
  CLK48 for USB timing.

Signed-off-by: Pete Johanson <peter@peterjohanson.com>
2020-06-02 20:11:30 +02:00
Emil Obalski 19f6ed02b8 usb: driver: Fix Nordic driver for fragmented control OUT transfers.
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>
2020-05-22 12:50:35 +02:00
Emil Obalski 2a2d92f9c2 usb: driver: nordic: Unlock mutex in case of error.
Mutex that was previously locked must be unlocked in case
of an error.

Signed-off-by: Emil Obalski <emil.obalski@nordicsemi.no>
2020-05-21 11:02:02 +02:00
Marek Pieta 6da15634bf drivers: usb_dc_nrfx: Abort write on ep_ctx_reset
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>
2020-05-14 13:28:46 +02:00
Johann Fischer 5a3d44256e drivers: usb_dc_sam: free endpoint memory on End of Reset event
Free endpoint memory on End of Reset event (EORST).

Fixes: #24626

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2020-05-13 11:13:36 +02:00
Johann Fischer 29d95ba1d4 drivers: usb_dc_sam: tweak logging for enable, disable, configure
Tweak logging for enable, disable, configure.

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2020-05-13 11:13:36 +02:00
Martí Bolívar 7e0eed9235 devicetree: allow access to all nodes
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>
2020-05-08 19:37:18 -05:00
Emil Obalski 38aea280e7 usb: Sync receiving data from ISO OUT endpoint with SOF
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>
2020-05-08 15:12:27 +02:00
Emil Obalski 9e998d108a drivers: usb: Correct naming for endpoint Transfer Type
This commit updates definitions to better match usb 2.0 spec.

Signed-off-by: Emil Obalski <emil.obalski@nordicsemi.no>
2020-05-08 15:12:27 +02:00
Emil Obalski 79704fac5a usb: ISO endpoint size may not be power of 2.
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>
2020-05-08 15:12:27 +02:00
Pete Johanson 91d6139338 boards: arm: nucleo_wb55rg: Enable USB for stm32wb.
* 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>
2020-05-06 10:46:23 -05:00
Kumar Gala 1ce133d0fe drivers: usb: usb_dc_stm32: Rename defines to remove DT_ prefix
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>
2020-05-01 07:49:00 -05:00
Kumar Gala 085747e5fb drivers: usb: usb_dc_sam: Convert to DT_INST macros
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>
2020-04-23 06:10:07 -05:00
Kumar Gala 22a41e4eb7 drivers: usb: usb_dc_stm32: Convert DT_COMPAT_ define usage to new macros
Convert driver from using DT_COMPAT_ST_STM32_* to new macro
DT_HAS_COMPAT(st_stm32_*).

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-04-23 05:58:17 -05:00
Martí Bolívar 18c9c8cf27 drivers: usb_dc_nrfx: move to new DT API
Close out the existing partial conversion to the new DT API.

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2020-04-21 13:34:22 -05:00
Kumar Gala af5515e2e0 drivers: usb: device: kinetis: Convert driver to DT_INST macro
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>
2020-04-20 15:40:44 +02:00
Kumar Gala 1d605684ce drivers: usb: device: mcux_ehci: Convert driver to DT_INST macro
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>
2020-04-17 11:27:30 -05:00
Kumar Gala 8b56e7a63c drivers: usb_dc_nrfx: Convert driver to new DT_INST macros
Convert to using DT_LABEL(DT_INST()) to get label of the
nordic,nrf-clock device.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-04-14 10:37:34 -05:00
Kumar Gala e6e5d868e1 drivers: usb: usb_dw: Convert to new DT_INST macros
Convert older DT_INST_ macro use the new include/devicetree.h
DT_INST macro APIs.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-03-30 08:29:30 -05:00
Kumar Gala 28870e7a32 drivers: atmel sam0: Convert atmel sam0 drivers to new DT_INST macros
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>
2020-03-27 11:02:57 -05:00
Kumar Gala 989484b4bf drivers: stm32: Convert STM32 drivers to new DT_INST macros
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>
2020-03-26 12:22:12 -05:00
Stephanos Ioannidis c4479d0643 drivers: usb_dc_sam: Use mode-specific interrupt register fields
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>
2020-03-26 09:23:48 -05:00
Erwan Gouriou 9367c6ad3f drivers/usb: usb_dc_stm32: Convert to DT_INST
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>
2020-03-17 11:03:10 -06:00
Kumar Gala 0c7a5fdf1c drivers: usb: usb_dw: convert to DT_INST defines
Convert driver to use DT_INST_ defines.  The preferred defines for
drivers are DT_INST_.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-03-11 07:59:38 -06:00
Josh Gao b9d2028590 usb_dc_stm32: improve struct layout.
Put the one-byte sized fields next to each other to reduce padding.

Signed-off-by: Josh Gao <josh@jmgao.dev>
2020-03-10 18:32:47 +02:00
Josh Gao c4a7d96c04 usb_dc_stm32: reuse PMA buffer when possible.
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>
2020-03-10 18:32:47 +02:00
Johann Fischer 085e58faf8 drivers: usb_dc_mcux_ehci: re-enable reception after clear stall
Re-enable reception after clear an endpoint stall.

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2020-03-10 16:04:50 +01:00
Johann Fischer e0b2227c39 drivers: usb_dc_mcux_ehci: add checks for valid endpoint
Add checks for valid endpoint.
Fix controllerHandle check in usb_dc_detach().

Fixes: #19763

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2020-03-10 16:04:50 +01:00
Johann Fischer e9a35dd6f1 drivers: usb_dc_mcux_ehci: rework USB_DeviceNotificationTrigger()
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>
2020-03-10 16:04:50 +01:00
Johann Fischer c2d45640c2 drivers: usb_dc_mcux_ehci: rework ep_write/ep_read
Rework ep_write/ep_read. Fix style.

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2020-03-10 16:04:50 +01:00
Johann Fischer 0958667125 drivers: usb_dc_mcux_ehci: rework endpoint enable/disable
Rework endpoint enable/disable. Fix style.

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2020-03-10 16:04:50 +01:00
Johann Fischer 031d744b9a drivers: usb_dc_mcux_ehci: rework set/clear stall
Rework set/clear stall. Fix style.

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2020-03-10 16:04:50 +01:00
Johann Fischer 4bbd5ae438 drivers: usb_dc_mcux_ehci: do not reconfigure active endpoint
Do not reconfigure active endpoint. Fix style.

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2020-03-10 16:04:50 +01:00
Johann Fischer adf8cfdf3f drivers: usb_dc_mcux_ehci: fix style, rework usb_dc_detach()
Fix style, rework usb_dc_detach().

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2020-03-10 16:04:50 +01:00
Johann Fischer 6116a0388b drivers: usb_dc_mcux_ehci: fix style, rework usb_dc_attach
Fix style, rework usb_dc_attach.

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2020-03-10 16:04:50 +01:00
Johann Fischer a6207db0f7 drivers: usb_dc_mcux_ehci: remove unnecessary cast
Remove unnecessary cast, fix style.

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2020-03-10 16:04:50 +01:00
Johann Fischer b04715b3b9 drivers: usb_dc_mcux_ehci: fix style, variables name
Fix style, variables name, defines.

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2020-03-10 16:04:50 +01:00
Johann Fischer 4253280525 drivers: usb_dc_nrfx: always reset data toggle in usb_dc_ep_enable
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>
2020-03-10 14:54:29 +02:00
Audun Korneliussen 388c6ea01f drivers: usb_dc_nrfx: Reset dtoggle when stall is cleared
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>
2020-03-10 14:54:29 +02:00
Erwan Gouriou 557d263354 dts: stm32f3: Remap USB IRQ to avoid conflict with CAN
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>
2020-02-18 18:44:42 +02:00
Emil Obalski 3ed9dc3a24 usb: Fix for set/reset endpoints
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>
2020-02-12 14:40:40 +02:00
Yannis Damigos ee351328a4 usb_dc_stm32: Convert usb disconnect gpio to new gpio api
Convert usb disconnect gpio to new gpio api.
Updates device tree for the olimexino_stm32.

Signed-off-by: Yannis Damigos <giannis.damigos@gmail.com>
2020-02-05 12:00:36 +01:00
Gerson Fernando Budke 17ccd9ee1b drivers: usb: sam: Add support to samv71 soc
Add depends on SOC_SERIES_SAMV71 to enable usb driver for samv71 soc.

Signed-off-by: Gerson Fernando Budke <nandojve@gmail.com>
2020-02-04 14:02:59 -05:00
Anas Nashif 0358d707b0 usb: dw: fix undefined callback variable
Add missing declaration of variables for callbacks.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2020-01-31 14:51:37 -05:00
Tomasz Bursztyka b8e14b5b9d drivers/usb: Switching to DTS based configuration for DW driver
And applying the changes to intel_s1000_crb board as well.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2020-01-28 18:18:18 -05:00
Tomasz Bursztyka 2161c91f0b drivers/usb: Fixing style issues in DW driver
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>
2020-01-28 18:18:18 -05:00
Peter Bigot 84497d0e49 treewide: use full path to usb/usb_dc.h header
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>
2020-01-26 17:52:12 +01:00
Peter Bigot 0b0d2e640b treewide: use full path to clock_control/stm32_clock_control.h header
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>
2020-01-26 17:52:12 +01:00
Erwan Gouriou 136d92de33 drivers/usb/device: stm32: Update due to API change on F0/F3/L0
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>
2020-01-16 10:09:58 -05:00
Krzysztof Chruscinski 00156ad80a drivers: clock_control: nrf: Switch to single clock device
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>
2019-12-17 14:38:19 +01:00
Ulf Magnusson 984bfae831 global: Remove leading/trailing blank lines in files
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>
2019-12-11 19:17:27 +01:00
Benjamin Valentin 2ffb8dd9f1 usb: sam0: use TRIM registers when available
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>
2019-12-11 11:13:24 +01:00
Benjamin Valentin e0b94e92d5 usb: sam0: Add support for MCLK
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>
2019-12-11 11:13:24 +01:00
Benjamin Valentin 2ff38cc631 usb: sam0: Support more then one USB IRQ
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>
2019-12-11 11:13:24 +01:00
Johann Fischer 9a7a1b0132 drivers: usb_dc_nrfx: remove not relevant bashing comments
Remove not relevant bashing comments.

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2019-12-11 11:10:01 +01:00
Johann Fischer b22035de45 drivers: usb_dc_nrfx: free memory if event is intended to be dropped
Free memory block if event is intended to be dropped.

Resolves: #20953

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2019-12-11 11:10:01 +01:00
Emil Obalski c1f5e11bb6 usb: Cleanup for multiplied defines
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>
2019-12-09 12:48:13 -05:00
Josh Gao 2717b28b0f usb: usb_dc_native_posix: fix control transfers with data.
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>
2019-12-09 16:08:27 +01:00
Andrei Emeltchenko 105e0997f2 usb: usb_dc_native_posix: Refactor similar code to function
Use skip_setup() function helper in a place we need to skip setup
data.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2019-11-29 07:54:14 -05:00
Andrei Emeltchenko 0957f4978c usb: usb_dc_native_posix: Use return code for skip_setup()
Use return code for usbip_skip_setup()

Fixes #20840

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2019-11-29 07:54:14 -05:00
Andrei Emeltchenko 80dbcfa306 usb: usb_dc_native_posix: Check return code in handle_usb_data()
Fixes coverity complaints dealing with send()

Fixes #20839
Fixes #20841

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2019-11-29 07:54:14 -05:00
Andrei Emeltchenko 1d81c0cf31 usb: usb_dc_native_posix: Fix buffer and max data 0 case
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>
2019-11-29 07:54:14 -05:00
Andrei Emeltchenko 5b22c88184 usb: usb_dc_native_posix: Check return values in dc_write()
Fixes coverity issue:

Fixes #20836
Fixes #20837

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2019-11-29 07:54:14 -05:00
Andrei Emeltchenko 959b833f91 usb: usb_dc_native_posix_adapt: Check correct size
Fixes Coverity issues

Fixes #20842

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2019-11-29 07:54:14 -05:00
Johann Fischer d4ba8fff66 drivers: usb_dc_stm32: do not restrict out stage transfers to one MPS
Do not restrict control out stage transfers to one MPS.

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2019-11-21 11:33:41 +01:00
Emil Obalski 6c82c80a3c drivers: Add support for nRF52833 in several drivers
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>
2019-11-13 10:33:38 -06:00
Andrzej Głąbek b1d5eed262 drivers: nrfx: Update implementations after switching to nrfx 2.0.0
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>
2019-11-08 14:54:12 +01:00
Ulf Magnusson bd6e04411e kconfig: Clean up header comments and make them consistent
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>
2019-11-04 17:31:27 -05:00
Peter Bigot 6e5db350b2 coccinelle: standardize k_sleep calls with integer timeouts
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>
2019-10-09 08:38:10 -04:00
Richard Osterloh 37514ae660 drivers: usb: Add STM32G4X USB support
Add USB driver support for STM32G4X SoC series.

Signed-off-by: Richard Osterloh <richard.osterloh@gmail.com>
2019-10-04 18:44:24 -07:00
Krzysztof Chruscinski 43af941131 drivers: Align nrf counter, timer and usb driver to new clock_control
Align drivers to use new clock control API.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2019-10-04 17:15:39 +02:00
Peter Bigot ab91eef23b coccinelle: standardize kernel API timeout arguments
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>
2019-10-03 11:55:44 -07:00
Johann Fischer 51f550cd07 usb: allow hardware to handle ZLP for Variable-length Data Stage
Allow hardware to handle ZLP for Variable-length Data Stage.

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2019-09-26 13:19:02 +02:00
Ulf Magnusson e833fafd4b drivers: usb: stm32: Fix broken DT_USB_ENABLE_PIN_REMAP test
'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>
2019-09-24 09:36:31 -07:00
Anas Nashif d7f2055dd7 usb: remove QMSI include
No users of this after dropping quark platforms.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-09-18 11:06:18 -05:00
Erwan Gouriou b42ad680c5 dts/Kconfig: Remove symbol HAS_DTC_USB
Symbol not used, so clean it up.

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2019-09-12 08:16:42 -05:00
Johann Fischer e16217aa06 drivers: usb_dc_sam: validate pointer in usb_dc_ep_is_stalled
Validate pointer argument in usb_dc_ep_is_stalled.

Fixes: #18824

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2019-09-08 12:35:23 +02:00
Anas Nashif 578ae40761 boards: remove quarl_se_c1000
This board and SoC was discontinued some time ago and is currently not
maintained in the zephyr tree.
Remove all associated configurations and variants from the tree.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-07-29 21:30:25 -07:00
Andrzej Głąbek f69e194ece drivers: usb_dc_nrfx: Use dedicated work queue for handling ISR events
This patch introduces a dedicated work queue for handling the events
from ISR (i.e. for notifying the USB device stack, for executing the
enpoints callbacks, etc.). The system work queue cannot be used for
this purpose as it might be used in applications for scheduling USB
transfers and this could lead to a deadlock when the USB device stack
would not be notified about certain event because of a system work
queue item waiting for a USB transfer to be finished.

The FIFO named so far `work_queue` is renamed to `usbd_evt_fifo`
to better indicate its purpose and to avoid confusion.

Signed-off-by: Andrzej Głąbek <andrzej.glabek@nordicsemi.no>
2019-07-22 18:19:33 +02:00
Francois Ramu 474c99c9ef drivers: usb/stm32: use dts information to populate clock settings
This patch populates "clocks" property in stm32 usb nodes
for clock related usb configuration code of each  dtsi files

Signed-off-by: Francois Ramu <francois.ramu@st.com>
2019-07-16 09:08:51 -04:00
Johann Fischer 1e9a53e548 drivers: usb_dc_nrfx: make macros names less confusing
Rename EP_BUF_* to EP_BUF_POOL*.
Rename MAX_*EP_BUF_SZ to *EP_BUF_MAX_SZ.

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2019-07-05 08:31:38 -04:00
Johann Fischer 7f118be601 drivers: usb_dc_nrfx: remove unused EPSTATUS defines
Remove unused EPSTATUS defines.

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2019-07-05 08:31:38 -04:00
Johann Fischer 6904a86835 drivers: usb_dc_nrfx: cleanup USB_NRFX_EVT_QUEUE_SIZE
Cleanup around USB_NRFX_EVT_QUEUE_SIZE option.
Add value range for USB_NRFX_EVT_QUEUE_SIZE to Kconfig.

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2019-07-05 08:31:38 -04:00
Johann Fischer 226a429c97 drivers: usb_dc_nrfx: fix style issues
Fix style issue reported by checkpatch.

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2019-07-05 08:31:38 -04:00
Johann Fischer 04b91579ae drivers: usb_dc_nrfx: use REQTYPE_GET_DIR and REQTYPE_GET_TYPE macros
Use REQTYPE_GET_DIR and REQTYPE_GET_TYPE macros from
USB subsystem instead of specially introduced.

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2019-07-05 08:31:38 -04:00
Johann Fischer eb57607c7d drivers: usb_dc_nrfx: validate pointer in usb_dc_ep_is_stalled
Validate pointer argument in usb_dc_ep_is_stalled.

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2019-07-04 21:36:07 +02:00
Johann Fischer cb37505976 drivers: usb_dc_nrfx: check the device state before disable or uninit
Check the device state before nrfx_usbd_disable and
nrfx_usbd_uninit. Otherwise it may lead to an ASSERT
inside the HAL driver.

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2019-07-04 21:36:07 +02:00
Johann Fischer 38cc23a7d9 drivers: usb_dc_nrfx: do not use NRF_USBD_EP_NR_GET in ep_is_valid
Do not use NRF_USBD_EP_NR_GET in ep_is_valid because
it masks the higher nibble. Although this behavior is valid
to get an index from an endpoint, it is not suitable to check
if the address is incorrect, such as: 0x11.

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2019-07-04 21:36:07 +02:00
Yannis Damigos 2d537f49a9 usb_dc_stm32: Don't update ret_bytes if send fails in usb_dc_ep_write()
Don't update ret_bytes if send fails in usb_dc_ep_write().

Signed-off-by: Yannis Damigos <giannis.damigos@gmail.com>
2019-07-02 19:05:37 -04:00
Erwan Gouriou 6b40394df9 drivers/usb/device: stm32: Remove reference to unsupported low speed
Low speed isn't supported in device mode for any of the STM32
references.
Remove the code that refer to it.

Fixes #17114

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2019-06-28 06:16:10 -04:00
Anas Nashif a2fd7d70ec cleanup: include/: move misc/util.h to sys/util.h
move misc/util.h to sys/util.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif 5d001f3e41 cleanup: include/: move misc/byteorder.h to sys/byteorder.h
move misc/byteorder.h to sys/byteorder.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif 6aa9c3a68f cleanup: include/: move gpio.h to drivers/gpio.h
move gpio.h to drivers/gpio.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif 17ddd1714c cleanup: include/: move clock_control.h to drivers/clock_control.h
move clock_control.h to drivers/clock_control.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Andrzej Głąbek 6e75d644de drivers: usb_dc_nrfx: Add pre-transfer checks if endpoint is enabled
The shim didn't check if a given endpoint was enabled before requesting
the nrfx_usbd driver to perform a read or write operation on it.
In certain circumstances this led to nrfx_usbd driver being stuck in
a loop waiting for the associated DMA transfer to complete.

Signed-off-by: Andrzej Głąbek <andrzej.glabek@nordicsemi.no>
2019-06-27 12:17:45 +02:00
Andrzej Głąbek 1b3514a07e Revert "drivers: usb: usb_dc_nrfx: Set cfg.en to false on Reset"
This reverts commit 03ef375f5f.

The cfg.en flag contains only the state of the endpoint as seen by the
shim. It is mainly used to enable the endpoints when the USB peripheral
becomes ready for operation (and the USB stack may want to enable some
endpoints earlier, especially the control ones, so the operation must
be sometimes deferred). In particular, setting this flag to false has
no effect on the actual state of the endpoint in the hardware.
Moreover, this flag was set to false for all the endpoints, including
the control ones which should not be disabled, so such operation
actually fooled the shim.

Signed-off-by: Andrzej Głąbek <andrzej.glabek@nordicsemi.no>
2019-06-27 12:17:45 +02:00
Andrzej Głąbek 036791364c usb: kconfig: nrf52840: Enable REMOTE_WAKEUP option only when needed
This patch removes the "hard" selection of the USB_DEVICE_REMOTE_WAKEUP
Kconfig option for USB devices made on the nRF52840 SoC. Now it's up to
the application to decide if it wants to enable the option. This change
makes it possible to pass the USB3CV Chapter 9 Tests for applications
that don't use the remote wakeup feature, since when a USB device only
reports that it supports this feature, and the mentioned option makes
it to do so, one of the test cases expects the USB device to actually
perform the remote wakeup. And when the feature is not reported as
supported, the test case is skipped.

Signed-off-by: Andrzej Głąbek <andrzej.glabek@nordicsemi.no>
2019-06-27 12:17:45 +02:00
Kumar Gala dba65ce47c drivers: Update DT IRQ alias defines
The defines should have had a _0 on them, now that we generate the
proper defines, fixup the cases that used that old scheme.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2019-06-21 07:53:05 -05:00
Andrei Emeltchenko d385db0884 usb: drivers: usb_dc_stm32: Fix coverity issue
Fixes coverity issue CID: 198865.

Fixes #16582

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2019-06-19 11:08:26 +02:00
Andrei Emeltchenko 1d61bef39e usb: drivers: usb_dc_stm32: Fix coverity issue
Add __ASSERT() for coverity issue CID: 198874. Assert is used instead
of check since this is callback we get from stm32cube.

Fixes #16573

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2019-06-19 11:08:26 +02:00
Loic Poulain 4fe7f69182 drivers: usb: nxp: Add cache management
Clean/Invalidate cache before/after usb TX/RX transfers.

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
2019-06-17 16:25:06 -04:00
Loic Poulain 7428f9c070 drivers: usb: nxp: Fix board freeze with various USB classes
Prevent to reschedule a transfer if one is already ongoing (occupied).
This happens with USB class drivers scheduling transfer once interface
is enabled (netusb, ACM...) and cause freeze due to infinite loop in
low level driver.

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
2019-06-17 16:25:06 -04:00
Kumar Gala a2693975d7 dts: Convert from DT_<COMPAT>_<INSTANCE>_<PROP> to DT_INST...
Change code from using now deprecated DT_<COMPAT>_<INSTANCE>_<PROP>
defines to using DT_INST_<INSTANCE>_<COMPAT>_<PROP>.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2019-06-14 08:02:15 -05:00
Anas Nashif 4c32258606 style: add braces around if/while statements
Per guidelines, all statements should have braces around them. We do not
have a CI check for this, so a few went in unnoticed.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-06 15:20:21 +02:00
Johann Fischer 105fccfb2d drivers: usb_dc_nrfx: cleanup logging and fix style
Cleanup logging and fix style. Use hex format specifier
for endpoint address. Remove periods from log messages.

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2019-05-30 09:31:48 -04:00
Andrei Emeltchenko 03ef375f5f drivers: usb: usb_dc_nrfx: Set cfg.en to false on Reset
Set false to enable flag on USB Reset.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2019-05-22 11:19:49 +02:00
Yannis Damigos a1e3f39214 usb_dc_stm32: Check if functions' arguments are valid
Check if usb_dc_* functions' arguments are valid.
Fixes `tests/subsys/usb/device` on STM32 SoCs.

Signed-off-by: Yannis Damigos <giannis.damigos@gmail.com>
2019-05-20 13:01:41 -04:00
Mark Wang 5f0d065514 drivers: usb: nxp: add NXP EHCI USB device controller driver shim
usb_dc_mcux_ehci driver is one shim of the NXP SDK ehci driver.
select NOCACHE_MEMORY if HAS_MCUX_CACHE

Signed-off-by: Mark Wang <yichang.wang@nxp.com>
2019-05-09 13:37:02 -05:00
Andrei Emeltchenko 5a4a658de1 usb: usb_dc_stm32: Return EAGAIN on lock failure
Return -EAGAIN on k_sem_take() failure to take write lock, the error
code is similar to nrfx write_in_progress flag.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2019-05-06 11:14:24 +02:00
Derek Hageman 07d18e3f52 drivers: usb: sam0: Remove defines from dts_fixup.h
Move SAM0 flash to use the raw defines generated from the DTS
parsing.

Signed-off-by: Derek Hageman <hageman@inthat.cloud>
2019-05-03 08:46:57 -05:00
Andrei Emeltchenko 446f5e48cb usb: dc: native_posix: Increase number of endpoints supported
Support 8 endpoints in each direction for native_posix.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2019-04-28 12:22:23 -04:00
Andrei Emeltchenko 8d6fbde898 usb: Remove usb_dc_ep_set_callback return code
Make usb_dc_ep_set_callback() return void since the code is never
used.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2019-04-28 12:22:23 -04:00
Benjamin Valentin c8208a399a usb: sam0: Implement missing API functions
This implements three API functions that are required for
tests/subsys/usb/device to build:

 - usb_dc_ep_disable()
 - usb_dc_ep_halt()
 - usb_dc_ep_flush()

While halt and disable are trivial, flush is just a stub for now.

Signed-off-by: Benjamin Valentin <benpicco@googlemail.com>
2019-04-26 03:20:29 -07:00
Benjamin Valentin f95f5ae41e usb: sam0: Ensure API arguments are valid
Make sure the parameters for the API functions are valid, return error
otherwise.

This is expected by the tests/subsys/usb/device test case.

Signed-off-by: Benjamin Valentin <benpicco@googlemail.com>
2019-04-26 03:20:29 -07:00
Benjamin Valentin 4d9486fc22 soc: sam0: Enable generic peripheral selection
Make sure that when e.g. CONFIG_SERIAL is set, CONFIG_UART_SAM0 is
selected automatically when the sam0 SoC family is used.

Signed-off-by: Benjamin Valentin <benjamin.valentin@ml-pa.com>
2019-04-19 14:37:17 -05:00
Andrei Emeltchenko f6784ed1d7 usb: usb_dc_stm32: Add missing function
Add missing API functions which will be tested with harness tests.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2019-04-18 12:16:05 -04:00
Andrei Emeltchenko cf349df34d usb: usb_dc_kinetis: Fix using invalid index
I does make sense to use index only after we make sure it is valid,
issue is found in harness tests.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2019-04-18 12:16:05 -04:00
Andrei Emeltchenko cc9c91513f usb: usb_dc_kinetis: Verify endpoint is valid
Verify endpoint before usb_dc_ep_set_callback().

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2019-04-18 12:16:05 -04:00
Andrei Emeltchenko 53ab1e2414 usb: usb_dc_native_posix: Check endpoint is valid
Fix harness tests.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2019-04-18 12:16:05 -04:00
Andrei Emeltchenko 582b44014c usb: usb_dc_dw: Check endpoint is valid
Fix harness test issues.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2019-04-18 12:16:05 -04:00
Andrei Emeltchenko 81fbf0f4b5 usb: usb_dc_native_posix: Fix valid endpoints check
Fix check for valid endpoints; issue is found in harness testing.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2019-04-18 12:16:05 -04:00
Andrei Emeltchenko 23d22043a4 usb: usb_dc_dw: Fix valid endpoints check
Fix check for valid endpoints; issue is found in harness testing.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2019-04-18 12:16:05 -04:00
Josef Gajdusek f01a7250f0 drivers: usb_dc_stm32: Reinitialize the write semaphores on bus reset
If the user attempts to send data before the USB connection is
established (see the HID sample for an example of such code), the
DataInCallback never gets called which leaves the write semaphore in a
taken state forever.

Signed-off-by: Josef Gajdusek <atx@atx.name>
2019-04-17 09:58:09 -05:00
Josef Gajdusek 29ffcae80c drivers: usb_dc_stm32: Make pin remapping part of the device tree
The SYSCFG_CFGR1_PA11_PA12_RMP define is present even on packages where
the remap isn't strictly required. This commit makes the remap optional
based on a DT property.

Also fixes syntax error caused by a missing );.

Signed-off-by: Josef Gajdusek <atx@atx.name>
2019-04-17 09:58:09 -05:00
Paweł Zadrożniak b2a3e12d86 drivers: usb: nordic: Do not log an error if HFCLK is busy
HFCLK may be requested for multiple modules, i.e. Bluetooth stack.
When any other module has requested HFCLK to run, the driver will
return -EBUSY on free attempt which is not an error - thie means
that free request has been processed, but someone else is still
requiring the clock to run. When all clock users free the clock,
it may be disabled.

Related issue: #15145

Signed-off-by: Paweł Zadrożniak <pawel.zadrozniak@nordicsemi.no>
2019-04-15 11:10:19 +02:00
Johann Fischer d2c6869e30 drivers: usb: check maximum packet size
Check maximum packet size (MPS) of an endpoint in usb_dc_kinetis
and usb_dc_native_posix drivers.

resolves #14957
resolves #14954

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2019-04-11 13:35:24 -04:00
Johann Fischer c13e201b18 usb: replace MAX_PACKET_SIZE0 with meaningful USB_MAX_CTRL_MPS
Replace MAX_PACKET_SIZE0 with meaningful USB_MAX_CTRL_MPS.

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2019-04-11 13:35:24 -04:00
Andrei Emeltchenko 5b74fb4f23 usb: usb_dc_kinetis: Fix endpoint index check
Fix check for maximum endpoint index.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2019-04-11 13:35:24 -04:00
Andrei Emeltchenko 40774007c3 usb: usb_dc_kinetis: Fix access wrong memory
Add appropriate check.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2019-04-11 13:35:24 -04:00
Andrei Emeltchenko 08f53a435c usb: usb_dc_kinetis: Fix setting address for not attached device
Add appropriate check.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2019-04-11 13:35:24 -04:00
Anas Nashif 3ae52624ff license: cleanup: add SPDX Apache-2.0 license identifier
Update the files which contain no license information with the
'Apache-2.0' SPDX license identifier.  Many source files in the tree are
missing licensing information, which makes it harder for compliance
tools to determine the correct license.

By default all files without license information are under the default
license of Zephyr, which is Apache version 2.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-04-07 08:45:22 -04:00
Andrei Emeltchenko 8ed215e011 usb: usb_dc_stm32: Fix reading invalid EP
Fix crash when reading invalid endpoint found in harness test.

Fixes #13560

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2019-04-05 16:12:46 -04:00
Andrei Emeltchenko 06ef0ca0fc usb: usb_dc_stm32: Add placeholders for missing API
Fix build error when executing sanitycheck on stm32 devices.

Command to execute tests:
sanitycheck --device-testing --device-serial /dev/ttyACM0 -p <board>
    -t usb

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2019-04-05 16:12:46 -04:00
Patrik Flykt 97b3bd11a7 drivers: Rename reserved function names
Rename reserved function names in drivers/ subdirectory. Update
function macros concatenatenating function names with '##'. As
there is a conflict between the existing gpio_sch_manage_callback()
and _gpio_sch_manage_callback() names, leave the latter unmodified.

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2019-04-03 17:31:00 -04:00
Paweł Zadrożniak e01662d387 drivers: usb: nordic: Fix for startup with USB cable attached.
Fixes bug introduced in #14875.
USBDETECTED event is be generated on cable attachment and
when cable is already attached during reset, but not when
the peripheral is re-initialized. When USB-enabled bootloader
is used, target application will not receive this event
and it needs to be generated again. This commit implements
a check against driver being enabled multiple times in case
of application without bootlader starting with cable attached
(both "fake" and "real" events are generated). Such dirty
trick allows bootloader to leave the peripheral in any state
before jumping to target application.

Fixes #15073

Signed-off-by: Paweł Zadrożniak <pawel.zadrozniak@nordicsemi.no>
2019-04-02 11:16:27 -04:00
Patrik Flykt 21358baa72 all: Update unsigend 'U' suffix due to multiplication
As the multiplication rule is updated, new unsigned suffixes
are added in the code.

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2019-03-28 17:15:58 -05:00
Patrik Flykt 24d71431e9 all: Add 'U' suffix when using unsigned variables
Add a 'U' suffix to values when computing and comparing against
unsigned variables.

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2019-03-28 17:15:58 -05:00
Takumi Ando bdde5fd984 driver: usb: nordic: Enable USB DC when VBUS is Hi
We want to enable USB DC at not only VBUS detection event
but also it has been already high.

Signed-off-by: Takumi Ando <takumi.ando@atmark-techno.com>
2019-03-28 14:59:01 +01:00
Ioannis Glaropoulos 6a546d1938 drivers: usb: nrfx: initialize local struct to zero
Initialize a local struct variable to zero, to suppress
un-initialized variable error.

Fixes #14422.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2019-03-15 09:26:43 -05:00
Kumar Gala 626dd420fc drivers: usb: nrf: Fix mixing of enum types
When we build with clang we can a warning related to mixing of enum
types.  Just use nrfx_usbd_ep_status_t since that is the type returned
by nrfx_usbd_ep_status_get.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2019-03-15 05:53:32 +01:00
Paweł Zadrożniak 79dc1feeb3 drivers: usb: nordic: Fix for events when cable is detached
When user disconnects the USB cable, peripheral should be
immediately disabled, howewer a delay may occur when driver
events are processed from a workqueue or higher-priority
thread/ISR is active. This may lead to a fake resume/reset
event (peripheral-specific behavior). This fix drops such
events when cable is detached.

Fixes #13822

Signed-off-by: Paweł Zadrożniak <pawel.zadrozniak@nordicsemi.no>
2019-03-13 17:35:55 +01:00
Andrei Emeltchenko f8e1dfc331 usb: dc: native_posix: Fix Coverity bug
Fixes Untrusted array index read bug.

Fixes #14406

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2019-03-13 05:35:25 -05:00
Paweł Zadrożniak 804b9e1ada drivers: usb: nordic: implement remote wakeup
Adds remote wakeup support for nRF chips.

Signed-off-by: Paweł Zadrożniak <pawel.zadrozniak@nordicsemi.no>
2019-02-27 10:37:16 +01:00
Piotr Zięcik d30c9aeafd drivers: nrf_power_clock: Migrate to DTS.
This commit migrates the nrf_power_clock driver to DTS.

Signed-off-by: Piotr Zięcik <piotr.ziecik@nordicsemi.no>
2019-02-25 17:51:24 +01:00
Carlos Stuart 75f77db432 include: misc: util.h: Rename min/max to MIN/MAX
There are issues using lowercase min and max macros when compiling a C++
application with a third-party toolchain such as GNU ARM Embedded when
using some STL headers i.e. <chrono>.

This is because there are actual C++ functions called min and max
defined in some of the STL headers and these macros interfere with them.
By changing the macros to UPPERCASE, which is consistent with almost all
other pre-processor macros this naming conflict is avoided.

All files that use these macros have been updated.

Signed-off-by: Carlos Stuart <carlosstuart1970@gmail.com>
2019-02-14 22:16:03 -05:00
Yannis Damigos 6a676caab6 usb_dc_stm32: Fix check endpoint capabilities
DT_USB_NUM_BIDIR_ENDPOINTS includes EP0, which we should not
take it into account when we check endpoint capabilities

Signed-off-by: Yannis Damigos <giannis.damigos@gmail.com>
2019-02-09 16:58:22 -06:00
Andrei Emeltchenko bd7d48a61f usb: native_posix: Fix ep_configure() and ep_mps()
Fix issues found in unit tests.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2019-02-08 07:56:24 -05:00
Takumi Ando 782a88f2c1 driver: usb: nordic: Fix compile warning with newlib
This commit fixes compile warning with CONFIG_NRFX_USB
and CONFIG_NEWLIB_LIBC.

Signed-off-by: Takumi Ando <takumi.ando@atmark-techno.com>
2019-02-06 14:25:09 +01:00
Paweł Zadrożniak 85d75ec853 drivers: usb: nordic: Power consumption fix with cable detached
This commit fixes the issue with excess current being drawn
during sleep due to active HFCLK with external crystal.
Clock-related operations were moved to cable attachmend and
detachment handlers to ensure that HFCLK is not requested
when it's not needed.

Signed-off-by: Paweł Zadrożniak <pawel.zadrozniak@nordicsemi.no>
2019-02-04 20:48:25 -05:00
Tom Burdick 08d900df4b usb: fix usb data race
Clock ISR would callback into the USB driver before it was initialized
and ready to deal with events. This caused a fault.

Statically initialize the fifo to queue events and process them when the
USB device is initialized to avoid the problem.

Signed-off-by: Tom Burdick <thomas.burdick@gmail.com>
2019-02-01 19:04:07 -05:00
Andrei Emeltchenko b6b5fdac32 usb: native_posix: Implement other then Control transfers
Add support for other transfers.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2019-02-01 19:03:12 -05:00
Andrei Emeltchenko 80120871ed usb: native_posix: Move to new logging subsystem
Use new logger log method.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2019-02-01 19:03:12 -05:00
Andrei Emeltchenko 9f1443e18a usb: native_posix: Use non-blocking connection socket
Use non-blocking connfd from accept4() call for native_posix.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2019-02-01 19:03:12 -05:00
Andrei Emeltchenko 03b7d9f59d usb: native_posix: Use non-blocking socket
Use non-blocking socket for native_posix to allow other processes to
run.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2019-02-01 19:03:12 -05:00
Andrei Emeltchenko b8b86c4c75 usb: driver: Add native_posix USB driver
Add native_posix USB virtual driver connected over USBIP to the Host
Linux.

Fixes: #9846

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2019-02-01 19:03:12 -05:00
Kumar Gala 9e4016d8dc usb: usb_dc_stm32: Convert to DT instance defines to remove dts_fixup.h
Convert usb_dc_stm32 driver GPIO disconnect to use new defines so we
can remove the dts_fixup.h code for it.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2019-02-01 04:12:15 -06:00
Kumar Gala 0370dbee4a usb: usb_dc: Replace CONFIG_ symbols that should be DT_
1. Fix trailing comment for DT_USBHS_MAXIMUM_SPEED
2. Fix missed CONFIG_USB_HS_BASE_ADDRES that should be
   DT_USB_HS_BASE_ADDRESS

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2019-02-01 04:08:26 -06:00
Paweł Zadrożniak a0e2737aff drivers: nordic: usb: USBD event handling rework
Some of the events from USBD peripheral (i.e. cable disconnect)
were handled in IRQ context and some of them (i.e. ep r/w events) in
system workqueue (inherited from initial driver implementation).
This may lead to race condition in some specific situations.
Currently, all of the events are enqueued in ISR and processed in
workqueue. Driver is reinitialized on queue overflow and queue size
is configurable in KConfig.

Fixes #12016

Signed-off-by: Paweł Zadrożniak <pawel.zadrozniak@nordicsemi.no>
2019-01-23 16:55:15 +01:00
Pawel Dunaj bfb23cc5de drivers: usb: Do not enable non-existing USB endpoints
Number of USB endpoints is set via DTS, nevertheless USB driver
tries to enable all endpoints as it uses number of endpoints from
nRFx.
This commit makes driver enable only these endpoints that were
enabled in DTS.

Signed-off-by: Pawel Dunaj <pawel.dunaj@nordicsemi.no>
2019-01-22 17:44:17 +01:00
Ioannis Glaropoulos 2e687653fa drivers: clock control: rename nrf5_power_clock source and header
This commit renames the nrf5_clock_control.h and
nrf5_clock_control.c files to nrf_clock_control.h and
nrf_clock_control.c, respectively, as they are used
in nRF9160 builds, as well.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2019-01-15 18:03:24 +01:00
Ioannis Glaropoulos 302a746bd6 drivers: clock control: nrf: rename CLOCK_CONTROL_NRF5 Kconfig symbol
This commit renames the CLOCK_CONTROL_NRF5 Kconfig symbol to
CLOCK_CONTROL_NRF. The change is required to aleviates confusion
when selecting the symbol in nRF9160 SOC definition.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2019-01-15 18:03:24 +01:00
Paweł Zadrożniak 480b728d52 drivers: usb: nordic: Fix IN transfer fragmentation
Currently, when usb_dc_ep_write is called, data is copied to the
internal buffer, hence the requirement for fragmentation, regardless
of low-level nrfx_usbd driver. This commit forces the fragmentation
and prevents potential internal buffer overflow. Adittional
fragmentation flag was added to prevent triggering status stage
(it is handled by hardware completely on nRF chips).

Fixes #12339

Signed-off-by: Paweł Zadrożniak <pawel.zadrozniak@nordicsemi.no>
2019-01-14 11:02:47 +01:00
Loic Poulain a32a39f3d2 drivers: usb_dc_stm32: Add support for MSI clock
When MSI clock is available and in PLL-Mode (high accuracy), use it as
USB source clock. This allows to enable USB on STM34l475 disco iot
board without having to add external oscillator.

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
2019-01-02 09:33:21 -05:00
Andrzej Głąbek 4b43065cfc drivers: nrf: Enable nRF drivers by default in Kconfig
Make the following nRF peripheral drivers:
- ADC
- GPIO
- I2C
- SPI
- UART
- USB_DEVICE
enabled by default so that users do not need to explicitly enable them
in their applications after choosing an nRF SoC as the build target.

Kconfig options enabling these drivers depend on both a given hardware
feature (e.g. I2C) and an nRF family SoC selected, so effectively they
will be automatically enabled only when it is adequate (and in most
cases these drivers are the only option for a given hardware feature
on nRF SoCs).

Signed-off-by: Andrzej Głąbek <andrzej.glabek@nordicsemi.no>
2018-12-21 21:01:37 +01:00
Aurelien Jarno c52a64624e drivers: usb_dc_stm32: add support for SoF event
Add support for SoF events to the USB STM32 device driver. When
CONFIG_USB_DEVICE_SOF is enabled, enable the corresponding interrupt
and provide a non-weak callback function calling status_cb.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2018-12-17 08:17:58 -06:00
Erwan Gouriou 9062e97a45 drivers: stm32: check clock_control_on return value
Check clock_control_on return value now that it is checking appropriate
bus is used in the request.

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2018-12-07 11:31:48 -05:00
Patrik Flykt 8ff96b5a57 drivers: Add 'U' to unsigned variable assignments
Add 'U' to a value when assigning it to an unsigned variable.
MISRA-C rule 7.2

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2018-12-04 22:51:56 -05:00
Paweł Zadrożniak 6e460ca64f drivers: usb: nordic: Fix class/vendor request handling
SetAddress request (0x05) is ignored and not propagated, because it
is handled by nRF hardware. Curently, request type is not checked
causing class or vendor request 0x05 to be inappropiately ignored.
Only standard requests (type = 0) shoud be ignored. This commit
fixes the issue.

Signed-off-by: Paweł Zadrożniak <pawel.zadrozniak@nordicsemi.no>
2018-12-04 13:53:48 +01:00
Andrzej Głąbek 965128bab1 drivers: usb_dc_nrfx: Align with nrfx version 1.4.0
A typo in the name of the bmRequest field in the nrfx_usbd_setup_t
structure was fixed in nrfx version 1.4.0. Update the driver to use
the new correct name: bRequest.

Signed-off-by: Andrzej Głąbek <andrzej.glabek@nordicsemi.no>
2018-12-03 17:56:15 +01:00
Paweł Zadrożniak 1da367b5bf drivers: nordic: usbd: Fix long (fragmented) control OUT transfers
Fragmented long CTRL OUT transfers does not work properly, because
they were not handler properly by the shim. In such transfers,
a special call (nrfx_usbd_setup_data_clear()) must be performed
before every data packet and not just before the first one.
This patch adds a byte counter which is set while processing setup
packet (host->device only) to be able to decide whether there will
be more data packets coming (and to call_data_clear() or not).

Fixes #11232 .

Signed-off-by: Paweł Zadrożniak <pawel.zadrozniak@nordicsemi.no>
2018-12-03 10:28:11 +01:00
Aurelien Jarno 6ed2ea66d0 drivers: usb_dc_sam: add support for SoF event
Add support for SoF events to the USB SAM device driver. When
CONFIG_USB_DEVICE_SOF is enabled, enable the corresponding interrupt
and call the callback function from there.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2018-12-02 10:39:39 -05:00
Aurelien Jarno 92f7c7c3b5 drivers: usb_dc_sam: kill a coverity warning
Coverity complains that packet_len can get assigned a negative value if
usb_dc_ep_mps() returns an error. This is correct, however it only
happens if the endpoint address is invalid, and in that case the value
is not used as the endpoint address is also validated in
usb_dc_ep_write().

Fix the issue by moving the assignment after the endpoint address
validation and by accessing the value directly instead of getting it
through usb_dc_ep_mps().

Fixes #11481
Coverity-CID: 189742

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2018-11-23 09:19:44 -05:00
Marcin Szymczyk e4c447aac3 usb: add SoF event
Start of Frame events can now be accessed from USB classes.
This will be useful when implementing idle rate functionality.

Signed-off-by: Marcin Szymczyk <Marcin.Szymczyk@nordicsemi.no>
2018-11-23 09:18:41 -05:00
Paweł Zadrożniak 55674d8e17 drivers: usb: nordic: change USBD driver locking scheme
Nordic USB driver shim uses nrfx_usbd driver from nrfx package.
The driver was protected by a semaphore during every transfer
to prevent access from multiple threads at the same time.
This leads to the problem when a class schedules transfer on one
endpoint before host asks for the data (to be sent later) - driver
is locked and other endpoints (including control EP) are blocked.
Currently, only driver calls are wrapped with semaphore without
waiting for the transfer to complete, allowing scheduling transfers
on different endpoints. This is allowed bu nrfx_usbd, however
shim prevents user from scheduling multiple transfers on one
EP (required by nrfx_usbd).

Signed-off-by: Paweł Zadrożniak <pawel.zadrozniak@nordicsemi.no>
2018-11-22 13:13:16 -05:00
Mieszko Mierunski ac4f588e1f dts: nrf: Remove USBD dts.fixup defines and use aliases instead.
Changed driver to use defines from aliases instead of fixup.

Signed-off-by: Mieszko Mierunski <mieszko.mierunski@nordicsemi.no>
2018-11-20 22:18:09 +01:00
Yannis Damigos 954a943854 drivers: usb_dc_stm32: Use DT to check if USBPHYC exists
Use DT to check if SoC has a USBPHYC controller.

Signed-off-by: Yannis Damigos <giannis.damigos@gmail.com>
2018-11-15 07:27:23 -06:00
Andrzej Głąbek 20202902f2 dts_fixups: Use DT_ prefix in all defined labels not related to Kconfig
These changes were obtained by running a script  created by
Ulf Magnusson <Ulf.Magnusson@nordicsemi.no> for the following
specification:

1. Read the contents of all dts_fixup.h files in Zephyr
2. Check the left-hand side of the #define macros (i.e. the X in
   #define X Y)
3. Check if that name is also the name of a Kconfig option
   3.a If it is, then do nothing
   3.b If it is not, then replace CONFIG_ with DT_ or add DT_ if it
       has neither of these two prefixes
4. Replace the use of the changed #define in the code itself
   (.c, .h, .ld)

Additionally, some tweaks had to be added to this script to catch some
of the macros used in the code in a parameterized form, e.g.:
- CONFIG_GPIO_STM32_GPIO##__SUFFIX##_BASE_ADDRESS
- CONFIG_UART_##idx##_TX_PIN
- I2C_SBCON_##_num##_BASE_ADDR
and to prevent adding DT_ prefix to the following symbols:
- FLASH_START
- FLASH_SIZE
- SRAM_START
- SRAM_SIZE
- _ROM_ADDR
- _ROM_SIZE
- _RAM_ADDR
- _RAM_SIZE
which are surprisingly also defined in some dts_fixup.h files.

Finally, some manual corrections had to be done as well:
- name##_IRQ -> DT_##name##_IRQ in uart_stm32.c

Signed-off-by: Andrzej Głąbek <andrzej.glabek@nordicsemi.no>
2018-11-13 10:44:42 -06:00
Aurelien Jarno 7ef3ddce45 drivers: usb_dc_sam: use original logger functions
Rename USB_{DBG,ERR,INF,WRN} into LOG_{DBG,ERR,INF,WRN}. This driver has
been missed from PR #11001 as it has been committed after.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2018-11-08 16:33:23 -05:00
Andrei Emeltchenko 93bd26343e usb: logs: Rename USB_WRN to LOG_WRN
Since logger is now suitable for our logs use it directly.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-11-08 08:35:20 -05:00
Andrei Emeltchenko f22060cdbe usb: logs: Rename USB_INF to LOG_INF
Since logger is now suitable for our logs use it directly.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-11-08 08:35:20 -05:00
Andrei Emeltchenko 17f7abd3dc usb: logs: Rename USB_ERR to LOG_ERR
Since logger is now suitable for our logs use it directly.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-11-08 08:35:20 -05:00
Andrei Emeltchenko 92c7ab74c0 usb: logs: Rename USB_DBG to LOG_DBG
Since logger is now suitable for our logs use it directly.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-11-08 08:35:20 -05:00
Aurelien Jarno 6b6e54321a drivers: usb: add usb device driver for Atmel SAM E70 family
This patch adds a USB device driver for the USBHS device that can be
found on Atmel SAM E70 SoC family. Only the FIFO mode is supported
(as opposed to DMA). It supports LS, FS and HS modes, but defaults to
FS mode as Zephyr does not fully support HS mode yet.

Tested examples on an Atmel SMART SAM E70 Xplained Board:
* usb/cdc_acm
* usb/hid-mouse
* usb/mass

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2018-11-06 16:32:35 -05:00
Andrei Emeltchenko 767b4ec6b7 usb: usb_dc_nrfx: Remove dead code
Fix deadcode warning.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-11-05 08:46:55 -05:00
Kumar Gala aa2bdbe322 drivers: Remove board.h include
We either don't need board.h in the driver or we should be include soc.h
instead.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2018-11-01 13:21:11 -04:00
Paweł Zadrożniak 7791f58a15 drivers: usb: nordic: Fix max packet size handling
This commit fixes the issue with non-default max packet size (<64).
The max packet size value was not passed to low-level driver
in norfic hal (nrfx_usbd) causing 64-byte being send regardless of
configured endpoint size. Size mismatch results in communication
error on Linux hosts.

Signed-off-by: Paweł Zadrożniak <pawel.zadrozniak@nordicsemi.no>
2018-10-30 18:14:17 +01:00
Anas Nashif 80ced11209 drivers: usb_dc_nrfx: move to new logger
Move to new logger and apply style guidelines.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-10-16 17:30:09 -04:00
Paweł Zadrożniak 68cb7b3e38 drivers: usb: Add nRF52840 USBD driver
* Add usbd_dc_nrfx shim

The shim is based on the previous one usbd_dc_nrf5.
For handling the USBD hardware, tested nrfx_usbd driver from nRF SDK
was used.

Briefly tested examples:
* usb/cdc_acm
* usb/dfu (USB communication only due to flash handling issues)
* usb/hid-mouse
* bluetooth/hci_usb

Signed-off-by: Paweł Zadrożniak <pawel.zadrozniak@nordicsemi.no>
2018-10-12 13:14:12 +02:00
Yannis Damigos c9007f0daf drivers: usb_dc_stm32: Add HIGH and HIGH_IN_FULL defines for L4 series
STM32L4 series USB LL API doesn't provide HIGH and HIGH_IN_FULL speed.
Define them on drivers level.

Signed-off-by: Yannis Damigos <giannis.damigos@gmail.com>
2018-10-10 12:27:55 -05:00
Carles Cufi 4fe661181c drivers: usb: stm32: Limit the amount of bytes to write
Limit the amount of bytes to write to EP0 to 64 bytes so that there is
no overflow or error when sending.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2018-10-09 21:37:51 +02:00
Yannis Damigos 3c9f1c9627 drivers: usb_dc_stm32: Get maximum-speed from DT
Get maximum-speed from device tree for OTG FS/HS.

Signed-off-by: Yannis Damigos <giannis.damigos@gmail.com>
2018-10-09 12:59:34 -04:00
Yannis Damigos 452c3d6a87 include/usb/usb_device: Add USB_* log macros
Add USB_DBG, USB_WRN, USB_ERR, USB_INF macros
in usb_device header file and remove them
from usb device drivers.

Signed-off-by: Yannis Damigos <giannis.damigos@gmail.com>
2018-10-08 12:54:57 -04:00
Yannis Damigos 1674d061b6 drivers: usb: device: Migrate to new logger
Move to new logger subsystem.

Signed-off-by: Yannis Damigos <giannis.damigos@gmail.com>
2018-10-08 12:54:57 -04:00
Mark Ruvald Pedersen d67096da05 portability: Avoid void* arithmetics which is a GNU extension
Under GNU C, sizeof(void) = 1. This commit merely makes it explicit u8.

Pointer arithmetics over void types is:
 * A GNU C extension
 * Not supported by Clang
 * Illegal across all ISO C standards

See also: https://gcc.gnu.org/onlinedocs/gcc/Pointer-Arith.html

Signed-off-by: Mark Ruvald Pedersen <mped@oticon.com>
2018-09-28 07:57:28 +05:30
Flavio Ceolin 67ca176754 headers: Fix headers across the project
Any word started with underscore followed by and uppercase letter or a
second underscore is a reserved word according with C99.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2018-09-17 15:49:26 -04:00
Flavio Ceolin da49f2e440 coccicnelle: Ignore return of memset
The return of memset is never checked. This patch explicitly ignore
the return to avoid MISRA-C violations.

The only directory excluded directory was ext/* since it contains
only imported code.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2018-09-14 16:55:37 -04:00
Maureen Helm 95be60a80f usb: device: Fix kinetis driver to compile with SYS_LOG disabled
Fixes a compile error in the kinetis usb device driver when SYS_LOG is
disabled.

Signed-off-by: Maureen Helm <maureen.helm@nxp.com>
2018-09-14 13:22:03 -05:00
Vinayak Kariappa Chettimada 67786e3270 usb: device: nrf5: Fix HF clock enable check
Fixed return value check after HF clock is requested in
non-blocking mode.

hci_usb sample on nRF52840 SoC failed to enumerate USB
device on cold reset, the clock_control_on interface would
return -EINPROGRESS when clock is enabled in non-blocking
mode.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2018-09-05 15:26:18 +02:00
Istvan Bisz ea9d4a79c9 drivers: usb: add support for USB OTG FS on STM32F2
Add support for usbotg_fs, by adding the DT fixup, pinmux macros,
and the DT entries in stm32f2.dtsi.

Signed-off-by: Istvan Bisz <istvan.bisz@t-online.hu>
2018-08-16 06:19:19 -07:00
Ulf Magnusson 8cf8db3a73 Kconfig: Use a short, consistent style for prompts
Consistently use

    config FOO
            bool/int/hex/string "Prompt text"

instead of

    config FOO
            bool/int/hex/string
            prompt "Prompt text"

(...and a bunch of other variations that e.g. swapped the order of the
type and the 'prompt', or put other properties between them).

The shorthand is fully equivalent to using 'prompt'. It saves lines and
avoids tricking people into thinking there is some semantic difference.

Most of the grunt work was done by a modified version of
https://unix.stackexchange.com/questions/26284/
how-can-i-use-sed-to-replace-a-multi-line-string/26290#26290, but some
of the rarer variations had to be converted manually.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2018-08-15 04:10:10 -07:00
Andrei Emeltchenko 1f4e8d679b usb_dc_stm32: Fix FS mode
Fixes FS mode for STM32F7XX devices.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-07-24 22:27:17 -04:00
Yannis Damigos 48de3ec616 drivers: usb_dc_stm32: Add OTG HS full-speed PHY support
Enable the driver to work in full-speed mode on OTG HS
controller using its full-speed or high-speed internal
PHY.

Please note that only one interface should be enabled
at a time, OTG FS or OTG HS. The driver will raise an
error if both are enabled.

Signed-off-by: Yannis Damigos <giannis.damigos@gmail.com>
2018-07-24 22:27:17 -04:00
Johann Fischer f5b91bad17 drivers: usb_dc_kinetis: fix gcc 7.3.1 warning
Use the same variable type for the odd bit handling
and fix the boolean expression warning with gcc 7.3.1.

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2018-07-16 13:54:02 -05:00
Aurelien Jarno 9107e3dac8 drivers: usb: add support for USB OTG FS on STM32F7
The STM32F7 uses the same USB OTG FS controller than the STM32F4 series.
It is therefore trivial to add support for it, by adding the DT fixup
and pinmux macros, and the DT entries in stm32f7.dtsi. Keep it disabled,
it should be enabled at the board level.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2018-07-11 16:28:10 -05:00
Johannes Hutter 6c0d089594 drivers: usb_dc_stm32: don't wait for semaphore in ISR context
usb_dc_ep_write may be executed in an ISR context and should therefore
not take a semaphore with a timeout. The semaphore was initially
introduced to prevent USB buffer overwrite when writing to an endpoint
in a loop. This is not requested anymore since there is an existing USB
transfer API available.

Signed-off-by: Johannes Hutter <johannes@proglove.de>
2018-07-05 11:06:30 -04:00
Ulf Magnusson 7cdd946d2d drivers: usb: Kconfig: Remove redundant 'default n' properties
Bool symbols implicitly default to 'n'.

A 'default n' can make sense e.g. in a Kconfig.defconfig file, if you
want to override a 'default y' on the base definition of the symbol. It
isn't used like that on any of these symbols though, and is
inconsistent.

This will make the auto-generated Kconfig documentation have "No
defaults. Implicitly defaults to n." as well, which is clearer than
'default n if ...'

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2018-07-03 17:11:31 -04:00
Sathish Kuttan 1b0641e2e2 drivers: usb: Add High Speed support for DesignWare USB
Added CONFIG_USB_DW_USB_2_0
Updated global configuration register to use UTMI 16 bit PHY
Updated device configuration register to use High Speed

Signed-off-by: Sathish Kuttan <sathish.k.kuttan@intel.com>
2018-06-19 20:16:18 -04:00
Savinay Dharmappa e682652d8c drivers: usb: Fix build error for intel_s1000.
As not all controllers using DW usb doesn't inherit
the qmsi related header, use of QM_USB_MAX_PACKET_SIZE,
QM_USB_IN_EP_NUM and QM_USB_OUT_EP_NUM break the build
for such platform. Hence defined new macros and corresponding
change done in driver.

Signed-off-by: Savinay Dharmappa <savinay.dharmappa@intel.com>
2018-06-19 15:52:03 -04:00
Aurelien Jarno 7688f49065 drivers: usb_dc_stm32: change all endpoints to bidirectional
The various STM32 reference manuals sometimes define the USB endpoints
as IN or OUT only and sometimes as bidirectional, even in the same
manual. This is likely because the OTG implementation has one set of
registers for the IN endpoints and one other set for OUT endpoints.
However at the end a given endpoint address can both transmit and
receive data.

This causes some confusion how to declare the endpoints in the device
tree, and depending on the SoC, they are either the same number of IN
and OUT endpoints declared, or they are declared as bidirectional. At
the end it doesn't really matter given how the driver uses those values:

    #define NUM_IN_EP (CONFIG_USB_NUM_BIDIR_ENDPOINTS + \
                       CONFIG_USB_NUM_IN_ENDPOINTS)

    #define NUM_OUT_EP (CONFIG_USB_NUM_BIDIR_ENDPOINTS + \
                        CONFIG_USB_NUM_OUT_ENDPOINTS)

    #define NUM_BIDIR_EP NUM_OUT_EP

This patch therefore cleanup the driver, the DTS, and the DTS fixups to
only define the number of bidirectional endpoints.

In addition to the cleanup, that fixes a regression introduced by commit
52eacf16a2 ("driver: usb: add check for endpoint capabilities"), which
introduced a wrong check for SoC only defining the number of
bidirectional endpoints.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2018-06-18 15:24:15 -04:00
Istvan Bisz 49554dd35a drivers: usb_dc_stm32: Change SYS_LOG_LEVEL
Suppress messages by DBG SYS_LOG_LEVEL setting:
[general] [ERR] usb_dc_ep_check_cap: ep 81, mps 64, type 2
[general] [ERR] usb_dc_ep_check_cap: ep 1, mps 64, type 2

Signed-off-by: Istvan Bisz <istvan.bisz@t-online.hu>
2018-06-17 10:49:16 -04:00
Johann Fischer 52eacf16a2 driver: usb: add check for endpoint capabilities
Add function to check capabilities of an endpoint.
Only basic properties are checked, especially on STM32
capabilities of different USB controller configurations
have to be considered in the future.

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2018-06-15 11:02:05 +02:00
Johann Fischer 4d0a1912a6 drivers: usb_dc_kinetis: fix usb_dc_ep_read_continue
usb_dc_ep_read_continue can be called without usb_dc_ep_read_wait,
check if the current buffer is claimed by the controller
(transfer not finished) to prevent a faulty behavior.

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2018-05-30 11:23:39 -05:00
Aurelien Jarno 80a9b02200 drivers: usb_dc_stm32: enable VDDUSB on STM32L4x2
The STM32L4x2 SoCs need to control the isolation of the USB features
from VDDUSB. This is done through the PWR_CR2 bit USV, however the
current code checks for the PWR_CR2_PVME1 bit instead, which is only
available on Cat. 3 devices. This bug is also present int the HAL and
likely copied from there.

Replace the check by PWR_CR2_USV instead.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2018-05-24 09:42:30 -05:00
Johann Fischer 192833a828 drivers: usb_dc_kinetis: fix out-of-bounds write/read
Fix out-of-bounds write/read.

fixes: #7714
fixes: #7715
fixes: #7719
fixes: #7721
fixes: #7723
fixes: #7725
fixes: #7727
fixes: #7734
fixes: #7738

Coverity-ID: 186032
Coverity-ID: 186036
Coverity-ID: 186044
Coverity-ID: 186046
Coverity-ID: 186048
Coverity-ID: 186051
Coverity-ID: 186055
Coverity-ID: 186059
Coverity-ID: 186061

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2018-05-23 18:57:33 -04:00
Johann Fischer 06840af1cc drivers: usb: kinetis: fixup endpoint config, stall and read
This patch fixes some bugs found during testing with testusb from
linux kernel.

An unresolved issue is that the stack is not fast enough
to stall (if necessary) the control endpoint during Setup Stage.
This might require a API change so that the usb device stack
can explicit allow the driver to resume token processing.

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2018-05-17 07:00:49 -05:00
Johann Fischer 5dc6f99cfd drivers: usb: add usb device driver for Kinetis USBFSOTG Controller
Add usb device driver for Kinetis USBFSOTG Controller.

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2018-05-17 07:00:49 -05:00
Yannis Damigos aec465968c drivers/usb_dc_stm32: Check if SYSCFG is enabled
Add a check to raise an error if SYSCFG is disabled,
before doing the pin remaping for F0 SoCs on QFN28
and TSSOP20 packages.

Signed-off-by: Yannis Damigos <giannis.damigos@gmail.com>
2018-05-14 09:45:40 -05:00
Yannis Damigos c9d5b56140 drivers/usb_dc_stm32: HSI48 requires VREFINT in L0
In STM32L0 series, HSI48 requires VREFINT and its buffer
with 48 MHz RC to be enabled. This patch enables
VREFINT reference for HSI48 oscillator.

Signed-off-by: Ilya Tagunov <tagunil@gmail.com>
Signed-off-by: Yannis Damigos <giannis.damigos@gmail.com>
2018-05-14 09:33:29 -05:00
Yannis Damigos 2a55fcf607 drivers/usb/usb_dc_stm32: Provide EP_TYPE_* defines for L0
USB LL API provides the EP_TYPE_* defines. STM32Cube does not
provide USB LL API for STM32L0 family. Map EP_TYPE_* defines
to PCD_EP_TYPE_* defines.

Signed-off-by: Yannis Damigos <giannis.damigos@gmail.com>
2018-05-14 09:33:29 -05:00
Yannis Damigos c0b472132c dts/arm/st: Add USB support for stm32l072/73
Add USB support for stm32l072 and stm32l073 SoCs

Signed-off-by: Yannis Damigos <giannis.damigos@gmail.com>
2018-05-14 09:33:29 -05:00
Yannis Damigos f47b9c2fca drivers/usb/device: Remove USB DISCONNECT gpio options
Remove USB DISCONNECT gpio options from Kconfig.

Signed-off-by: Yannis Damigos <giannis.damigos@gmail.com>
2018-05-11 16:53:12 -04:00
Yannis Damigos 3bbe87e171 dts/arm/st: Add usbotg_fs node to stm32l4 DT
Add otgfs (USB) node to stm32l4.dtsi.

Signed-off-by: Yannis Damigos <giannis.damigos@gmail.com>
2018-05-10 07:47:13 -05:00
Pushpal Sidhu e2b27d820d drivers: usb_dc_stm32: enable VDDUSB if needed
This is required on boards that isolate VDDUSB from the system.

Signed-off-by: Pushpal Sidhu <psidhu.devel@gmail.com>
2018-05-10 07:47:13 -05:00
Pushpal Sidhu b1478518c0 drivers: usb_dc_stm32: use HSI48 if available
This clock was designed to power crystal-less usb if available.

Signed-off-by: Pushpal Sidhu <psidhu.devel@gmail.com>
2018-05-10 07:47:13 -05:00
Yannis Damigos 47fe4ee78b dts/arm/st: Add USB support for stm32f070/72
Add USB support for stm32f072 and stm32f070 SoCs

Signed-off-by: Yannis Damigos <giannis.damigos@gmail.com>
2018-05-10 07:47:13 -05:00
Yannis Damigos 38d2567e08 boards: olimexino_stm32: Add USB support
Add USB support to OLIMEXINO-STM32 board

Signed-off-by: Yannis Damigos <giannis.damigos@gmail.com>
2018-05-10 07:47:13 -05:00
Yannis Damigos 55dada2592 drivers: usb_dc_stm32: Add usb disconnect pin support
Add usb disconnect pin support.
Some boards use a GPIO pin to controll a transistor,
which drives the pull-up resistor on USB DP pin.

Signed-off-by: Yannis Damigos <giannis.damigos@gmail.com>
2018-05-10 07:47:13 -05:00
Yannis Damigos 921bfeb05a drivers: usb_dc_stm32: Add support for all STM32 families
Add support for all STM32 families

Signed-off-by: Yannis Damigos <giannis.damigos@gmail.com>
Signed-off-by: qianfan Zhao <qianfanguijin@163.com>
2018-05-10 07:47:13 -05:00
Andrei Emeltchenko 943ca29d4b usb: dw: Fix Coverity issue with get_mps()
Fix issue with Coverity using if / else instead of switch, though it
does not affect code.

Fixes: #7257
CID: 185399

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-05-02 09:26:44 -04:00
Savinay Dharmappa 5060f4bd14 driver: usb: enable usb2.0 on intel_s1000
Change-Id: I59091c465e84f1d6ba64433b7320182d83ff9589
Signed-off-by: Savinay Dharmappa <savinay.dharmappa@intel.com>
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-05-01 16:46:41 -04:00
Andrei Emeltchenko 8d3b2fa8a9 usb: usb_dc_dw: Fix incorrect MPS return
Because of incorrectly set MPS we always got 0 returned for WRITE
transfers and ZLP were always generated for every packet.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-04-20 21:03:33 -07:00
Michael Hope 5a6271b08d usb: sam0: add the new usb_dc_ep_mps() function.
This was added as part of the USB transfer infrastructure.  Implement
for the SAM0.

Signed-off-by: Michael Hope <mlhx@google.com>
2018-03-27 19:57:38 -04:00
Andrzej Głąbek ad24576501 usb: device: nrf5: Remove support for the ACCESSFAULT event
This event is no longer exposed for the USBD peripheral,
and the newest MDK version (and consequently new nrfx HAL)
does not contain its definition and related bitfields.

Signed-off-by: Andrzej Głąbek <andrzej.glabek@nordicsemi.no>
2018-03-27 09:35:21 -04:00
Sundar Subramaniyan 120ddbc089 drivers: usb: nrf5: Fix ISO IN/OUT SOF handling
For ISOOUT transaction, check if the buffer is empty before starting
the DMA and for ISOIN case check if the buffer is available to start
the DMA for IN transaction. This handling was swapped. So, handle it
accordingly.

Signed-off-by: Sundar Subramaniyan <sundar.subramaniyan@gmail.com>
2018-03-17 18:58:06 +01:00
Sundar Subramaniyan cfdaa1dcaf drivers: usb: nrf5: Fix cdc_acm OUT endpoint read size issue
Problem:
cdc_acm sample outputs junk characters to the console when any key
is pressed. It is supposed to echo the same character as the input.

Analysis:
nRF52840 USB driver always reads 64 bytes from the USB peripheral's
local buffer irrespective of the data length. Even when 1 byte
is sent by the host, the usb driver receives as 64 bytes.

Since the maximum packet size value had been used when setting up
the EasyDMA's MAXCNT register for OUT transactions, DMA transffered
the entire 64 bytes of it's local buffer into the data RAM
irrespective of the OUT data length, containing garbage at the end
of useful payload. For some applications like hci_usb the extra
bytes were being ignored. But for cdc_acm, the entire 64 bytes
is getting echoed back displaying garbled characters on the terminal.

Fix:
For OUT endpoints, the amount of data received by USBD to its local
buffer should be read using SIZE.EPOUT[x] registers in the case of
BULK and INTERRUPT endpoints and SIZE.ISOOUT register for ISOOUT
endpoint. This value should be set to the EasyDMA maxcnt register
to DMA into RAM buffer. Fix this issue for Bulk, Interrupt and
ISOOUT endpoints.

Signed-off-by: Sundar Subramaniyan <sundar.subramaniyan@gmail.com>
2018-03-17 18:58:06 +01:00
Sundar Subramaniyan 9a195e36cd drivers: usb: nrf5: Add usb_dc_ep_mps function
This function is now required and used by usb_transfer APIs.

Signed-off-by: Sundar Subramaniyan <sundar.subramaniyan@gmail.com>
2018-03-17 18:58:06 +01:00
Loic Poulain e7fa746b0c usb: dc_dw: Do not clear RX NAK at init for transfer endpoints
Reading is managed by transfer API.

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
2018-03-16 14:45:24 -07:00
Loic Poulain 5beb183879 usb: dc_dw: Fix FIFO available space
For now tx-fifo sizes are not configured (cf usb_dw_set_fifo).
Default fifo size is 136 bytes and sending more than 136 bytes
makes the data split into incorrect chunk size.
This patch prevents this by reducing available fifo size to a
multiple of the endpoint max packet size.

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
2018-03-16 14:45:24 -07:00
Loic Poulain 9d1957fae1 usb_dc: Add usb_dc_ep_mps function
This function returns endpoint max packet size (mps).

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
2018-03-16 14:45:24 -07:00
Loic Poulain 10923173a6 Revert "usb: stm32: Introduce transfer method"
This reverts commit b23d599682.

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
2018-03-16 14:45:24 -07:00
Sundar Subramaniyan 380a25018d drivers: usbd_nrf5: Add nRF52840 USB Device Controller Driver
* Add USB device controller driver for nRF52840 SoC.
* Supports only Bulk and Interrupt endpoints for now.
* ISO endpoint support is WIP.

What's tested:
* BTUSB - LE Scanning and connection.

Known issues in btusb tests:
 * Observed momentary delays during LE scanning. This is possibly
due to hci_usb's way of calling the usb_write().

 * Sometimes, when LE scan stop command is issued, response is not
sent and as a result USB stops functioning. This is also related
to the way btusb is handling the write(). For some reason, the
btusb class handler seems to issue another data packet write before
the USB control transaction is complete.

Miscellaneous:
* Lots of TODO items to discuss and fix.

Origin: Original

Signed-off-by: Sundar Subramaniyan <sundar.subramaniyan@gmail.com>
2018-03-15 12:39:53 +01:00
Savinay Dharmappa 8d7da51827 drivers: usb: device: code cleanup
include clk.h only for system that use QMSI.

Signed-off-by: Savinay Dharmappa <savinay.dharmappa@intel.com>
2018-03-12 09:02:03 -04:00
Michael Hope f2651d0cc7 usb: sam0: add a USB device driver.
Implements a USB device driver for the SAM0 series.

Signed-off-by: Michael Hope <mlhx@google.com>
2018-03-10 08:41:39 -05:00
Yannis Damigos 899ed91506 drivers: usb_dc_stm32: Get USB configuration from DT
Use defines generated from DT.

Signed-off-by: Yannis Damigos <giannis.damigos@gmail.com>
2018-02-21 09:17:12 -06:00
Savinay Dharmappa 98d6a9928c driver: usb_dw: Move base address and irq num of usb to soc.h
base adrress and irq number moved to soc.h

Signed-off-by: Savinay Dharmappa <savinay.dharmappa@intel.com>
2018-02-07 22:55:11 -05:00
Loic Poulain b23d599682 usb: stm32: Introduce transfer method
Transfer is an important concept of USB specification.
During a transfer, several packets can be transmitted.
Today the usb API only provides ep_read and ep_write
functions but the transfer concept is missing.

This is typically ok for basic drivers which don't have
to take care of how data is transfered/splitted.
However there are some drivers like CDC EEM, in which
transfer concept is important for packet management.

Moreover, current ep-write and ep_read method have a
different implementation in usb_dc_dw and usb_dc_stm32
device drivers. For example usb_dc_dw supports only
1-data-packet transfers due to its implementation.
This can increase latency and reduce performance.

I think this is something we need to fix/improve by
implementing better transfer management.

This patch introduces usb_dc_ ep_transfer method which
can be used to configure IN/OUT transfers. This allows
to configure and request different transfer sizes and
should prevent usage of the current stm32 temporary
buffer.

This method has asynchronous and synchronous mode.
Synchronous mode waits for transfer completion before
returning. Asynchronouse mode (irq safe) configures
the transfer and returns immediately, the provided
callback will be then called on transfer completion.

This also update ep_write and ep_read stm32 implementation
to use this new method but keep their behavior unchanged
for legacy reasons.

Note that for now this method is local to stm32 device
driver, however the goal would be to expose this function
as a new USB device driver API method so that class
drivers use it. This will request same implementation in
the usb_dc_dw_driver.

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
2018-01-29 11:26:48 -06:00
qianfan Zhao cd931bb7c4 usb: stm32: add usb_dc_ep_read_wait/conitinue
usb mass example need usb_dc_ep_read_wait/continue API.
test usb mass storage with RAM DISK on stm32f4 series.

Signed-off-by: qianfan Zhao <qianfanguijin@163.com>
2018-01-29 11:26:48 -06:00
Erwin Rol 780c1efb9f drivers: usb: stm32: use Kconfig to select HAL/LL sources
Use "select USE_STM32_LL_USB/USE_STM32_HAL_PCD/USE_STM32_HAL_PCD_EX"
to select the needed STM32 HAL files, instead of editing
ext/hal/st/stm32cube/CMakeLists.txt

Signed-off-by: Erwin Rol <erwin@erwinrol.com>
2018-01-23 08:46:16 -06:00
Andrei Emeltchenko af0bf06aa3 usb: Fix USB Device dependency
USB Device stack should depend on supported drivers not on menuconfig
option.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-01-12 07:46:28 -05:00
Anas Nashif 429c2a4d9d kconfig: fix help syntax and add spaces
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-12-13 17:43:28 -06:00
Loic Poulain eb83cda770 usb: dc_dw: Improve TX perf and reliability
During large USB transfer it's pretty common to call ep_write whereas
the previous TX transfer is not achieved and so the TX FIFO space is
not available. Sleeping 20ms in this case introduce a relatively high
latency and reduce the throughput.

This can be observed when pinging the board with CDC-ECM net class.
ping reply is split into 2 USB TX transfer, the second one is only
triggered after 20ms, making ping latency > 20ms.

To fix this, just continuously read the FIFO availabilty and fire TX
as soon as possible.

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
2017-11-09 09:15:55 -06:00