Commit Graph

200 Commits

Author SHA1 Message Date
Tomas Rezucha
85049c9338 fix(host/usb): Fixed deadlock that prevented closing devices from high priority tasks
If in usb_host_interface_release() the underlying pipe was halted while having an URB in-flight,
usb_host_client_handle_events() may not have had a chance to process the URB yet.
Check if there are any pending URBs on the pipe before attempting to free it.

Closes https://github.com/espressif/esp-idf/issues/17707
2026-02-04 08:00:21 +01:00
Alexey Lapshin
47aaedeb94 fix(usb): fix warnings found by GNU static analyzer 2025-07-02 20:30:30 +08:00
Tomas Rezucha
4addf21286 feat(usb/host): Add option to choose peripheral for USB host library
Starting with ESP32-P4 we can have targets that have more than 1 USB-OTG peripheral.
This commit adds an option to choose which peripherals will be used by USB Host lib.

Internally, we will still have only 1 Root HUB but with multiple Root ports.

# Conflicts:
#	components/usb/host_test/usb_host_layer_test/main/usb_host_install_unit_test.cpp
#	components/usb/hub.c
#	components/usb/test_apps/common/phy_common.c
#	components/usb/test_apps/common/phy_common.h
#	components/usb/test_apps/hcd/main/test_hcd_common.c
#	components/usb/test_apps/usb_host/main/test_app_main.c
#	components/usb/usb_host.c
2025-06-30 14:45:59 +08:00
morris
15bc442a88 Merge branch 'feat/usb-explicit-fifo-config_v5.3' into 'release/v5.3'
feat(usb/hal): Add HAL API to configure custom FIFO layout (backport v5.3)

See merge request espressif/esp-idf!39264
2025-06-03 14:35:32 +08:00
Roman Leonov
e550fb11c3 fix(ext_hub): Added processing waiting_release flag while dev changed to IDLE
11382a2a fix(ext_hub): Added processing waiting_release flag while dev changed to IDLE

Co-authored-by: Roman Leonov <roman.leonov@espressif.com>
2025-06-02 11:45:29 +02:00
Roman Leonov
59aa1cbaf8 refactor(ext_hub): Device release (allows to run usb_host test with ext hub)
754d357f refactor(ext_hub): Fixed device release, optimized the order of closing usbh device
fc61875a refactor(ext_hub): Pospone the device release, if device is not IDLE
3fd17b8b refactor(hub): Applied new ext_hub api, refactor func names
3003362b refactor(usb_host): Cancel hub porpagation to the user, rename non-critical func
19ce9ed6 refactor(test_usb_host_async): Added host_lib_task finish notification
f238d75b refactor(ext_port): Remove the error verification, as error will be handled in ext hub driver

Co-authored-by: Roman Leonov <roman.leonov@espressif.com>
2025-06-02 11:45:19 +02:00
Jiang Jiang Jian
96037e9cc3 Merge branch 'fix/fix_usb_hs_phy_leakage_on_deepsleep_v5.3' into 'release/v5.3'
fix(esp_hw_support): Fix deepsleep leakage after initializing USB HS phy (v5.3)

See merge request espressif/esp-idf!39169
2025-05-26 19:56:41 +08:00
igor.masar
d98a828c7e feat(usb/hal): Add support for explicit FIFO configuration
Introduce a new HAL API `usb_dwc_hal_set_fifo_config()` that allows advanced users
to manually configure RX, Non-Periodic TX, and Periodic TX FIFO sizes. This offers
fine-grained control beyond the previous bias-based sizing approach.

The HAL function no longer returns `esp_err_t`, and internal validations are enforced
via `HAL_ASSERT()`. Responsibility for input validation has been moved to the HCD layer.

FIFO configuration must be applied before any USB pipes are created or activated.
This feature is intended for use during `usb_host_install()`.

If no custom FIFO configuration is provided (i.e., all values are zero),
the driver falls back to a bias-based default layout based on Kconfig settings
(`CONFIG_USB_HOST_HW_BUFFER_BIAS_*`). Bias resolution is done inside `hcd_port_init()`.

