Commit graph

450 commits

Author SHA1 Message Date
Andrei Emeltchenko 841dda42a0 usb: trivial: Correct coding style
Trivial style fix.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2020-01-07 21:05:44 +01:00
Andrei Emeltchenko 9618becb0f usb: usb_device: Remove old extensive logs
Make USB logging clearer removing old logs.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2020-01-07 21:05:44 +01:00
Barry Solomon 6118ca2785 usb: make usb descriptor power options configurable
Add two new kconfig options USB_SELF_POWERED and USB_MAX_POWER.
These can be set by the user to change the USB configuration descriptor.
USB_MAX_POWER can be set to any value between 0 and 250, but practically
should be 50 or 250. These values are half the ammount of mA that the
device will tell the host that it needs.
USB_SELF_POWERED sets the 7th bit in bmAttributes of the USB config
descriptor. Should be set to y if the device has its own power source
other than USB.

Signed-off-by: Barry Solomon <barry.solomon@dexcom.com>
2019-12-20 19:46:16 -05:00
Emil Obalski 939c05a7af usb: hid: Make it possible to specify HID debug level
Until now HID class derived log level from USB stack.
By this commit new Kconfig option for HID specific log
level is introduced.

Signed-off-by: Emil Obalski <emil.obalski@nordicsemi.no>
2019-12-20 19:30:22 -05:00
Johann Fischer ab346a502b usb: initialize USB descriptor earlier
Initialize USB descriptor earlier.

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2019-12-19 13:08:55 +01:00
Emil Obalski 2128750138 usb: api: Add user device status callback
By this commit user gets possibility to register USB
device satutus callback. This callback represents device state
and is added so user could know what happend to USB device.

Callback is registered by providing it to usb_enable()
USB api is extended by this callback handler.

Samples using using USB are by default provide no callback
and the usb_enable() is called with NULL parameter.

Status callback registered by hid class is deleted as now
USB device has global callback for all classes within device.

Signed-off-by: Emil Obalski <emil.obalski@nordicsemi.no>
2019-12-19 13:08:55 +01:00
Emil Obalski d65027d8c0 usb: samples: Application calling usb_enable by itself
User app is reponsible for issuing usb_enable and
making USB hardware operative.

Signed-off-by: Emil Obalski <emil.obalski@nordicsemi.no>
2019-12-19 13:08:55 +01:00
Emil Obalski e3619d50e0 usb: Add mutex to usb_enable
The purpose of this commit is to prevent user from
calling usb_enable() twice from different contexes.

If for example user configures composite device with hid
and USB uart console (CONFIG_USB_UART_CONSOLE=y)
then introduced mutex will prevent from calling
usb_enable twice and thus lead to undefined behaviour of
usb driver controller.

usb_enable shall always be called once as it refers to usb driver
and for now only one USB driver instance is supported in Zephyr.
This mechanism ensures that.

Signed-off-by: Emil Obalski <emil.obalski@nordicsemi.no>
2019-12-19 13:08:55 +01:00
Johann Fischer f75c30b2ed usb: derive USB device Serial Number String from HWINFO
Derive USB device Serial Number String from HWINFO driver.

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2019-12-18 11:12:28 +01:00
Emil Obalski 85a08da966 usb: Rename defines to match present naming convention
This commit renames two defines:
CS_INTERFACE -> USB_CS_INTERFACE_DESC
CS_ENDPOINT -> USB_CS_ENDPOINT_DESC
in order to match current naming convention when it comes
to descriptors fields.

All relevant files are updated to match renamed macros.

Signed-off-by: Emil Obalski <emil.obalski@nordicsemi.no>
2019-12-09 12:48:13 -05: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
Ulf Magnusson 87e917a925 kconfig: Remove redundant 'default n' and 'prompt' 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.

Also replace some

    config
    	prompt "foo"
    	bool/int

with the more common shorthand

    config
    	bool/int "foo"

See the 'Style recommendations and shorthands' section in
https://docs.zephyrproject.org/latest/guides/kconfig/index.html.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-12-09 16:14:50 +01:00
Johann Fischer 021ee7ade3 usb: hid core: fix call by reference
Fix call by reference.

