Commit Graph

53 Commits

Author SHA1 Message Date
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
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
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
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
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
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
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
Tomas Rezucha
1805efb0b2 Merge branch 'feat/dynamic_usb_hal' into 'master'
feat(hal/usb): Make USB-DWC HAL&LL configuration independent

Closes IDF-11437

See merge request espressif/esp-idf!34045
2024-10-30 18:32:32 +08:00
Roman Leonov
501e4e6c81 Merge branch 'refactor/usb_host_hcd_dwc_enum_messages' into 'master'
refactor(usb_host):  HCD DWC and Enum additional error messages

See merge request espressif/esp-idf!34236
2024-10-25 16:09:25 +08:00
Tomas Rezucha
d837cae2b0 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-10-24 16:54:20 +02:00
Roman Leonov
c19e2b7f8d refactor(usb_host): Removed error in enum when stalled, added hcd_dwc no more free channels 2024-10-24 16:40:55 +08:00
Tomas Rezucha
b02ad37a55 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-10-24 15:18:30 +08:00
Peter Marcisovsky
d19666d8e5 refactor(usb_host): Update the USB component to new critical section API 2024-10-08 17:43:55 +02:00
Tomas Rezucha
19bf686d5e feat(usb/host): Enable USB Host tests on P4 2024-09-05 19:41:07 +02:00
Peter Marcisovsky
f7b31defc9 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-09-02 16:41:38 +02:00
Tomas Rezucha
660319ecaf fix(usb/host): Use new cache aligned DMA alloc functions 2024-08-20 08:13:32 +02:00
Ivan Grokhotkov
d146fb5b84 Merge branch 'bugfix/build_with_clang' into 'master'
fix build errors with clang

Closes IDFGH-13238

See merge request espressif/esp-idf!32099
2024-07-15 21:40:40 +08:00
Ivan Grokhotkov
df65b3829e fix(usb): variable declaration after label for clang 2024-07-12 13:58:18 +02:00
Tomas Rezucha
43c06a5d11 fix(usb/host): Fix occasional ISOC scheduler skipping transfers 2024-07-09 16:59:27 +02:00
Tomas Rezucha
04be071dc6 fix(usb/host): Decode error flags in ISOC transfers 2024-07-02 15:08:30 +02:00
Alexey Lapshin
e1b9985bd0 fix(usb): fix warnings found by GNU static analyzer 2024-06-18 14:25:37 +08:00
Darian Leung
99ec1c98f5 refactor(usb/usbh): Update USBH device creation and enumeration handling
This commit updates how the USBH handles device creation and enumeration so that
upper layers (such as the Hub driver) can use the USBH API for enumeration instead
of calling the HCD.

USBH Updates:

USBH now creates unenumerated devices set to address 0 with no device/config
descriptor. A newly created device can be opened and communicated with immediately
(using control transfers). This allows the Hub driver to call the USBH instead of
the HCD. Summary of USBH changes:

- Added new APIs to add/remove a device. Devices are now created as unenumerated
and can be immediately opened and communicated with.
- Added new APIs to enumerate a device (see 'usbh_dev_set_...()' functions). Device
must be locked (see 'usbh_dev_enum_lock()') before enumeration functions can be called.
- Added UID for each device. This allows the particular USBH without needing to
use the device's handle (which implies opening the device).

Hub Driver Updates:

Hub driver now calls the USBH for enumeration. Summary of USBH changes:

- Replace all 'hcd_pipe_...()' calls with 'usbh_dev_...()' calls
- Refactored port event handling to fit with new USBH API
- Updated to use UID to uniquely identify devices without opening them

USB Host Updates:

- Reroute USBH control transfers to clients and hub driver
2024-04-23 17:18:56 +08:00
Darian Leung
c10fe6ca48 refactor(usb/hcd): Allow port resets with allocated pipes
This commit updates the HCD API to allow port resets to occur even if pipes
are allocated. The pipes cannot be active and the port reset will simply
restore the pipes (by reinitializing their channel registers) following the
reset.

Changes:

