Commit Graph

87 Commits

Author SHA1 Message Date
morris
66e6e7c925 Merge branch 'feat/usb_host_set_device_config_v5.1' into 'release/v5.1'
USB Host: Add enumeration callback filter (backport v5.1)

See merge request espressif/esp-idf!28548
2024-03-05 09:47:56 +08:00
Peter Marcisovsky
e87bb08216 feat(us/host): set device cfg during enumeration
- user callback funciton to set device configuration
      as a part of usb_host_install
    - callback provides device descriptor of a device being enumerated
    - user can set which cfg descriptor the USB device will be set with
    - user can filter device enumeration
    - Kconfig menu to enable callback function
    - usb_host_lib example demonstration
2024-03-01 10:15:02 +01:00
Darian Leung
ef698857d1
fix(usb): Fix bug where usbh_process() misses an event
This commit fixes a bug where if multiple concurrent USBH API calls trigger
multiple events on the same device, some events will be lost. As a result,
those lost events don't get processed by the subsequent usbh_process() call.
2024-03-01 09:42:57 +08:00
Marius Vikhammer
929a8449bd Merge branch 'feature/usb_host_collective_backport_v5.1' into 'release/v5.1'
USB Host: Collective backport to v5.1

See merge request espressif/esp-idf!28096
2024-03-01 09:28:23 +08:00
Marius Vikhammer
48777e7983 Merge branch 'change/usb_host_minor_optimizations_v5.1' into 'release/v5.1'
change(usb/host): Remove unecessary features (v5.1)

See merge request espressif/esp-idf!27594
2024-02-28 17:20:18 +08:00
Darian Leung
2ba1790ef6
refactor(usb): Deprecate CONFIG_USB_OTG_SUPPORTED, use SOC_USB_OTG_SUPPORTED instead
Previously, USB build dependencies used the CONFIG_USB_OTG_SUPPORTED. However,
they could depend on `soc_caps.h` instead.
2024-02-28 16:09:53 +08:00
Darian Leung
d837836f84
refactor(hal/usb): Rename usb_fsls_phy API to match header/source names
Note: Also fixed some formatting issues in usb_wrap_struct.h
2024-02-28 16:09:52 +08:00
Darian Leung
148cc6e75d
refactor(hal/usb): Rename usb_phy files to usb_fsls_phy
This commit renames USB PHY related HAL files from "usb_phy_xxx" to
"usb_fsls_phy_xxx" since they are only designed to support Full-Speed/Low-Speed
Serial USB PHYs. This renmaing is done to accommodate future USB PHYs that use
other PHY interfaces (e.g., UTMI, ULPI etc).
2024-02-28 16:09:52 +08:00
Darian Leung
dc27d5456f
refactor(usb/host): reformat code with astyle 2024-02-28 16:09:50 +08:00
Tomas Rezucha
d26320d8a1
fix(usb/host): Correctly parse bInterval field in HighSpeed EP descriptors
For LS and FS interrupt endpoint: interval = bInterval
For isochronous and HS interrupt endpoint: interval = 2^(bInterval-1)
2024-02-28 16:09:50 +08:00
Tomas Rezucha
388360cc5a
fix(usb/host): Correctly parse MPS fields in HighSpeed EP descriptors
Bits [11,12] in HighSpeed periodic endpoints specify
the number of additional transaction opportunities per microframe
2024-02-28 16:09:49 +08:00
Darian Leung
507880fa32
change(usb/host): Remove some handler function event flags
This commit removes internal event flags in the USB Host Library event handling
functions (i.e., usb_host_lib_handle_events() and usb_host_client_handle_events()).

Previously, these flags were added to reduce the number of times semaphores
were given. However, these flags were removed as the performance gain is
negligible and made the logic more complicated.

For usb_host_client_handle_events(), the following flags were removed:

- Remove 'events_pending' flag. The semaphore is now always given
- Remove 'blocked' flag. The 'handling_events' flag is already sufficient
- Critical sections are now shortened due to simplication of semaphore usage.

For usb_host_lib_handle_events(), the following flags were removed:

