Commit Graph

233 Commits

Author SHA1 Message Date
peter.marcisovsky
8f3b01d158 refactor(usb_host): Remove val types from USB Host stack 2025-06-10 13:35:47 +02:00
Roman Leonov
79d69bc7e1 Merge branch 'fix/usb_host_test_with_multiple_hubs' into 'master'
fix(ext_hub): Added processing waiting_release flag while dev changed to IDLE

See merge request espressif/esp-idf!39322
2025-05-29 05:05:21 +08:00
Igor Masar
574f037b1e Merge branch 'fix/usb-log-priu32-fifo-config' into 'master'
fix(usb/hcd): Use PRIu32 in FIFO config log for portability

See merge request espressif/esp-idf!39299
2025-05-21 20:00:27 +08:00
Roman Leonov
11382a2aae fix(ext_hub): Added processing waiting_release flag while dev changed to IDLE 2025-05-21 12:13:47 +02:00
igor.masar
dcdeeeff45 fix(usb/hcd): Use PRIu32 in FIFO config log for portability
The ESP_LOGD message that prints FIFO line sizes used %u for uint32_t,
which may cause incorrect output on some architectures (e.g., ESP32-P4
where uint32_t maps to unsigned long). To ensure portable and correct
logging across all supported platforms, this patch replaces %u with
%" PRIu32 ", defined in <inttypes.h>.

No functional behavior is affected — this is a formatting correction
for debug output only.
2025-05-20 16:27:27 +02:00
Roman Leonov
f238d75ba3 refactor(ext_port): Remove the error verification, as error will be handled in ext hub driver 2025-05-20 11:34:53 +02:00
Roman Leonov
19ce9ed634 refactor(test_usb_host_async): Added host_lib_task finish notification 2025-05-20 11:34:53 +02:00
Roman Leonov
3003362bcb refactor(usb_host): Cancel hub porpagation to the user, rename non-critical func 2025-05-20 11:34:53 +02:00
Roman Leonov
3fd17b8be8 refactor(hub): Applied new ext_hub api, refactor func names 2025-05-20 11:34:53 +02:00
Roman Leonov
fc61875a56 refactor(ext_hub): Pospone the device release, if device is not IDLE 2025-05-20 11:34:53 +02:00
Roman Leonov
754d357f18 refactor(ext_hub): Fixed device release, optimized the order of closing usbh device 2025-05-20 11:34:53 +02:00
Tomas Rezucha
94d71a8cd0 Merge branch 'feature/usb_dual_host_2' into 'master'
feat(usb/host): Add option to choose peripherals for USB host library

Closes IDF-11705, IDF-9052, and DOC-10991

See merge request espressif/esp-idf!35401
2025-05-15 16:18:05 +08:00
wuzhenghui
7107177e2d fix(esp_hw_support): Fix deepsleep leakage after initializing USB HS phy 2025-05-15 10:12:59 +08:00
Tomas Rezucha
b961f42e8b 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.
2025-05-14 10:34:11 +02:00
Roman Leonov
79c66cc16c Merge branch 'refactor/usb_dwc_buff_delay_on_p4' into 'master'
refactor(hcd_dwc): Apply ls_via_fs_hub delay for all targets

See merge request espressif/esp-idf!38946
2025-05-14 01:08:55 +08:00
Tomas Rezucha
27099e1c55 Merge branch 'fix/usbjtag_after_tinyusb' into 'master'
fix(usb/phy): Fix ability to switch back to USB/JTAG after uninstalling TinyUSB

Closes IDFGH-15273 and IDFGH-15248

See merge request espressif/esp-idf!39061
2025-05-14 01:06:05 +08:00
Igor Masar
c06fa310cf Merge branch 'feat/usb-explicit-fifo-config' into 'master'
feat(usb/hal): Add HAL API to configure custom FIFO layout

Closes IDF-9042

See merge request espressif/esp-idf!38404
2025-05-13 22:28:41 +08:00
John Boiles
c9c8560169 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-13 13:21:41 +02:00
peter.marcisovsky
cd5b3877bf 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 15:37:30 +08:00
igor.masar
cb4d90186f 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-09 15:03:52 +02:00
Roman Leonov
898f881226 refactor(hcd_dwc): Apply delay for all targets 2025-05-07 11:14:30 +02:00
Roman Leonov
aaebc37467 Merge branch 'refactor/usb_host_ext_port_change_deps_to_ext_hub' into 'master'
refactor(ext_port): Remove dependency from the External Hub driver

Closes IDF-12562

See merge request espressif/esp-idf!37518
2025-05-02 16:30:20 +08:00
Tomas Rezucha
4b15ef706b Merge branch 'fix/usb_comprehensive_heap' into 'master'
fix(usb/host): Do not call heap_caps_get_allocated_size() in USB host driver

