Commit Graph

73 Commits

Author SHA1 Message Date
Tomas Rezucha
02fdd5f60e fix(usb/host): Decode error flags in ISOC transfers 2024-07-10 20:44:32 +08:00
Darian Leung
8277243522
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 14:24:39 +08:00
Roman Leonov
e50593662f fix(usb/host): remove bInterval verification during pipe opening for INTR and ISOC EPs 2023-11-24 16:26:08 +01:00
Tomas Rezucha
9cdd6ac5f1 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-24 16:25:54 +01:00
Darian Leung
ce351790a8 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-24 16:25:02 +01:00
wuzhenghui
ead822e6ee
fix(esp_hw_support): fix lightsleep current leakage on usb-phy controlled pad 2023-11-23 10:21:02 +08:00
Roman Leonov
8fbf4ba605 bugfix(usb/host): Fix transfer direction determination during argument checking for regular EP transfer 2023-09-13 21:53:28 +02:00
Marius Vikhammer
6bb1e32782 Merge branch 'bugfix/usb/host/urb_compliance_verification_add_v5.0' into 'release/v5.0'
[USB Host] added URB check args and transfer check compliance for regular EP transfer submit (v5.0)

See merge request espressif/esp-idf!25469
2023-08-23 19:09:17 +08:00
Roman Leonov
af45a6d40d usb_host: added URB check args and transfer check compliance for regular EP transfer submit 2023-08-22 16:31:37 +08:00
Darian Leung
a4fa0019ec 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-22 15:31:40 +08:00
Darian Leung
aeef81cde7 usb_host: Run formatting script 2023-07-28 10:39:37 +02:00
Darian Leung
3c7776cd58 usb_host: Fix spelling errors 2023-07-28 10:36:41 +02:00
Darian Leung
f5f3196c01 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-28 10:36:41 +02:00
morris
92ca847730 usbh: fix invalid assert on desc_status 2023-06-26 07:08:04 +00:00
Jiang Jiang Jian
899925e66b Merge branch 'feature/usb_host_interface_claim_debug_info_v5.0' into 'release/v5.0'
USB Host: better debugging information during usb_host_interface_claim() (backport v5.0)

See merge request espressif/esp-idf!23446
2023-06-13 10:15:42 +08:00
Roman Leonov
424b5c32d1 usb_host: better debugging information during hcd_pipe_alloc() when usb_host_interface_claim() is being fulfiled. 2023-04-25 17:05:17 +02:00
Darian Leung
b79cdd7e54 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:50:00 +08:00
Jason
62e1e5b765 Fix usb enumeration stage error for some device 2023-04-21 12:50:00 +08:00
Roman Leonov
35068ee7b9 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-10 12:40:01 +01:00
Saurabh Kumar Bansal
75b7202d71 Merge branch 'bugfix/usb_host_hub_enumeration_string_handling_v5.0' into 'release/v5.0'
USB Host: Fix string descriptor handling by the hub driver during enumeration (backport v5.0)

See merge request espressif/esp-idf!22324
2023-02-17 21:22:59 +08:00
Saurabh Kumar Bansal
2b665ee327 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-13 17:05:11 +05:30
Darian Leung
6e9500ad13 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-13 17:04:46 +05:30
Tomas Rezucha
3f1cff699d 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-13 17:03:59 +05:30
Darian Leung
cc159dfc5b 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).
2023-01-09 17:56:06 +08:00
Tomas Rezucha
05f30c1052 usb: Refactor USB Host tests
* USB tests migrated to pytest
* Error messages improved
* Configurable for different mock devices
2023-01-09 17:55:20 +08:00
Darian Leung
8d85a76a74 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.
2023-01-09 17:48:09 +08:00
Darian Leung
da91dbccfa 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"
2023-01-09 17:47:42 +08:00
Omar Chebib
0714847552 C/Cxx: unify static assertions with the macro ESP_STATIC_ASSERT
Closes https://github.com/espressif/esp-idf/issues/9938
2022-12-19 15:06:15 +01:00
Tomas Rezucha
823c8d4e77 usb: Don't access uninit pointer if usbh_install fails 2022-12-01 08:33:22 +01:00
Darian Leung
2dc3664075 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-11-07 13:41:46 +08:00
Darian Leung
9670402e1c 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-11-07 13:41:41 +08:00
Tomas Rezucha
9e145c5d30 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-11-07 13:41:35 +08:00
Tomas Rezucha
125ff0050e 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-25 06:44:55 +02:00
Darian Leung
d75037cc57 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-08 14:05:58 +02:00
Tomas Rezucha
c8585267ab usb: Remove -Wno-format compile option 2022-09-08 14:05:19 +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
Nicholas Palmer
0f645e59b6 usbh_print_intf_desc prints wrong value for tbInterfaceClass (IDFGH-9000) 2022-05-21 15:54:21 -07:00
Marius Vikhammer
c8617fe965 docs: fix all doxygen warnings
Doxygen warnings would previously not result in a failed pipeline.
Fixed this as well as all current warnings.
2022-05-12 14:50:03 +08:00
Ivan Grokhotkov
708e99497b
global: add dependency on esp_timer component and include esp_timer.h
Some components were including esp_timer.h without declaring a
dependency on esp_timer component. This used to work due to a
transitive public dependency on esp_timer from freertos component.
Add explicit dependencies where needed.
Also some source files were using esp_timer functions without
including the header file. This used to work because esp_timer.h was
included from freertos port header file. This commit adds esp_timer.h
includes where needed.
2022-04-25 18:39:23 +02:00
morris
29e9b5b46a hw_support: move periph_ctrl from driver to hw_support 2022-03-29 11:53:31 +08:00
Tomas Rezucha
e3ba980d11 usb_host: Use USB_Host library calls for desc printing 2022-03-21 18:34:25 +01:00
Omar Chebib
2571aaf3c9 G0: target component (components/esp32*) doesn't depend on driver anymore 2022-03-02 04:21:00 +00:00
Ivan Grokhotkov
9a7d9b59c1 usb: mark global variable declared in header 'extern' 2022-01-27 11:00:09 +07:00
Martin Valik
022fc12ed1 Bugfix: make wTotalLength uint16_t to avoid truncation 2022-01-17 13:43:37 +01:00
Darian Leung
ada1c9c5b8 usb: Add USB Host Library documentation
This commit adds the USB Host Library documentation and fixes some nitpicks
in the Host Stack types.

