USB ECM 主机驱动

[English]

iot_usbh_ecm 是基于 USB 接口的 ECM 协议的主机驱动。

ECM 协议

ECM(Ethernet Control Model) 通过将以太网帧封装在 USB 报文里,实现网络通信。

USB 描述符

ECM 接口一般由一个两个接口描述符和类特殊描述符组成。第一个接口描述符的 bInterfaceClass0x02bInterfaceSubClass0x06。 ECM 功能描述符 usb_ecm_function_desc_t 中的 iMACAddress 为 MAC 地址的字符串索引, wMaxSegmentSize 为以太网帧的最大长度(默认为 1514)。

备注

一些 ECM 设备的配置描述符不为默认的 config 1,因此需要开启宏 CONFIG_USB_HOST_ENABLE_ENUM_FILTER_CALLBACK 并实现枚举过滤回调函数。

示例描述符:

*** Interface descriptor ***
bLength 9
bDescriptorType 4
bInterfaceNumber 0
bAlternateSetting 0
bNumEndpoints 1
bInterfaceClass 0x2
bInterfaceSubClass 0x6
bInterfaceProtocol 0x0
iInterface 5
        *** Endpoint descriptor ***
        bLength 7
        bDescriptorType 5
        bEndpointAddress 0x81   EP 1 IN
        bmAttributes 0x3        INT
        wMaxPacketSize 64
        bInterval 8
*** Interface descriptor ***
bLength 9
bDescriptorType 4
bInterfaceNumber 1
bAlternateSetting 0
bNumEndpoints 0
bInterfaceClass 0xa
bInterfaceSubClass 0x0
bInterfaceProtocol 0x0
iInterface 0
*** Interface descriptor ***
bLength 9
bDescriptorType 4
bInterfaceNumber 1
bAlternateSetting 1
bNumEndpoints 2
bInterfaceClass 0xa
bInterfaceSubClass 0x0
bInterfaceProtocol 0x0
iInterface 0
        *** Endpoint descriptor ***
        bLength 7
        bDescriptorType 5
        bEndpointAddress 0x82   EP 2 IN
        bmAttributes 0x2        BULK
        wMaxPacketSize 64
        bInterval 0
        *** Endpoint descriptor ***
        bLength 7
        bDescriptorType 5
        bEndpointAddress 0x3    EP 3 OUT
        bmAttributes 0x2        BULK
        wMaxPacketSize 64
        bInterval 0

速率测试

以太网转 USB 设备

ESP32-S3/P4 连接 以太网转 USB 设备(CH397A),并开启 softAP,手机连接 softAP 进行网络测速:

芯片

上行(Mbps)

下行(Mbps)

ESP32-S3

6.6

7.2

ESP32-P4 with ESP32-C6

11.7

14.7

4G 模组

暂无

资料下载

CDC1.2 协议文档

API 参考

Header File

Functions

esp_err_t iot_eth_new_usb_ecm(const iot_usbh_ecm_config_t *config, iot_eth_driver_t **ret_handle)

Create a new USB ECM Ethernet driver.

This function initializes a new USB ECM Ethernet driver with the specified configuration. It allocates memory for the driver, sets up the driver functions, and returns a handle to the driver.

参数
  • config – Pointer to the ECM configuration structure.

  • ret_handle – Pointer to a location where the handle to the new Ethernet driver will be stored.

返回

  • ESP_OK: Driver created successfully

  • ESP_ERR_INVALID_ARG: Invalid argument (NULL config or ret_handle)

  • ESP_ERR_NO_MEM: Memory allocation failed

Structures

struct iot_usbh_ecm_config_t

USB Host Ethernet ECM Configuration.

Public Members

bool auto_detect

Auto detect ECM device

TickType_t auto_detect_timeout

Auto detect timeout in ticks, used when auto_detect is true

uint16_t vid

USB device vendor ID, used when auto_detect is false

uint16_t pid

USB device product ID, used when auto_detect is false

int itf_num

ecm device notif interface numbers, used when auto_detect is false