Closes IDFGH-15138

See merge request espressif/esp-idf!38715
2025-04-30 14:22:08 +08:00
Roman Leonov
178ac8ee0f refactor(ext_port): Removed ext_hub dependency: update test_app 2025-04-29 17:55:25 +02:00
Roman Leonov
a807fe7940 refactor(ext_port): Removed ext_hub dependency 2025-04-29 17:54:16 +02:00
Roman Leonov
8a6271bc32 feat(test_ext_port): Added test cases for the external port driver testing 2025-04-29 16:39:15 +08:00
Tomas Rezucha
6badd2cf25 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-29 14:50:11 +08:00
Roman Leonov
ea3f801e14 Merge branch 'feature/usb_host_ext_port_isolate_hub_request' into 'master'
refactor(ext_port): Isolated the hub class specific request

Closes IDF-12511

See merge request espressif/esp-idf!37272
2025-04-24 02:25:32 +08:00
peter.marcisovsky
6dfb7269a1 feat(usb_host): Host tests for individual USB Host layers
- Public API CMock based Host tests
    - USB Host layer: driver install/uninstall unit test
    - USBH layer: driver install/uninstall unit test
    - Host tests are run in CI
2025-04-23 12:09:25 +02:00
Roman Leonov
941647597b 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-04-23 10:52:34 +02:00
peter.marcisovsky
92ece05ac5 fix(usb_host): Correctly initialize set pipe ep char 2025-04-22 16:41:11 +02:00
Tomas Rezucha
179a468adf Merge branch 'fix/usb_host_hcd_test_pipe_stall' into 'master'
feat(usb_host): Fix HCD test HCD control pipe STALL

See merge request espressif/esp-idf!38338
2025-04-15 20:43:15 +08:00
Roman Leonov
dbf9d78763 fix(hcd): Added delay to slow down scatter-gather dma for ls device via fs hubs
Closes https://github.com/espressif/esp-idf/issues/15683
2025-04-11 17:06:08 +08:00
peter.marcisovsky
fe9290bfe1 fix(usb_host): Fix HCD Test pipe stall with only one URB enqeued 2025-04-10 17:44:16 +02:00
Roman Leonov
4e673844bf Merge branch 'refactor/usb_host_test_ext_hub_prereq' into 'master'
refactor(test_apps): Moved usb phy and hcd  to common folder

See merge request espressif/esp-idf!37551
2025-03-27 18:22:25 +08:00
Roman Leonov
d0f27448ad refactor(usb_host): Made phy and hcd common
fix
2025-03-26 12:49:31 +01:00
igor.masar
5f6155638d 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-25 23:00:56 +01:00
Myk Melez
aa669fa25d 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-24 21:58:34 +01:00
Roman Leonov
168aa0d25f feat(hcd): Added verification of intr pipe allocation with any bInterval 2025-03-21 20:25:38 +08:00
igor.udot
daf2d31008 test: format all test scripts 2025-03-05 12:08:48 +08:00
Tomas Rezucha
51fd02dd83 Merge branch 'fix/usb_phy_set_speed' into 'master'
fix(usb/phy): Fixed crash on external PHY init with speed != UNDEFINED

See merge request espressif/esp-idf!37218
2025-02-26 19:50:23 +08:00
Roman Leonov
858947e461 feat(ext_hub): Added support for low-speed devices, connected via hubs 2025-02-24 19:39:53 +08:00
Tomas Rezucha
ca24a117c7 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-21 14:11:51 +01:00
Roman Leonov
46952c601d feat(usb_host): Added uid presence check in USBH device object list 2025-02-19 10:23:44 +01:00
Roman Leonov
7c118fd072 feat(enum): Added test application to test enum driver with mocked device 2025-02-13 11:58:57 +01:00
Roman Leonov
9c8517045c fix(usb_phy): Removed pull resistors override configuration for Internal FSLS PHY 2025-02-05 12:28:38 +01:00
Roman Leonov
2255cdc462 fix(usb_host): Fixed unchecked return value in enum driver (coverity) 2025-01-28 14:11:55 +01:00
Tomas Rezucha
ce59bd4017 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-24 14:02:52 +01:00
Tomas Rezucha
65c2cc095d 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-15 11:18:10 +01:00
Peter Marcisovsky
c4a4de0bb1 Merge branch 'feat/usb_host_external_power_switch_ci' into 'master'
Feat/usb host external power switch for esp32s2(s3) CI target runners

Closes IEC-238

See merge request espressif/esp-idf!35247
2025-01-09 01:16:20 +08:00