Closes https://github.com/espressif/esp-idf/issues/6408
2022-01-06 15:15:32 +08:00
Darian Leung
b6dfadb168 usb: Update USB Host Library
This commit updates the USB Host Library as follows:

- usb_helpers.h
    - Removed dependency on USB Host Library API
    - Added function to print string descriptors
- usbh
    - Fixed bug where an interface/endpoint could be claimed/allocated multiple times
    - Removed redundant device ref_count change
- Added unit test for USB Host Library API usage
2022-01-06 15:14:10 +08:00
Darian Leung
22c152c388 usb: Hub Driver and USBH recover port automatically after disconnection
This commit updates the Hub Driver and USBH as follows:
- Updated communication mechanism between Hub Driver and USBH
    - USBH notifies the Hub Driver via Hub request callback (usbh_hub_req_cb_t)
    - Hub Driver notifies the USBH via usbh_hub_pass_event()
- Hub Driver now defers all event handling to hub_process.
- Hub Driver and USBH will now automatically recover the port after a disconnected
    device has been closed.
- Fixed incorrect assert in usbh_dev_close()
2022-01-06 15:12:16 +08:00
Darian Leung
1aad12468a usb: Hub Driver Update and Refactor
Hub Driver is refactored as follows:

This commit update and refactors the Hub Driver as follows:

- Refactored enumeration state machine and stage functions
    - Enumeration stage is now incremented
    - Combined transfer stages of enumeration into common functions
- Comments updated
- Fixed usbh_hal_disable_debounce_lock() that would cause root_port_handle_events()
    to fail the HCD_PORT_CMD_RESET call because the previous port connection interrupt
    was not cleared.

The following features were added to the Hub Driver

- Enumeration config descriptor is now fetched in two separate stages
    - Header is fetched first to determine the wTotalLength of the descriptor
    - Fetching the full descriptor will request exactly wTotalLength bytes
    - This works around some non-compliant devices that will babble/return zero
        when requesting a length > wTotalLength
    - Closes https://github.com/espressif/esp-idf/issues/7799
- Enumeration now stores string descriptors
    - The Manufacturer, Product, and Serial Number string descriptors are
        now read and stored during enumeration
    - String descriptors are now part of usb_device_info_t
- Added unit test to test enumeration
2022-01-06 15:11:13 +08:00
Darian Leung
854127a57c usb: USB Host stack uses USB PHY driver
This commit updates the USB Host stack to use the USB PHY driver. The
USB PHY and the OTG Controller should now both be setup/deleted using
usb_new_phy() and usb_del_phy() respectively.

- The hcd_install() now expects the USB PHY and OTG Contorller to be
    already setup before it is called
- usb_host_install() now has an option to skip calling usb_del_phy() if
    the user wants to setup their own USB PHY (e.g., in the case of using
    and external PHY).
- CDC-ACM and MSC examples/test updated to use internal PHY

Closes https://github.com/espressif/esp-idf/issues/8061
2022-01-06 15:09:39 +08:00
Darian Leung
5a2ef15565 usb: HCD multiple fixes
This commit fixes the following bugs in the HCD

- HCD control pipes fill incorrect transfer size

_buffer_fill_ctrl() would fill the transfer descriptors length with
wLength instead of transfer->num_bytes. Therefore, the remaining length
would be incorrect when a control transfer requests more bytes than are
available.

- Fix USB_TRANSFER_FLAG_ZERO_PACK behavior

The previous behavior of USB_TRANSFER_FLAG_ZERO_PACK was incorrect, and did not
support interrupt pipes. A zero length packet can now be added to Bulk/Interrupt
OUT transfers where the length is a multiple of the endpoint's MPS.

- Fixed HCD port suspend and resume test case

Halting a control pipe mid control transfer can lead some test devices to get stuck
2022-01-06 15:07:56 +08:00