Commit Graph

178 Commits

Author SHA1 Message Date
morris
b4baef0e47 Merge branch 'fix/usb_phy_pull_override_backport_v5.3' into 'release/v5.3'
fix(usb_phy): Removed pad pull override config for Full-speed (backport to v5.3)

See merge request espressif/esp-idf!36775
2025-04-16 10:21:11 +08:00
morris
f1bc85de12 Merge branch 'fix/usb_host_enum_unchecked_return_coverity_backport_v5.3' into 'release/v5.3'
fix(usb_host): Fixed unchecked return value in enum driver (coverity) (backport to v5.3)

See merge request espressif/esp-idf!36670
2025-04-16 10:20:38 +08:00
igor.masar
ddd9d02794 fix(usb_host): Fix return code and description
Changed error code from ESP_ERR_INVALID_STATE to ESP_ERR_NOT_FOUND
when the client never opened the device.
Updated function documentation to correctly reflect return values.
2025-03-31 23:44:32 +02:00
Myk Melez
5750b151cf fix(usb_host): Give semaphore on attempted close of non-opened device
If you call *usb_host_device_close()* for a device that isn't open, the function exits early,
without giving back the semaphore it took, which causes any other call that tries to take
that semaphore to hang indefinitely.

Strangely, there's redundant handling of this condition, with two checks in a row that both handle
the case where `_check_client_opened_device(client_obj, dev_addr)` returns `false`:

```c
    HOST_CHECK_FROM_CRIT(_check_client_opened_device(client_obj, dev_addr), ESP_ERR_NOT_FOUND);
    if (!_check_client_opened_device(client_obj, dev_addr)) {
        // Client never opened this device
        ret = ESP_ERR_INVALID_STATE;
        HOST_EXIT_CRITICAL();
        goto exit;
    }
…
exit:
    xSemaphoreGive(p_host_lib_obj->constant.mux_lock);
    return ret;
```

The first line is the one that exits early, as HOST_CHECK_FROM_CRIT returns its second parameter
if its first parameter is false, without giving back the semaphore (although it does exit
the critical section).

The subsequent block handles the exact same case, except that it ensures the semaphore is given
back before returning. Currently, this block is never reached.

Perhaps the first check was added, then someone noticed the issue and added the second check,
but they forgot to remove the first one.

In any case, this PR removes the first check, so the second check can properly handle this case
by giving back the semaphore before returning.

This bug appears to have been present in the initial commit of the USB Host library to the ESP-IDF
repo: accbaee57c

Of course, if you never try to close a non-opened device, then you won't encounter it!
Unfortunately, I have some code that tried to do that, which is how I found the issue.
2025-03-31 23:44:32 +02:00
Roman Leonov
26ba099bd1 fix(usb_host): Fixed unchecked return value in enum driver (coverity) 2025-03-06 20:19:39 +08:00
Tomas Rezucha
3b2c3cb854 fix(usb/phy): Fixed crash on external PHY init with speed != UNDEFINED
Also deprecated usb_phy_otg_dev_set_speed()
and usb_phy_action() which are no longer used in esp-idf
2025-02-27 15:10:13 +01:00
Roman Leonov
b937bd3a1e fix(usb_phy): Removed pad pull override config for Full-speed 2025-02-27 15:10:13 +01:00
Tomas Rezucha
55f5f29517 fix(usb): Fixed missing GPIO drive capability on ESP32-P4
All USB PHYs that share their IOs with GPIOs must set
the GPIO's drive capability to maximum.
2025-01-27 08:07:46 +01:00
Tomas Rezucha
6d97cd0aa1 refactor(usb/phy): Merge P4 and S2/S3 PHYs into one module
P4 had separate PHY implementation for initial bring-up,
now we can merge it with the original PHY driver.
2025-01-16 10:25:25 +01:00
Tomas Rezucha
19bdc77e55 fix(usb): Backport v5.3 compatibility commit 2025-01-16 09:53:22 +01:00
Tomas Rezucha
144f8a660e refactor(usb/phy): Start using values from usb_dwc_info in PHY driver
Add tests for PHY sanity checks
2025-01-16 16:39:59 +08:00
Tomas Rezucha
005ae0554a refactor(usb/phy): Do not use deprecated variables in usb_phy 2025-01-16 16:39:59 +08:00
Tomas Rezucha
47fd8aac23 feat(hal/usb): Explicitly enable clock and reset USB WRAP on init 2025-01-16 16:39:59 +08:00
morris
92b06b4b9a Merge branch 'feature/usb_host_hubs_support_msg_backport_v5.3' into 'release/v5.3'
feat(hub): Added notification when hubs support is disabled (backport to v5.3)