- Allow port resets while channels are allocated
- Remove pipe persistance API 'hcd_pipe_set_persist_reset()'
2024-04-23 16:50:53 +08:00
Armando
d341540a5e change(drivers): other driver changes for cache malloc 2024-04-15 15:34:51 +08:00
Gao Xu
db3e43908a Merge branch 'feat/add_esp_dma_capable_malloc' into 'master'
dma_utils: add esp dma capable malloc function

Closes IDF-9638

See merge request espressif/esp-idf!29869
2024-04-02 21:31:45 +08:00
Roman Leonov
dbad0df765 refactor(hcd_dwc): Added mps request from hcd_dwc 2024-04-02 10:23:52 +02:00
gaoxu
40f38bea6f feat(dma): refactor dma calloc function 2024-04-02 14:30:14 +08:00
Armando
f0518b3c16 feat(dma): advanced dma malloc helper 2024-04-02 14:30:14 +08:00
Tomas Rezucha
e9daf4912b fix(usb/host): Do not allow unaligned cache access for M2C direction 2024-03-26 16:41:12 +01:00
Tomas Rezucha
72f00d7c6d feat(usb/host): Update ISOC scheduler for HS endpoints
USB-OTG uses 'sched_info' field of HCTSIZ register to schedule transactions
in USB microframes.
2024-03-01 18:05:40 +01:00
Tomas Rezucha
ed1f20a972 feat(hal/usb): Add HS PHY configuration 2024-01-22 12:14:11 +01:00
Tomas Rezucha
ec004c788b fix(usb/host): Sync cache for memory shared by CPU and USB-OTG
Transfer descriptor list, frame list and transfer data buffers
are accessed by both CPU and USB-OTG. Sync CPU cache between the accesses.
2024-01-10 15:23:24 +01:00
Darian Leung
d7b83bfd3b refactor(usb/host): reformat code with astyle_py 2023-12-15 04:44:02 +08:00
Tomas Rezucha
e32b7b060c fix(usb/host): Correctly parse bInterval field in HighSpeed EP descriptors
For LS and FS interrupt endpoint: interval = bInterval
For isochronous and HS interrupt endpoint: interval = 2^(bInterval-1)
2023-12-12 21:10:43 +01:00
Tomas Rezucha
c2660ce7c6 fix(usb/host): Correctly parse MPS fields in HighSpeed EP descriptors
Bits [11,12] in HighSpeed periodic endpoints specify
the number of additional transaction opportunities per microframe
2023-12-12 21:10:37 +01:00
Tomas Rezucha
39d57f1cfd refactor(usb/host): Move FIFO size configuration to HAL layer
The logic of calculating FIFO sizes is DWC OTG specific.
We move it to the HAL layer to provide better abstraction in the HDC layer.
2023-11-30 12:04:30 +08:00
Tomas Rezucha
b258bbf068 refactor(usb/host): Make private hal types USB_DWC specific 2023-11-30 10:24:53 +08:00
Tomas Rezucha
69d9e7625b feat(usb/host): Add High Speed enumeration types 2023-11-30 10:17:00 +08:00
Roman Leonov
bd51768340 fix(usb/host): remove bInterval verification during pipe opening for INTR and ISOC EPs 2023-11-16 14:11:01 +01:00
Darian Leung
c0de14d0b9 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-14 20:49:51 +08:00
Darian Leung
a1ed398481 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-06-21 17:50:20 +08:00
morris
8885d20482 usbh: fix invalid assert on desc_status 2023-06-19 10:59:46 +08:00
Darian Leung
cbed197e10 usb_host: Run formatting script 2023-05-29 17:30:41 +08:00
Darian Leung
1ffbbf5aef usb_host: Fix spelling errors 2023-05-29 17:30:41 +08:00
Darian Leung
bab1c61a4c 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-05-29 17:30:41 +08:00
Roman Leonov
1be6977a9d usb_host: better debugging information during hcd_pipe_alloc() when usb_host_interface_claim() is being fulfiled. 2023-04-24 08:37:57 +02:00