docs(enum): Added description for Enumeration process (Enum Driver)

This commit is contained in:
Roman Leonov
2024-05-23 13:13:13 +02:00
parent 410a6a21c5
commit d41dd420da
8 changed files with 455 additions and 1 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 23 KiB

After

Width:  |  Height:  |  Size: 19 KiB

View File

@@ -114,6 +114,7 @@ USB_DOCS = ['api-reference/peripherals/usb_device.rst',
'api-reference/peripherals/usb_host/usb_host_notes_dwc_otg.rst',
'api-reference/peripherals/usb_host/usb_host_notes_index.rst',
'api-reference/peripherals/usb_host/usb_host_notes_usbh.rst',
'api-reference/peripherals/usb_host/usb_host_notes_enum.rst',
'api-guides/usb-otg-console.rst',
'api-guides/dfu.rst']

View File

@@ -0,0 +1,276 @@
contribute/esp-idf-tests-with-pytest.rst
contribute/contributor-agreement.rst
contribute/documenting-code.rst
contribute/creating-examples.rst
contribute/style-guide.rst
contribute/copyright-guide.rst
contribute/install-pre-commit-hook.rst
contribute/index.rst
api-guides/jtag-debugging/debugging-examples.rst
api-guides/jtag-debugging/configure-ft2232h-jtag.rst
api-guides/jtag-debugging/tips-and-quirks.rst
api-guides/jtag-debugging/using-debugger.rst
api-guides/jtag-debugging/building-openocd-macos.rst
api-guides/jtag-debugging/building-openocd-linux.rst
api-guides/jtag-debugging/configure-other-jtag.rst
api-guides/jtag-debugging/building-openocd-windows.rst
api-guides/jtag-debugging/index.rst
api-guides/jtag-debugging/configure-builtin-jtag.rst
api-guides/partition-tables.rst
api-guides/thread-local-storage.rst
api-guides/error-handling.rst
api-guides/tools/idf-tools.rst
api-guides/tools/idf-clang-tidy.rst
api-guides/tools/idf-component-manager.rst
api-guides/tools/idf-py.rst
api-guides/tools/qemu.rst
api-guides/tools/idf-windows-installer.rst
api-guides/tools/idf-monitor.rst
api-guides/tools/idf-docker-image.rst
api-guides/tools/index.rst
api-guides/low-power-mode.rst
api-guides/startup.rst
api-guides/hlinterrupts.rst
api-guides/RF_calibration.rst
api-guides/unit-tests.rst
api-guides/deep-sleep-stub.rst
api-guides/blufi.rst
api-guides/lwip.rst
api-guides/coexist.rst
api-guides/flash_psram_config.rst
api-guides/usb-serial-jtag-console.rst
api-guides/linker-script-generation.rst
api-guides/wifi.rst
api-guides/usb-otg-console.rst
api-guides/bluetooth.rst
api-guides/wireshark-user-guide.rst
api-guides/bootloader.rst
api-guides/esp-wifi-mesh.rst
api-guides/cplusplus.rst
api-guides/build-system.rst
api-guides/core_dump.rst
api-guides/inc/external-ram-esp32-notes.rst
api-guides/inc/linux-host-requirements.rst
api-guides/c.rst
api-guides/dfu.rst
api-guides/current-consumption-measurement-modules.rst
api-guides/esp-ble-mesh/ble-mesh-index.rst
api-guides/esp-ble-mesh/ble-mesh-feature-list.rst
api-guides/esp-ble-mesh/ble-mesh-terminology.rst
api-guides/esp-ble-mesh/ble-mesh-architecture.rst
api-guides/esp-ble-mesh/ble-mesh-faq.rst
api-guides/external-ram.rst
api-guides/reproducible-builds.rst
api-guides/hardware-abstraction.rst
api-guides/wifi-security.rst
api-guides/host-apps.rst
api-guides/index.rst
api-guides/openthread.rst
api-guides/fatal-errors.rst
api-guides/memory-types.rst
api-guides/general-notes.rst
third-party-tools/platformio.rst
third-party-tools/clion.rst
third-party-tools/visualgdb.rst
COPYRIGHT.rst
libraries-and-frameworks/libs-frameworks.rst
libraries-and-frameworks/index.rst
libraries-and-frameworks/cloud-frameworks.rst
versions.rst
api-reference/api-conventions.rst
api-reference/template.rst
api-reference/provisioning/protocomm.rst
api-reference/provisioning/provisioning.rst
api-reference/provisioning/index.rst
api-reference/provisioning/wifi_provisioning.rst
api-reference/storage/vfs.rst
api-reference/storage/spiffs.rst
api-reference/storage/nvs_encryption.rst
api-reference/storage/wear-levelling.rst
api-reference/storage/fatfs.rst
api-reference/storage/nvs_partition_gen.rst
api-reference/storage/nvs_flash.rst
api-reference/storage/partition.rst
api-reference/storage/sdmmc.rst
api-reference/storage/mass_mfg.rst
api-reference/storage/fatfsgen.rst
api-reference/storage/index.rst
api-reference/storage/nvs_partition_parse.rst
api-reference/peripherals/sdspi_share.rst
api-reference/peripherals/adc_continuous.rst
api-reference/peripherals/adc_oneshot.rst
api-reference/peripherals/usb_host.rst
api-reference/peripherals/twai.rst
api-reference/peripherals/usb_host/usb_host_notes_arch.rst
api-reference/peripherals/usb_host/usb_host_notes_index.rst
api-reference/peripherals/usb_host/usb_host_notes_dwc_otg.rst
api-reference/peripherals/usb_host/usb_host_notes_design.rst
api-reference/peripherals/usb_host/usb_host_notes_usbh.rst
api-reference/peripherals/usb_host/usb_host_notes_enum.rst
api-reference/peripherals/usb_device.rst
api-reference/peripherals/sdspi_host.rst
api-reference/peripherals/spi_slave.rst
api-reference/peripherals/etm.rst
api-reference/peripherals/gptimer.rst
api-reference/peripherals/touch_element.rst
api-reference/peripherals/lcd.rst
api-reference/peripherals/ana_cmpr.rst
api-reference/peripherals/temp_sensor.rst
api-reference/peripherals/spi_features.rst
api-reference/peripherals/clk_tree.rst
api-reference/peripherals/spi_flash/spi_flash_concurrency.rst
api-reference/peripherals/spi_flash/spi_flash_override_driver.rst
api-reference/peripherals/spi_flash/spi_flash_optional_feature.rst
api-reference/peripherals/spi_flash/spi_flash_idf_vs_rom.rst
api-reference/peripherals/spi_flash/index.rst
api-reference/peripherals/sdm.rst
api-reference/peripherals/touch_pad.rst
api-reference/peripherals/adc_calibration.rst
api-reference/peripherals/spi_slave_hd.rst
api-reference/peripherals/parlio.rst
api-reference/peripherals/i2c.rst
api-reference/peripherals/dedic_gpio.rst
api-reference/peripherals/sd_pullup_requirements.rst
api-reference/peripherals/spi_master.rst
api-reference/peripherals/index.rst
api-reference/peripherals/sdmmc_host.rst
api-reference/peripherals/ecdsa.rst
api-reference/kconfig.rst
api-reference/network/esp_openthread.rst
api-reference/network/esp_eth.rst
api-reference/network/esp_netif_driver.rst
api-reference/network/esp_dpp.rst
api-reference/network/esp_now.rst
api-reference/network/esp-wifi-mesh.rst
api-reference/network/esp_smartconfig.rst
api-reference/network/esp_nan.rst
api-reference/network/esp_wifi.rst
api-reference/network/index.rst
api-reference/network/esp_netif.rst
api-reference/system/sleep_modes.rst
api-reference/system/mm_sync.rst
api-reference/system/ota.rst
api-reference/system/perfmon.rst
api-reference/system/esp_function_with_shared_stack.rst
api-reference/system/efuse.rst
api-reference/system/chip_revision.rst
api-reference/system/async_memcpy.rst
api-reference/system/random.rst
api-reference/system/esp_event.rst
api-reference/system/freertos.rst
api-reference/system/log.rst
api-reference/system/soc_caps.rst
api-reference/system/internal-unstable.rst
api-reference/system/app_image_format.rst
api-reference/system/freertos_additions.rst
api-reference/system/himem.rst
api-reference/system/power_management.rst
api-reference/system/mem_alloc.rst
api-reference/system/wdts.rst
api-reference/system/misc_system_api.rst
api-reference/system/bootloader_image_format.rst
api-reference/system/inc/show-efuse-table_ESP32-C5.rst
api-reference/system/inc/revisions_ESP32-C5.rst
api-reference/system/inc/espefuse_summary_ESP32-C5.rst
api-reference/system/inc/power_management_esp32c5.rst
api-reference/system/heap_debug.rst
api-reference/system/mm.rst
api-reference/system/ipc.rst
api-reference/system/esp_https_ota.rst
api-reference/system/esp_err.rst
api-reference/system/freertos_idf.rst
api-reference/system/console.rst
api-reference/system/intr_alloc.rst
api-reference/system/index.rst
api-reference/system/pthread.rst
api-reference/bluetooth/esp_spp.rst
api-reference/bluetooth/esp_l2cap_bt.rst
api-reference/bluetooth/esp_hidd.rst
api-reference/bluetooth/esp_avrc.rst
api-reference/bluetooth/controller_vhci.rst
api-reference/bluetooth/esp_bt_defs.rst
api-reference/bluetooth/esp_hf_ag.rst
api-reference/bluetooth/esp_bt_main.rst
api-reference/bluetooth/esp_bt_device.rst
api-reference/bluetooth/esp_hidh.rst
api-reference/bluetooth/esp_gatts.rst
api-reference/bluetooth/esp_gattc.rst
api-reference/bluetooth/esp_sdp.rst
api-reference/bluetooth/bt_common.rst
api-reference/bluetooth/nimble/index.rst
api-reference/bluetooth/esp_hf_client.rst
api-reference/bluetooth/esp_a2dp.rst
api-reference/bluetooth/esp_blufi.rst
api-reference/bluetooth/bt_le.rst
api-reference/bluetooth/esp_hf_defs.rst
api-reference/bluetooth/esp_gap_bt.rst
api-reference/bluetooth/esp_gatt_defs.rst
api-reference/bluetooth/esp-ble-mesh.rst
api-reference/bluetooth/index.rst
api-reference/bluetooth/esp_gap_ble.rst
api-reference/bluetooth/classic_bt.rst
api-reference/error-codes.rst
api-reference/index.rst
api-reference/protocols/icmp_echo.rst
api-reference/protocols/esp_serial_slave_link.rst
api-reference/protocols/mqtt.rst
api-reference/protocols/mbedtls.rst
api-reference/protocols/esp_http_server.rst
api-reference/protocols/esp_local_ctrl.rst
api-reference/protocols/esp_crt_bundle.rst
api-reference/protocols/esp_http_client.rst
api-reference/protocols/esp_https_server.rst
api-reference/protocols/esp_spi_slave_protocol.rst
api-reference/protocols/modbus.rst
api-reference/protocols/esp_tls.rst
api-reference/protocols/mdns.rst
api-reference/protocols/index.rst
api-reference/protocols/asio.rst
security/flash-encryption.rst
about.rst
resources.rst
migration-guides/release-5.x/5.2/ieee802154.rst
migration-guides/release-5.x/5.2/gcc.rst
migration-guides/release-5.x/5.2/protocols.rst
migration-guides/release-5.x/5.2/wifi.rst
migration-guides/release-5.x/5.2/storage.rst
migration-guides/release-5.x/5.2/index.rst
migration-guides/release-5.x/5.2/system.rst
migration-guides/release-5.x/5.2/peripherals.rst
migration-guides/release-5.x/5.3/security.rst
migration-guides/release-5.x/5.3/bluetooth-low-energy.rst
migration-guides/release-5.x/5.3/storage.rst
migration-guides/release-5.x/5.3/index.rst
migration-guides/release-5.x/5.3/system.rst
migration-guides/release-5.x/5.3/peripherals.rst
migration-guides/release-5.x/5.1/ieee802154.rst
migration-guides/release-5.x/5.1/gcc.rst
migration-guides/release-5.x/5.1/networking.rst
migration-guides/release-5.x/5.1/storage.rst
migration-guides/release-5.x/5.1/index.rst
migration-guides/release-5.x/5.1/system.rst
migration-guides/release-5.x/5.1/peripherals.rst
migration-guides/release-5.x/5.0/bluetooth-classic.rst
migration-guides/release-5.x/5.0/gcc.rst
migration-guides/release-5.x/5.0/bluetooth-low-energy.rst
migration-guides/release-5.x/5.0/removed-components.rst
migration-guides/release-5.x/5.0/protocols.rst
migration-guides/release-5.x/5.0/networking.rst
migration-guides/release-5.x/5.0/provisioning.rst
migration-guides/release-5.x/5.0/build-system.rst
migration-guides/release-5.x/5.0/storage.rst
migration-guides/release-5.x/5.0/index.rst
migration-guides/release-5.x/5.0/system.rst
migration-guides/release-5.x/5.0/tools.rst
migration-guides/release-5.x/5.0/peripherals.rst
migration-guides/index.rst
get-started/establish-serial-connection.rst
get-started/linux-macos-setup.rst
get-started/linux-macos-start-project.rst
get-started/windows-setup.rst
get-started/start-project.rst
get-started/flashing-troubleshooting.rst
get-started/windows-start-project.rst
get-started/index.rst
get-started/windows-setup-update.rst
index.rst