- Remove 'process_pending' flag. The semaphore is now always given
- Renamed 'blocked' flag to 'handling_events'
2024-02-27 18:16:00 +08:00
Darian Leung
bfc8c3a154
change(usb/host): Remove data buffer headers from URBs
This commit removes the ability to reserve a header in the data buffer of an
allocated URB. The header was required for a now defunct implementation of a
synchronous USB Host library API. Thus, headers are no longer required in
URB data buffers.
2024-02-27 18:15:59 +08:00
Tomas Rezucha
cb4e90ca6e refactor(usb/host): Move FIFO size configuration to HAL layer
The logic of calculating FIFO sizes is DWC OTG specific.
We move it to the HAL layer to provide better abstraction in the HDC layer.
2023-12-21 10:45:21 +01:00
Tomas Rezucha
325205faee refactor(usb/host): Make private hal types USB_DWC specific 2023-12-21 10:45:04 +01:00
Tomas Rezucha
d9223c6d91 feat(usb/host): Add High Speed enumeration types 2023-12-21 10:35:31 +01:00
Roman Leonov
e950cdf549 fix(usb/host): remove bInterval verification during pipe opening for INTR and ISOC EPs 2023-11-28 22:00:54 +01:00
Tomas Rezucha
609628e139 fix(usb/host): Do not abort on string descriptor overflow
Some devices return full LANGID table, even if short LANGID table was requested.
No memory overflow occurs, because we have allocated enough memory for transfers to the
default pipe. So we can ignore the error and continue with string desc fetching.
2023-11-28 22:00:54 +01:00
Darian Leung
fdab2d0c32 refactor(hal/usb_dwc): Add DWC OTG configuration values
This commit adds a subset of the DWC OTG configuration values to the
'usb_dwc_ll.h' file. Only relevant configuration values have been added.

Some DWC OTG releated constants have also been moved from 'usb_dwc_hal.h'
to 'usb_dwc_ll.h' and renamed.
2023-11-28 22:00:54 +01:00
wuzhenghui
6ae596c764
fix(esp_hw_support): fix lightsleep current leakage on usb-phy controlled pad 2023-11-16 20:03:30 +08:00
Roman Leonov
75b1a135ad bugfix(usb/host): Fix transfer direction determination during argument checking for regular EP transfer 2023-09-13 21:51:24 +02:00
morris
cd979e293c Merge branch 'bugfix/usb/host/urb_compliance_verification_add_v5.1' into 'release/v5.1'
[USB Host] added URB check args and transfer check compliance for regular EP transfer submit (v5.1)

See merge request espressif/esp-idf!25467
2023-08-25 23:17:32 +08:00
Roman Leonov
29a38ceeca usb_host: added URB check args and transfer check compliance for regular EP transfer submit 2023-08-24 12:02:49 +08:00
Darian Leung
6b585fe542 usb_host: Fix coverity issues with hcd_install()
- Use single "err_ret" variable for returning errors
- Simplify bail out procedure by using more labels
2023-08-24 12:01:50 +08:00
Darian Leung
ff8c4f79d2 usb_host: Run formatting script 2023-07-15 12:56:45 +02:00
Darian Leung
a3e4e9c772 usb_host: Fix spelling errors 2023-07-15 12:56:45 +02:00
Darian Leung
b891aa0443 usb_host: Refactor USBH and USB Host Library calls to HCD
This commit refactors the USBH and the USB Host Library in the following ways:

- USBH now presents an abstraction of an endpoint (via usbh_ep_handle_t)
    - Added separate functions to enqueue/dequeue URBs to a particular endpoint
    - USB Host Library no longer calls HCD API directly. Calls USBH endpoint API
      instead.
- Renamed "notif_cb" to "proc_req_cb" (Processing Request Callback)
    - This is to avoid confusion with FreerTOS task notifications and Host
      Library client event notifications.
    - The processing functions of each layer (i.e., "xxx_process()") request
      calls via the "proc_req_cb"
    - The main handling function (i.e., usb_host_lib_handle_events()) is
      responsible for calling the required "xxx_process()" of each layer
2023-07-15 12:56:45 +02:00
Roman Leonov
b188085ce8 usb_host: better debugging information during hcd_pipe_alloc() when usb_host_interface_claim() is being fulfiled. 2023-07-13 12:42:00 +02:00
morris
0e68d6fb29 usbh: fix invalid assert on desc_status 2023-06-26 07:07:52 +00:00
Tomas Rezucha
f1a2bc777e usb_host: Use up-to-date syntax in pytest 2023-04-21 15:45:42 +08:00
Darian Leung
71786a7413 usb_host: Update docs and comments regarding first configuration enumeration
This commit updates some comments and documentation regarding changes made in
PR https://github.com/espressif/esp-idf/pull/11113.
2023-04-21 12:49:18 +08:00
Jason
4102628a3b Fix usb enumeration stage error for some device 2023-04-21 12:49:18 +08:00
Roman Leonov
be899f6653 usb_host: add recovering interval after SetAddress(). Possibility to change constant delay value via menuconfig.
Closes https://github.com/espressif/esp-idf/issues/10444
Closes https://github.com/espressif/esp-idf/issues/10718
2023-03-09 08:11:05 +01:00
Tomas Rezucha
31ff3bc0c2 usb_host: Fix interface descriptor parsing
Previously the USB host driver did not accept interface number greater or equal bNumInterfaces, even though these are valid interface numbers
2023-02-10 15:49:11 +01:00
Saurabh Kumar Bansal
7010349a9a usb_host: Hub driver skips fetching string descriptors if their index is 0
When a USB does not support a particular string dsecriptor (e.g.,
manufacturer, product, and serial number), the string descriptors corresponding
index will be set to 0 in the device descriptor (e.g., iManufacturer, iProduct,
iString).