See merge request espressif/esp-idf!35454
2024-12-09 10:20:08 +08:00
morris
3946fbb142 Merge branch 'feat/dynamic_usb_hal_backport_v5.3' into 'release/v5.3'
feat(hal/usb): Make USB-DWC HAL&LL configuration independent backport v5.3

See merge request espressif/esp-idf!34811
2024-12-07 23:19:56 +08:00
Roman Leonov
ad9419c2ae feat(hub): Added notification when hubs support is disabled 2024-12-05 10:31:05 +01:00
Tomas Rezucha
177679b74e feat(hal/usb): Make USB-DWC HAL&LL configuration independent
Previously, we included symbols from soc/usb_dwc_cfg.h and configured
the HAL and LL according to it. Now we get the configuration in runtime
from USB-DWC registers.

Added missing definition for USB FS peripheral on ESP32-P4.
2024-11-22 17:32:22 +08:00
Tomas Rezucha
1d5a8f6952 feat(hal/usb): Add USB UTMI PHY HAL
* Add a bare-bones HAL API for the USB UTMI PHY
* Split USB-DWC LL per target
2024-11-22 17:32:22 +08:00
Tomas Rezucha
7019a9f61c feat(soc/usb): Add USB related changes to soc_caps and usb_dwc_periph
This commit changes the following:

- Add types and data structures indicating the available USB controllers
for each target.
2024-11-22 17:32:22 +08:00
Daniel Mangum
6db2b4c1ad fix(usb_host): return ESP_ERR_NO_MEM on failed alloc in client register
Fixes issue where ESP_ERR_NO_MEM was being silently discarded after
cleaning up after a failed malloc in usb_host_client_register.

Signed-off-by: Daniel Mangum <georgedanielmangum@gmail.com>
2024-11-20 21:07:54 +08:00
Roman Leonov
b15e83f6e0 refactor(usb_host): Removed error in enum when stalled, added hcd_dwc no more free channels 2024-10-28 18:14:14 +01:00
Roman Leonov
63f9104669 fix(ext_port): Added port recovery delay 2024-10-28 18:14:14 +01:00
Roman Leonov
670f11644f refactor(usb_host/examples): Enabled external Hub support feature 2024-10-28 18:14:14 +01:00
Roman Leonov
52aa6a1d4c feat(ext_port): Added External Port driver
Closes https://github.com/espressif/esp-idf/issues/12554
2024-10-28 18:14:08 +01:00
Peter Marcisovsky
46e610fe13 fix(usb_host): Update log level and error poropagation 2024-10-08 11:25:28 +02:00
Peter Marcisovsky
07dc67c640 refactor(usb_host): Fixed function return values in usb_host stack:
- updated doxygen for the whole usb_host stack
    - doxygen for test_apps is not updated
    - fixed error codes propagation problems in the usb_host stack
2024-10-08 11:25:28 +02:00
Tomas Rezucha
e009a4f451 feat(usb/host): Enable USB Host tests on P4 2024-09-27 11:31:42 +02:00
Tomas Rezucha
9bdea61071 fix(usb/host): Correctly handle unpowered port in HUB 2024-09-27 11:31:42 +02:00
Darian Leung
802ab4c2cc refactor(usb): Remove use of usb_phy_action() from unit tests
Currently, USB Host unit tests that require a software triggered disconnection/
reconnection rely on the 'usb_phy_action()' function.

This commit replaces those calls with 'hcd_port_command()' or
'usb_host_lib_set_root_port_power()'.

Note: Also removed 'test_usb_common.h/c' as it is no longer necessary are the
function call replacements.
2024-09-27 11:31:42 +02:00
Darian Leung
318c69a671 feat(usb): Add usb_host_lib_set_root_port_power()
This commit adds the usb_host_lib_set_root_port_power() function. This provides
a public API for users to power the root port OFF or ON at runtime, thus trigger
a disconnection or allow connections respectively.