Fixes: #20872
Coverity CID :205779

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2019-11-28 14:04:31 -05:00
Peter Bigot e563c3d89b usb: dfu: default progressive erase on Nordic
The instructions for samples/usb/dfu fail on Nordic platforms if the
erase is not progressive.  Default to enable that on Nordic.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2019-11-26 08:25:02 -05:00
Johan Hedberg d67416321e Bluetooth: hci_raw: Add support for specifying buffer headroom
The HCI transport implemented by an application using the HCI raw
interface may have its own buffer headroom requirements. Currently the
available headroom gets completely determined by the selected HCI
driver. E.g. most of the time this is the native controller driver
which doesn't reserve any headroom at all.

To cover for the needs of HCI raw users, add a new Kconfig variable
for the apps to set to whatever they need. Correspondingly, use the
maximum of the HCI driver and HCI raw headroom requirements for the
buffer pool definitions and the headroom initializations.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-11-20 19:29:06 +01:00
Peter A. Bigot 6770d1c671 usb: dfu: correct upload implementation
The routine to read the image from the device and upload it to the
host stored data in a buffer unrelated to the one transferred to the
host, resulting in a corrupt image.

Signed-off-by: Peter A. Bigot <pab@pabigot.com>
2019-11-18 13:50:43 +01:00
Johann Fischer 1c2e965569 usb: bluetooth: do not use ZLP for HCI event transfers
Linux btusb driver do not relies on ZLP to determine the
end of a transfer. Instead the data is transmitted
continuously and the driver obtains the length of a event
from the HCI Event Packet header.

Fixes: #20250

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2019-11-15 17:02:43 +01:00
Johann Fischer 0230b46ce5 usb: bluetooth: make HCI event endpoint size configurable
Make HCI event endpoint size configurable.

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2019-11-15 17:02:43 +01:00
Peter A. Bigot a58d8ebaa6 driver: uart: make deprecation effective
Several macros were documented as deprecated but lacked the
infrastructure to produce deprecation warnings.  Add the deprecation
marker, and fix the in-tree references to the deprecated spellings.

Note that one non-deprecated macro should have been deprecated, and
is, referring to a newly added line control bit.