Previously, the Hub driver would always attempt to fetch the all three string
descriptors, thus leading an error in CHECK_SHORT_SER_STR_DESC if the device
did not support the descriptor.

This commit fixes the Hub drvier by skipping the enumeration stages of a
particular descriptor if its index is 0 (i.e., not supported by the device).
2023-02-08 23:12:54 +05:30
Darian Leung
6ae151db8c usb_host: Fix error when fetching LANGID table
USB devices may support string descriptors in multiple languages. The supported
languages are stored in a LANGID table, which itself is a string descriptor at
index 0.

When fetching the LANGID table itself, the USB 2.0 specification does not
specify what LANGID to use, thus the Hub driver would use the default LANGID
"ENUM_LANGID". However, this would cause some devices to stall.

This commit fixes the issue by always requesting the LANGID table itself using
a LANGID of 0.
2023-02-08 22:36:01 +08:00
Darian Leung
c2bc34ee84 usb: Fix incorrect bmRequestType direction flag in USB Host Library
usb_host_transfer_submit_control() uses the incorrect bmRequestType direction
flag. Therefore, when doing a transfer check, all transfers were mistakenly
treated as OUT transfers (only affects transfer check and not actual transfer).
2022-12-06 18:10:45 +08:00
Tomas Rezucha
7ae5705977 Merge branch 'feature/usb_v5_update' into 'master'
usb: Run usb_host tests in CI

See merge request espressif/esp-idf!19468
2022-12-01 15:29:01 +08:00
Tomas Rezucha
a0dacf826f usb: Don't access uninit pointer if usbh_install fails 2022-11-30 18:48:31 +00:00
Tomas Rezucha
645592e157 usb: Refactor USB Host tests
* USB tests migrated to pytest
* Error messages improved
* Configurable for different mock devices
2022-11-30 18:12:54 +01:00
Omar Chebib
cd21058097 C/Cxx: unify static assertions with the macro ESP_STATIC_ASSERT
Closes https://github.com/espressif/esp-idf/issues/9938
2022-11-21 16:18:08 +08:00
Darian Leung
4e84212077 usb_host: Test host library inflight transfer resubmission check
This commit updates the USB Host Library unit tests to test that resubmitting
an inflight transfer will return an error.
2022-10-31 13:56:59 +08:00
Darian Leung
e17e066828 usb_host: Add check to prevent submitting already inflight transfers
This commit adds a simple flag/check in the USB Host Library that prevents
users from submitting a transfer that is already inflight.

- A transfer is considered inflight as soon as it is submitted by calling
usb_host_transfer_submit() or usb_host_transfer_submit_control()
- An inflight transfer remains inflight up until right before its callback
is called by one of the USB Host Library handler functions.

Closes https://github.com/espressif/esp-idf/issues/8748
2022-10-31 13:56:59 +08:00
Tomas Rezucha
27078ac34c usb_host: Fixed incorrect opening devices from multiple clients
1. During USBH device open both queues (idle and pending) must be checked.
2. Don't overwrite already allocated endpoints
2022-10-31 13:56:44 +08:00
Tomas Rezucha
dc705312a3 usb: Allow settings of all signals in usb_phy
Until now, only usb_phy signals for external PHY were defined.
This is now extended with all OTG signals.
2022-10-18 09:18:29 +02:00
Darian Leung
d333833f59 usb_host: Rename struct/ll/hal symbols to use "usb_dwc" prefix
Following the file renaming to use the "usb_dwc" prefix, this commit
updates the symbol names of those files to use the "usb_dwc" as well.

Some LL functions were also renamed so that the register name is
mentioned.
2022-09-16 16:45:26 +08:00
Darian Leung
d8d4e3acb0 usb_host: Rename struct/ll/hal files to use "usb_dwc" prefix
This commit updates the DWC_OTG based struct/ll/hal file names to
use the prefix "usb_dwc". This naming scheme reduces ambiguity if
another USB controller implementation is added.

As a result, "hcd.c" has been renamed to "hcd_dwc.c"
2022-09-16 16:45:26 +08:00
Darian Leung
89f828ee02 usb_host: Fix incorrect memset() usage in HCD
This commit fixes incorrect usage of memset() in the HCD's various
_buffer_parse_...() functions. The memset was not clearing the qtd lists, and
were simply setting the first qtd to a non zero value (i.e., the length of
the QTD list).

However, no bug occurred as the subsequent _buffer_fill_...() functions would
overwrite the QTD list anyways.
2022-09-05 20:15:03 +02:00
Tomas Rezucha
dfdb814644 usb: Remove -Wno-format compile option 2022-09-05 20:14:56 +02:00
Ivan Grokhotkov
401c10ecfb build system: re-add -Wno-format as private flag for some components 2022-08-03 16:42:47 +04:00