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.
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
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.
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
- 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
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.
- 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
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.
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.