Signed-off-by: Peter A. Bigot <pab@pabigot.com>
2019-11-07 12:44:15 -06: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
Ulf Magnusson 975de21858 kconfig: Global whitespace/consistency cleanup
Clean up space errors and use a consistent style throughout the Kconfig
files. This makes reading the Kconfig files more distraction-free, helps
with grepping, and encourages the same style getting copied around
everywhere (meaning another pass hopefully won't be needed).

Go for the most common style:

 - Indent properties with a single tab, including for choices.

   Properties on choices work exactly the same syntactically as
   properties on symbols, so not sure how the no-indentation thing
   happened.

 - Indent help texts with a tab followed by two spaces

 - Put a space between 'config' and the symbol name, not a tab. This
   also helps when grepping for definitions.

 - Do '# A comment' instead of '#A comment'

I tweaked Kconfiglib a bit to find most of the stuff.

Some help texts were reflowed to 79 columns with 'gq' in Vim as well,
though not all, because I was afraid I'd accidentally mess up
formatting.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-11-01 15:53:23 +01:00
David B. Kinder 241044f178 doc: fix misspellings in Kconfig files
Fix misspellings in Kconfig files missed during regular reviews.

Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
2019-10-30 10:24:30 +01:00
Peter Bigot e28f330a8e coccinelle: standardize k_thread create/define calls with integer timeouts
Re-run with updated script to convert integer literal delay arguments
to k_thread_create and K_THREAD_DEFINE to use the standard timeout
macros.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2019-10-09 08:38:10 -04:00
Sebastian Bøe 9d0e2cb325 cmake: Fix usb include directory organization
There are two problems with how zephyr/subsys/usb is being added to
the include path. Firstly it is using the zephyr_library_ API to
modify the zephyr library, when the zephyr_ API should have been used.

Secondly the code is located in the class directory even though it
affects the more general usb directory.

This patch fixes these issues. Using zephyr_library_ in this instance
works by accident when 'zephyr' is the current library but has not
guarantees of working in the future.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2019-10-01 19:22:02 +02:00
Andrei Emeltchenko 67795b79a2 usb: Remove extra logs
usb_handle_bos() and usb_handle_os_desc() are got invoked from
usb_handle_standard_request(), remove those unneeded logs.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2019-10-01 09:16:42 -04: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
Johann Fischer b98d8cdaa0 usb: do not check size of REQUEST_BUFFER for Data stage IN
Do not check size of REQUEST_BUFFER for Data stage IN
transactions. The check can not be done effectively because
the pointer (usb_dev.data_buf) can be changed and the actual
size of the buffer used is unknown at this point.

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2019-09-26 13:19:02 +02:00
Yannis Damigos ad3f56f044 usb_device: Fix typo in comment
Fix typo in comment

Signed-off-by: Yannis Damigos <giannis.damigos@gmail.com>
2019-09-09 13:38:41 -05:00
Johann Fischer 60c4882bad usb: fix ZLP handling for Variable-length Data Stage
ZLP flag should only be set if less data is sent
than requested by host and the length is a multiple
of wMaxPacketSize. Current implementation does not
check it correctly.

For some platforms like nRF52, this patch will not
be enough to fix the problem. The driver must be informed
about the transfer type before sending the last packet,
without changing the API, it is not possible.

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2019-09-08 22:06:48 -04:00
Yannis Damigos 6425c52e62 usb_device: Wait for write done event (in) before sending zlp
Don't send zlp immediately after last packet for EP0.
Wait for write done event (in) before sending zlp.

Signed-off-by: Yannis Damigos <giannis.damigos@gmail.com>
2019-09-08 22:06:48 -04:00
Johann Fischer ac8a4eacce usb: make number of usb_write retries configurable
Make number of usb_write retries configurable.

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2019-09-08 22:06:48 -04:00
Andrei Emeltchenko 77125eafa9 usb: device: Allow limited amount of tries for write
Set limited amount of tries to write to USB control endpoint EP0.

Fixes #16223

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2019-09-08 22:06:48 -04:00
Bartosz Sokolski 07b942f689 usb: device: limit interface bits in setup message to 8
In setup messages addressing classes, USB standard defines that wIndex
constains interface number encoded in bits 0..7. Bits 8..15
are reserved and normally set to 0. However, in Audio Class they contain
entity number. Hence the need to filter 8 bits for getting interface
number.

Signed-off-by: Bartosz Sokolski <bartosz.sokolski@nordicsemi.no>
2019-09-08 12:38:52 +02:00
Tobias Svehagen 86592e97f3 usb: cdc_acm: Fix compiler warning
Compiler warns about unused function when CONFIG_UART_LINE_CTRL is not
set.

Signed-off-by: Tobias Svehagen <tobias.svehagen@gmail.com>
2019-09-07 10:19:27 -04:00
Johann Fischer 12a11201e2 usb: cdc_acm: enable CONFIG_CDC_ACM_IAD by default
Enable CONFIG_CDC_ACM_IAD by default so that
CDC ACM class works out of the box on Windows OS.

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2019-08-29 17:14:45 +02:00
Johann Fischer 84c38cb93a usb: increase the length of the request buffer
Increase the length of the request buffer.
Current value is not enough for an average
device descriptor.

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2019-08-29 17:14:45 +02:00
Johann Fischer 666fa31857 usb: mitigate the check of request buffer length
Mitigate the check of the request buffer length because
the host may not know the real length for some responds.

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2019-08-29 17:14:45 +02:00
Johann Fischer 9ba269f580 usb: check if the request buffer is not too small
The size of the request buffer (USB_REQUEST_BUFFER_SIZE)
is configurable and depends on the needs of an application.
Check if the request buffer is not too small.

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2019-08-26 15:06:22 +02:00
Johann Fischer 28e97c7f3a usb: loopback: use stack's request buffer for control requests
Use stack's request buffer for control requests.

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2019-08-26 15:06:08 +02:00
Johann Fischer 5fb7c11446 usb: cdc_acm: update state after RESUME event
Update state after RESUME event.
Use LOG_INF for important events and log a
warning if the data is discarded.

Fixes #17488

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2019-08-23 15:47:06 +02:00
Johann Fischer 2dc7c5a46b usb: usb_descriptor: fix null pointer dereferences
Check if usb_cfg_data pointer was initialized
before endpoint descriptor section is processed.

Coverity-CID: 203473
Fixes: #18423

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2019-08-22 07:26:33 -05:00
Johann Fischer 8e9bf88d66 usb: do not disable endpoints at USB_DC_SUSPEND event
Do not disable endpoints at USB_DC_SUSPEND event.

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2019-08-07 11:22:47 +02:00
Nicolas Pitre 0aa796cbaa print format: adjust specifiers to be compatible with a 64-bit build
The size_t type is either compatible with an int on 32-bit target, or
a long on 64-bit targets. It could even be a long even on some 32-bit
targets. Let's use the z qualifier in the printf format to be compatible
with whatever flavor in use.

In case of pointers, let's just use %p with pointers directly and
avoid casts altogether.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2019-07-11 20:12:26 -07: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 5eb90ec169 cleanup: include/: move misc/__assert.h to sys/__assert.h
move misc/__assert.h to sys/__assert.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 7435e5e089 cleanup: include/: move ring_buffer.h to sys/ring_buffer.h
move ring_buffer.h to sys/ring_buffer.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 d1b2718687 cleanup: include/: move uart.h to drivers/uart.h
move uart.h to drivers/uart.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 fe051a9055 cleanup: include/: move flash.h to drivers/flash.h
move flash.h to drivers/flash.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 f641d099cc cleanup: include/: move disk_access.h to disk/disk_access.h
move disk_access.h to disk/disk_access.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 83508a5677 cleanup: include/: move flash_map.h to storage/flash_map.h
move flash_map.h to storage/flash_map.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
Johann Fischer abaeaed2af usb: sort usb config data by section
USBD_CFG_DATA_DEFINE macro has not consider that a class
could have more than one set of usb_cfg_data struct.
If a class has more than one set of usb_cfg_data
then they should be sorted the same way like by
USBD_DEVICE_DESCR_DEFINE macro.

Fixes: #16240

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2019-06-27 12:18:05 +02:00
Anas Nashif f2cb20c772 docs: fix misspelling across the tree
Found a few annoying typos and figured I better run script and
fix anything it can find, here are the results...

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-19 15:34:13 -05:00
Loic Poulain d79bbc6d4d usb: netusb: cdc_eem: Fix Interface select
Parameter of set_interface_status is no more the interface index
but a pointer to interface descriptor.

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
2019-06-17 16:25:06 -04: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
Andrei Emeltchenko 26b514dec4 usb: usb_descriptor: Trivial syntax correct
Trivial function name fix.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2019-06-05 11:44:17 +02:00
Johann Fischer 28f2dc6c69 usb: usb_device: fix handlers call for secondary descriptor
Fix handlers call for secondary descriptor.
USB class like DFU has two sets of descriptors. In the handler
look up function, wind the pointer forward to the range
of the current descriptor.

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2019-05-27 09:25:06 -04:00
Andrei Emeltchenko a68d404833 usb: dfu: Remove old composite configuration
Use new method for USB config and enable.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2019-05-27 09:25:06 -04:00
Andrei Emeltchenko 3880a42375 usb: Align legacy and composite interface
Remove duplicated execution path for composite configuration, USB
device stack initialization is done inside stack for both cases.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2019-05-27 09:25:06 -04:00
Andrei Emeltchenko b3355c7924 usb: device: Remove unused variable
Remove unused variable.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2019-05-27 09:25:06 -04:00
Aurelien Jarno e059d5aa61 usb: simplify request handlers code
Now that Standard, Class and Vendor request handlers are using the same
buffer, we do not need to keep and array installed request data pointer.
This simplifies the code.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2019-05-27 09:25:06 -04:00
Andrei Emeltchenko 24142d0749 usb: Set correct default buffer size for RNDIS
Set correct USB_REQUEST_BUFFER_SIZE for USB_DEVICE_NETWORK_RNDIS.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2019-05-27 09:25:06 -04:00
Aurelien Jarno 327f61076a usb: merge all request handler buffers
Now that we have merged the class and vendor request buffers into the
USB device code, we can also merge the standard request buffer. We just
need to ensure it is at least 8 bytes, by using the range option in
Kconfig. The 64KiB limit is arbitrary.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2019-05-27 09:25:06 -04:00
Aurelien Jarno 819e749ccd usb: move the request handler buffer to the USB device code
In order to unify the legacy and composite code, move the class and
vendor request handler buffer into the USB device code, just like in
composite mode. The option is renamed from USB_COMPOSITE_BUFFER_SIZE
into USB_REQUEST_BUFFER_SIZE and also replaces the USB_DFU_MAX_XFER_SIZE
and USB_HID_MAX_PAYLOAD_SIZE options.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2019-05-27 09:25:06 -04:00
Andrei Emeltchenko a95f6385f2 usb: device: Do not return error if ep already enabled
Fixes USB3CV Tool tests. One case is enabling endpoints with Set
Interface after Set Configuration. In this case we report warning and
continue without returning error.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2019-05-22 11:19:49 +02:00
Andrei Emeltchenko 1370f16287 usb: device: Disable endpoints on disconnect and suspend
Disable endpoints on following events: USB_DC_DISCONNECTED
and USB_DC_SUSPEND.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2019-05-22 11:19:49 +02:00
Andrei Emeltchenko 83f625b4cc usb: device: Add debug logs catching re-enable failures
Add extra logs catching problem with re-enabling endpoints.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2019-05-22 11:19:49 +02:00
Andrei Emeltchenko 437ee504fa usb: device: Cancel all transfers on disconnect
Cancel all usb transfers when receiving USB_DC_DISCONNECTED.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2019-05-22 11:19:49 +02:00
Andrei Emeltchenko f206170c65 usb: device: Do not call callback when transfer is cancelled
Only call callback when transfer is not cancelled.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2019-05-22 11:19:49 +02:00
Andrei Emeltchenko bf76b2acc3 usb: device: Add transfer cancel helper
Add usb_cancel_transfers() helper to cancel all ongoing transfers.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2019-05-22 11:19:49 +02:00
Marcin Szymczyk 8f0c3b80cf usb: cdc_acm: reset to default after disconnect
Return to default values after USB is reset or disconnected.

Signed-off-by: Marcin Szymczyk <Marcin.Szymczyk@nordicsemi.no>
2019-05-21 08:23:46 -04:00
Marcin Szymczyk 2eb99ea38c usb: cdc_acm: fix typo in CDC_ACM_DEFAULT_BAUDRATE
From CDC_ACM_DEFAUL_BAUDRATE to CDC_ACM_DEFAULT_BAUDRATE.

Signed-off-by: Marcin Szymczyk <Marcin.Szymczyk@nordicsemi.no>
2019-05-21 08:23:46 -04:00
Marcin Szymczyk 3c3e267d72 usb: add zero-length packet after MPS-sized IN transaction
Send ZLP when host asks for a bigger length and the last chunk
is wMaxPacketSize long, to indicate the last packet.

Signed-off-by: Marcin Szymczyk <Marcin.Szymczyk@nordicsemi.no>
2019-05-12 15:15:08 -04:00
Marcin Szymczyk b1f3825ea3 usb: cdc: add option to force IAD
Interface Association descriptor has to be used with Windows 7.
Add CONFIG_CDC_ACM_IAD option to force its usage, disabled by default.

Signed-off-by: Marcin Szymczyk <Marcin.Szymczyk@nordicsemi.no>
2019-05-09 08:20:34 -04:00
Marcin Szymczyk e5cbe6a9e7 usb: cdc: Add unique PIDs for each sample
Unique PID is required for each sample in order
to be recognized by host.

When creating a new sample:
- Add USB_PID_<SAMPLE_NAME>_SAMPLE
  in samples/subsys/usb/usb_pid.Kconfig
- Create Kconfig file in your sample's subdirectory, containing:
  config USB_DEVICE_PID
	default USB_PID_<SAMPLE_NAME>_SAMPLE

  source "Kconfig.zephyr"

Signed-off-by: Marcin Szymczyk <Marcin.Szymczyk@nordicsemi.no>
2019-05-09 08:20:34 -04:00
Andrei Emeltchenko 98c8a9517d usb: cdc_acm: Refactor USB serial code
Add TX ring buffer, change USB API to transfer API.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2019-05-07 23:11:44 -04:00
Andrei Emeltchenko 2c672b92c8 usb: device: Add usb_transfer_is_busy() function
Add usb_transfer_is_busy() function to check if there is ongoing
transfer.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2019-05-07 23:11:44 -04:00
Johann Fischer 42bdcccd97 usb: usb_dfu: do not set bwPollTimeout dynamically
Partially revert commit ea177e785ca3
("usb: dfu: set bwPollTimeout dynamically")

Introduced fix does not work proper because there is no way to be
sure that a control stage had success before start erase process.
Instead IMG_ERASE_PROGRESSIVELY configuration should be used
if the erase of the flash takes longer time.

resolves: #15497

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2019-05-07 08:38:24 -04:00
Andrei Emeltchenko b4204631ee usb: Add log for endpoint assignment
Log fixed endpoint address.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2019-05-06 19:00:02 -04:00
Andrei Emeltchenko 3183c103b9 usb: Fix automatic assignment endpoints
Fix endpoints are not assigned correctly.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2019-05-06 11:14:24 +02:00
Andrei Emeltchenko c77e142fd5 usb: device: Handle EAGAIN for device transfer
Handle EAGAIN for the transfer.

Fixes #13799

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2019-05-06 11:14:24 +02:00
Johann Fischer 714c8ff28e usb: usb_device: fix set configuration request
Fix set configuration request for a configuration without
specific endpoint like USB DFU class.

The changes introduced in commit 2b58594e90
("usb: device: Use set_endpoint helper for set_config")
does not take into account that a configuration could only
contain control endpoint.

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2019-05-03 14:30:24 -04:00
Dennis Wildmark 791def84b1 usb: bluetooth: l2cap buffer size now configurable
Added check to see if CONFIG_BT_CTLR_TX_BUFFER_SIZE is defined,
and use that as the BT_L2CAP_MTU if that is the case. Otherwise,
use the previously hard coded MTU size (64). This enables users
to configure the MTU, enabling longer transfers.
The fix was inspired by how this is solved in
samples/bluetooth/hci_uart/src/main.c

Tested on nrf52840_pca10056.

Signed-off-by: Dennis Wildmark <dennis.wildmark@assaabloy.com>
2019-04-29 13:40:18 +03: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
Andrei Emeltchenko 0d3082cbfc usb: device: Code cleanup
Add missing braces and simple cleanup.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2019-04-28 12:22:23 -04:00
Andrei Emeltchenko e2d1c02770 usb: cdc_acm: Use UTIL_LISTIFY and device count macro
Use new method for defining USB CDC ACM devices using UTIL_LISTIFY and
device count from menuconfig.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2019-04-28 12:22:23 -04:00
Andrei Emeltchenko fbd2713431 usb: hid: Use UTIL_LISTIFY and device count macro
Use UTIL_LISTIFY and Kconfig device count template for specify number
of HID Devices.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2019-04-28 12:22:23 -04:00
Andrei Emeltchenko e79e4d9f1f usb: Add Kconfig template for DEVICE_COUNT
DEVICE_COUNT for some USB classes means how many instances of the
class can be supported by USB stack.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2019-04-28 12:22:23 -04:00
Andrzej Puzdrowski b50fe237f9 usb/class/usb_dfu: support progressive image erase
Disable bulk slot image erase when progressive erase is on.
Erase of image bank is performed by image collection procedure
progressively.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2019-04-28 12:20:01 -04:00
Andrei Emeltchenko 42b92e254e usb: device: Use set_endpoint helper
Use helper set_endpoint() for endpoint configuration.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2019-04-26 03:25:46 -07:00
Andrei Emeltchenko 2b58594e90 usb: device: Use set_endpoint helper for set_config
Refactor code making set_endpoint() helper which check validity of
input parameters.

Fix bug with usb_set_configuration() always returning true.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2019-04-26 03:25:46 -07:00
Marcin Szymczyk ea7afdde8f usb: cdc_acm: SerialState notification full support
Added bBreak, bRingSignal, bFraming, bParity and bOverRun
handling in cdc_acm_line_ctrl_set.
Reference: Chapter 6.5.4 of Universal Serial Bus Communications Class
Subclass Specification for PSTN Devices rev 1.2

Signed-off-by: Marcin Szymczyk <Marcin.Szymczyk@nordicsemi.no>
2019-04-19 13:36:32 -05:00
Johann Fischer a05ef2559d usb: dfu: set bwPollTimeout dynamically
Set bwPollTimeout for DFU_GETSTATUS request dynamically.
For now, adjust bwPollTimeout only during DNLOAD stage.

Fixes: #8734

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2019-04-16 08:55:51 -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 4c9ea1e370 usb: netusb: ecm: Enable netusb for the right iface/alt_set
Only enable netusb for the right configuration of interface and
alt_setting.

Fixes #13560

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2019-04-11 13:35:24 -04:00
Andrei Emeltchenko 1a1c518c25 usb: device: Change iface set callback parameters
Include to the callback parameters also alt_setting to be able to make
right choice for ECM.

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 721f3d1cd0 usb: Refactor USB status callback
Merge cb_usb_status_composite and cb_usb_status and use common
forward_status_cb for both composite and normal devices.

Fixes #14882

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2019-04-05 12:23:57 +02: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