View File

@@ -59,6 +59,7 @@ api-reference/peripherals/usb_host/usb_host_notes_index.rst
api-reference/peripherals/usb_host/usb_host_notes_dwc_otg.rst
api-reference/peripherals/usb_host/usb_host_notes_design.rst
api-reference/peripherals/usb_host/usb_host_notes_usbh.rst
api-reference/peripherals/usb_host/usb_host_notes_enum.rst
api-reference/peripherals/usb_device.rst
api-reference/peripherals/gpio.rst
api-reference/peripherals/dac.rst

View File

@@ -0,0 +1,119 @@
USB Host Enumeration Driver (Enum)
==================================
Introduction
------------
The USB Host Enumeration Driver (henceforth referred to as Enum Driver) provides a software interface which abstracts away the USB device enumeration process. The Enum Driver provides a simple API to start, proceed, complete and cancel the enumeration of a particular device. Internally, the Enum Driver will handle all stages of the enumeration process such as requesting various descriptors and setting the device's configuration.
Requirements
------------
USB Specification Requirements
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Chapter 9.1.2 of the USB 2.0 specification outlines some actions, when a USB device is attached to a powered port.
The design of the Enum Driver takes into consideration following actions:
- **The hub performs the required reset processing for the port.** ``enum_config_t.enum_event_cb`` call with ``ENUM_EVENT_RESET_REQUIRED`` event used for Hub Driver notification.
- **The host assigns a unique address to the USB device.** The Enum Driver keeps the device address value and assigns a unique address to the USB device, moving the device to the Address state.
- **The host reads the device descriptor to determine what actual maximum data payload size this USB device's default pipe can use**. The Enum Driver reads the device descriptor to determine what actual maximum data payload size this USB device's default pipe can use.
- **The host reads the configuration information from the device by reading each configuration zero to n-1, where n is the number of configurations.** This requirement simplified to reading only one configuration information from the device by reading configuration with default number, which could be selected by ``enum_config_t.enum_filter_cb`` call.
- **The host assigns a configuration value to the device.** The Enum Driver assigns a configuration value to the device.
.. note::
Typically, most USB devices only contain a single configuration. Thus, the Enum Driver defaults to selecting the configuration with `bConfigurationValue = 1`.
If users would like to select a different configuration, the Enum Driver provides an enumeration filter callback feature (enabled via :ref:`CONFIG_USB_HOST_ENABLE_ENUM_FILTER_CALLBACK`). This callback is called during the enumeration process and allows users to decide what devices to enumerate, and which ``bConfigurationValue`` to use.
.. note::
For more detailed information about Bus enumeration, please refer to `USB 2.0 Specification <https://www.usb.org/document-library/usb-20-specification>`_ > Chapter 9.1.2 **Bus Enumeration**.
Host Stack Requirements
^^^^^^^^^^^^^^^^^^^^^^^
In addition to the USB 2.0 specification requirements, the Enum Driver also takes into consideration the requirements set for the overall Host Stack (see :doc:`./usb_host_notes_design`):
- Enum Driver must not instantiate any tasks/threads
- Enum Driver must be event driven, providing event callbacks and an event processing function
- Enum Driver must use only API from underlying layer (USBH)
Implementation & Usage
----------------------
Host Stack Interaction
^^^^^^^^^^^^^^^^^^^^^^
The Enum Driver takes place between USB Host layer and USBH layer with a possibility to select configuration with ``enum_config_t.enum_event_cb`` callback provided on Enum Driver installation.
Events & Processing
^^^^^^^^^^^^^^^^^^^
The Enum Driver is completely event driven and all event handling is done via the ``enum_process()`` function. The ``enum_config_t.proc_req_cb`` callback provided on Enum Driver installation will be called when processing is required. Typically, ``enum_process()`` will be called from a shared USB Host stack thread/task.
The Enum Driver exposes the following event callbacks:
- ``enum_event_cb_t`` used to indicate various events regarding an enumeration process. This callback is called from the context of ``enum_process()``
The Enum Driver exposes the following events:
- ``ENUM_EVENT_STARTED`` Enumeration process has been started
- ``ENUM_EVENT_RESET_REQUIRED`` Enumeration process requires device reset
- ``ENUM_EVENT_COMPLETED`` Enumeration process has been completed
- ``ENUM_EVENT_CANCELED`` Enumeration process has been canceled (due to internal error or via ``enum_cancel()`` function call)
Device Enumeration
^^^^^^^^^^^^^^^^^^
The USB device enumeration process implemented in the Enum Driver is mostly based same process in the `Windows USB stack <https://techcommunity.microsoft.com/t5/microsoft-usb-blog/how-does-usb-stack-enumerate-a-device/ba-p/270685>`__. The Enum Driver's enumeration process involves the following steps:
#. First device descriptor request (to obtain the MPS of EP0)
#. Second device reset (to workaround some non-compliant devices)
#. Set device address
#. Second device descriptor request (to obtain and store the full device descriptor)
#. Configuration descriptor request (to obtain the full configuration descriptor of selected configuration)
#. Language ID Table request (checks to see if en-US is supported)
#. Manufacturer string descriptor request
#. Product string descriptor request
#. Serial number string descriptor request
#. Set configuration request (sets the device to target configuration number)
.. note::
String descriptors are optional. If a device does not support string descriptors, these stages could be omitted.
Enumeration Stages
^^^^^^^^^^^^^^^^^^
The Enum Driver splits the enumeration process into multiple stages which are executed linearly. Depending on the connected device, some stages (such as fetching the string descriptors) can be skipped. When a stage completes, a call to the ``enum_config_t.proc_req_cb`` callback must be made to trigger a subsequent call of ``enum_process()``.The subsequent call of ``enum_process()`` will then select and execute the next stage of enumeration. Stage completion can trigger the ``enum_config_t.proc_req_cb`` callback in one of the following ways:
- Inside the control transfer completion callback (for stages that send a control transfer)
- Direct call to ``enum_config_t.proc_req_cb`` (for stages that don't need to wait for any event)
- Inside ``enum_proceed()`` (for stages that require some action to be carried out outside the Enum Driver)
Any control transfer made during enumeration is split into two stages, where the first stage executes the transfer and the second stage (suffixed with ``_CHECK``) will check the results of the transfers.
When requesting a variable length descriptors (e.g., configuration or string descriptors), the request is split into two control transfers. The first control transfer is fixed in length which only reads the header of the descriptor. The ``bLength`` field of the descriptor's header indicates the full length of the entire descriptor and is used to set the size of the second transfer which fetches the entire descriptor. As a result, any request for a variable length descriptor is split into four stages:
- Get short **ANY** descriptor (prefixed with ``GET_SHORT_...``)
- Check short **ANY** descriptor (prefixed with ``CHECK_SHORT_...``)
- Get full **ANY** descriptor (prefixed with ``GET_FULL_...``)
- Check full **ANY** descriptor (prefixed with ``CHECK_FULL_...``)
.. note::
Retrieving the Device Descriptor is an exception here because the second reset is taken place after retrieving short Device Descriptor.
Cancel Enumeration
^^^^^^^^^^^^^^^^^^
In some cases (such as a device disconnection), an ongoing enumeration process may need to be cancelled. An ongoing enumeration can be cancelled (regardless of its current stage) by calling ``enum_cancel()`` which will change the enumeration process's current stage to ``ENUM_STAGE_CANCEL``.
On the next call to ``enum_process``, the Enum Driver will execute the ``ENUM_STAGE_CANCEL`` which does the following:
- releases the device's enumeration lock.
- frees all resources related to the current device.
- propagates the ``ENUM_EVENT_CANCELED`` event.

View File

@@ -21,6 +21,7 @@ This document is split into the following sections:
usb_host_notes_arch
usb_host_notes_dwc_otg
usb_host_notes_usbh
usb_host_notes_enum
Todo:

View File

@@ -0,0 +1 @@
.. include:: ../../../../en/api-reference/peripherals/usb_host/usb_host_notes_enum.rst

View File

@@ -1 +1,56 @@
.. include:: ../../../../en/api-reference/peripherals/usb_host/usb_host_notes_index.rst
USB 主机维护者注意事项(简介)
==============================
:link_to_translation:`en:[English]`
本文档包含有关 USB 主机协议栈实现细节的信息,面向 USB 主机协议栈的维护者和第三方贡献者。USB 主机协议栈的用户请参考 :doc:`../usb_host`
.. warning::
USB 主机协议栈的实现细节属于私有 API因此除 USB 主机库外的所有层均不遵循 :ref:`ESP-IDF 版本简介 <versioning-scheme>`,即允许进行重大更改。
.. figure:: ../../../../_static/usb_host/stack-overview.png
:align: center
:alt: 主机协议栈层次结构图
本文档分为以下几个部分:
.. toctree::
:maxdepth: 1
usb_host_notes_design
usb_host_notes_arch
usb_host_notes_dwc_otg
usb_host_notes_usbh
usb_host_notes_enum
待写章节:
- USB 主机维护者注意事项HAL 和 LL
- USB 主机维护者注意事项HCD
- USB 主机维护者注意事项Hub
- USB 主机维护者注意事项USB Host Library
.. -------------------------------------------------- Introduction -----------------------------------------------------
简介
----
ESP-IDF USB 主机协议栈允许 {IDF_TARGET_NAME} 作为 USB 主机运行,此时,{IDF_TARGET_NAME} 能够与各种 USB 设备通信。然而,大多数 USB 主机协议栈实现都不运行在嵌入式硬件上(即在电脑和手机端运行),因此,相对来说具有更多的资源(即,具有更高内存和 CPU 速度)。
ESP-IDF USB 主机协议栈(以下简称为主机协议栈)的实现考虑到了 {IDF_TARGET_NAME} 的嵌入式特性,这体现在主机协议栈设计的各个方面。
特性和局限性
^^^^^^^^^^^^
**主机协议栈目前支持以下显著特性:**
- 支持 FS全速和 LS低速设备
- 支持所有传输类型(控制传输、批量传输、同步传输和中断传输)
- 自动枚举已连接设备
- 允许多个类驱动程序(即 USB 主机库的客户端)同时运行并共享同一设备(即组合设备)
**主机协议栈目前存在以下显著局限:**
- 不支持 HS高速设备
- 不支持集线器(当前仅支持单个设备)