The `port_obj_t` structure has been extended with a `fifo_config` field, which stores
the configuration to allow re-application after a USB port reset.

Obsolete FIFO bias enums (`usb_hal_fifo_bias_t`, `hcd_port_fifo_bias_t`) and related
APIs (`hcd_port_set_fifo_bias()`) have been removed in favor of the new structure-based mechanism.

The HCD initialization and port reset flow has been updated to use the explicit
FIFO configuration.

USB Host maintainer documentation (`maintainers.md`) has been updated accordingly.
Test cases were updated to remove the usage of removed bias API and now rely on default
or custom FIFO configuration.
2025-05-20 15:44:54 +02:00
morris
292114f622 Merge branch 'refactor/usb_dwc_buff_delay_on_p4_backport_v5.3' into 'release/v5.3'
refactor(hcd_dwc): Apply ls_via_fs_hub delay for all targets (backport to v5.3)

See merge request espressif/esp-idf!39150
2025-05-16 23:04:43 +08:00
morris
995b09e792 Merge branch 'fix/usbjtag_after_tinyusb_backport_v5.3' into 'release/v5.3'
fix(usb/phy): Fix ability to switch back to USB/JTAG after uninstalling TinyUSB (backport to v5.3)

See merge request espressif/esp-idf!39125
2025-05-16 10:23:04 +08:00
wuzhenghui
e0d1641281 fix(esp_hw_support): Fix deepsleep leakage after initializing USB HS phy 2025-05-15 16:05:34 +08:00
Roman Leonov
bc7c612c1f refactor(hcd_dwc): Apply ls_via_fs_hub delay for all targets 2025-05-14 13:52:16 +02:00
John Boiles
362cca224a fix(usb/phy): Fix ability to switch back to USB/JTAG after uninstalling TinyUSB
Fixes #15912. This is a revert of a change made in 005ae0554 that breaks the
ability to re-initalize the USB/JTAG device after uninstalling TinyUSB.

Closes https://github.com/espressif/esp-idf/issues/15912
2025-05-14 08:25:43 +02:00
peter.marcisovsky
196bc310e5 feat(usb_host): Move DMA capable memory to external ram on P4
- DWC-OTG internal DMA can access psram on esp32p4
    - Move DMA memory buffs to psram, to save internal ram
    - HCD tests and MSC example runs in CI with psram enabled
2025-05-13 13:32:38 +02:00
Roman Leonov
add4213c6b refactor(ext_port): Removed ext_hub dependency 2025-05-06 15:21:39 +02:00
Roman Leonov
166a79a764 refactor(ext_port): Changed the mechanism for hub class request
Merged all Hub Class specific request to one function.
Added a callback for the External Port Driver to break the dependency from ext_hub.h
2025-05-06 15:01:33 +02:00
Roman Leonov
02b96db4ae feat(ext_hub): Added device error handling 2025-05-06 14:54:58 +02:00
Roman Leonov
622eab9bad feat(usbh): Added uid presence check in USBH device object list 2025-05-06 14:54:58 +02:00
morris
4066380f48 Merge branch 'fix/usb_host_hcd_dma_ls_via_fs_hubs_backport_v5.3' into 'release/v5.3'
fix(hcd): Added delay to slow down scatter-gather dma for ls device via fs hubs (backport v5.3)

See merge request espressif/esp-idf!38649
2025-05-06 13:40:40 +08:00
Tomas Rezucha
35e354c77f fix(usb/host): Do not call heap_caps_get_allocated_size() in USB host driver
It causes heap corruption if heap poisoning is enabled on ESP32-P4.
It returns incorrect size on ESP32-S3.

Closes https://github.com/espressif/esp-idf/issues/15815
2025-04-30 08:38:19 +02:00
Roman Leonov
c44f46751a fix(usb_host): Correctly initialize set pipe ep char 2025-04-23 09:59:28 +02:00
Roman Leonov
3750d02cb1 fix(hcd): Added delay to slow down scatter-gather dma for ls device via fs hubs 2025-04-23 09:59:16 +02:00
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