In addition, the usb_host_config_t.root_port_unpowered install configuration is
provided to allow users to install the USB Host Library without automatically
powering ON the root port.
2024-09-27 11:31:42 +02:00
Roman Leonov
cc505fe27d refactor(hub): Cleaned up dev_tree_node debug output, moved node freeing 2024-09-07 11:46:53 +02:00
Roman Leonov
c2691b94c8 refactor(ext_hub): Prerequisites for the Ext Port Driver 2024-09-06 10:53:13 +02:00
Roman Leonov
aa3adb747e fix(usb_host): The Enumeration Driver, cancellation on error 2024-09-06 10:53:01 +02:00
Roman Leonov
8c3a4fc1fe feat(ext_hub): Added External Hub driver 2024-09-06 10:29:02 +02:00
Roman Leonov
56c7b79253 fix(usb_host): Increased address map for clients and changed the uid member type 2024-09-06 10:27:42 +02:00
Tomas Rezucha
a9f8f2576a fix(enum): Returned usb_round_up_to_mps for control request of string descriptors 2024-09-06 10:27:42 +02:00
Roman Leonov
71708508d6 feat(hub): Added device tree nodes list and uid calculation logic 2024-09-06 10:27:42 +02:00
Roman Leonov
9eb4ea32fe fix(enum): Fixed STALL on descriptor request, removed unused value 2024-09-06 10:27:42 +02:00
Roman Leonov
e729453089 refactor(enum): Curved out Enumeration process from Hub Driver 2024-09-06 10:17:22 +02:00
Roman Leonov
231247b0f5 refactor(hub): Updated HUB api for ENUM driver 2024-09-06 10:17:22 +02:00
Roman Leonov
7fdc327cc1 refactor(usbh): Updated USBH api for ENUM driver 2024-09-06 10:17:22 +02:00
morris
412f1f5991 Merge branch 'feat/usb_ls_p4_backport_v5.3' into 'release/v5.3'
Fix USB Low-Speed devices on ESP32-P4 backport v5.3

See merge request espressif/esp-idf!33268
2024-09-05 10:41:16 +08:00
Tomas Rezucha
8e27a0fb25 refactor(usb/host): Move P4 HS PHY function to correct LL file
Moved usb_wrap_ll_enable_precise_detection() in usb_wrap_ll.h
to usb_utmi_ll_enable_precise_detection() in usb_utmi_ll.h

Fixes commit 97d30e7c48
2024-09-03 08:11:15 +02:00
Tomas Rezucha
3f1d59d6bb fix(usb/host): Fix USB Low Speed devices connection on P4
P4 USB UTMI PHY was updated to specification v2.0
2024-09-03 08:11:07 +02:00
Tomas Rezucha
8f7dcc1eab fix(usb/host): Use new cache aligned DMA alloc functions 2024-08-26 08:32:16 +02:00
morris
fc177553b2 Merge branch 'feature/usb_host_multi_configuration_backport_v5.3' into 'release/v5.3'
feat(usb/host): multiconfiguration support backport (v5.3)

See merge request espressif/esp-idf!32054
2024-08-02 11:45:29 +08:00
Tomas Rezucha
0d7d3b5dbb fix(usb/host): Fix occasional ISOC scheduler skipping transfers 2024-07-30 10:25:54 +08:00
Peter Marcisovsky
613ad211c6 refactor(usb_host): Update USB Host multiconfig public API
- previous usb_host_get_config_desc_free()
    - updated usb_host_free_config_desc()
2024-07-29 12:20:16 +02:00
Peter Marcisovsky
5fc18ffc04 feat(usb/host): multiconfiguration support
- usb host reads device's configuration on request
    - a control transfer is sent
    - memory is allocated for a new descriptor
    - user must manually free the memory
2024-07-29 12:20:16 +02:00
morris
c782e57a0f Merge branch 'feature/usb_host_hub_support_collective_backport_v5.3' into 'release/v5.3'
refactor(usb/host): Prerequisite Refactoring For Hub Collective backport (v5.3)

See merge request espressif/esp-idf!30480
2024-07-29 17:11:08 +08:00