USB Host

Moderator: ESP_Bob

Unique
Posts: 21
Joined: Tue Jun 08, 2021 5:42 am

USB Host

Postby Unique » Thu Sep 23, 2021 11:07 am

使用USBh_cdc库时遇到如下问题:


[0;32mI (00:00:23.598) USB_HCDC: Resetting Port
[0m
[0;32mI (00:00:23.658) USB_HCDC: Port speed = 1
[0m
[0;32mI (00:00:23.661) USB_HCDC: Pipe Default Created[0m
[0;32mI (00:00:23.663) USB_HCDC: 1. Set Device Addr = 1[0m
[0;33mW (00:00:23.666) USB_HCDC: line 393 Pipe: default HCD_PIPE_EVENT_ERROR_XFER[0m


USB配置部分代码
void peripherals_usb_config(void)
{
static const char *TAG = "USB_configuration";
usb_ep_desc_t bulk_out_ep_desc =
{
.bLength = sizeof(usb_ep_desc_t),
.bDescriptorType = USB_B_DESCRIPTOR_TYPE_ENDPOINT,
.bEndpointAddress = 0x0f, //endpiont f
.bmAttributes = USB_BM_ATTRIBUTES_XFER_BULK,
.wMaxPacketSize = 64, //MPS of 64 bytes
.bInterval = 0,
};
usb_ep_desc_t bulk_in_ep_desc =
{
.bLength = sizeof(usb_ep_desc_t),
.bDescriptorType = USB_B_DESCRIPTOR_TYPE_ENDPOINT,
.bEndpointAddress = 0x86, //endpoint 6
.bmAttributes = USB_BM_ATTRIBUTES_XFER_BULK,
.wMaxPacketSize = 64, //MPS of 64 bytes
.bInterval = 0,
};

usbh_cdc_config_t usbh_cdc_configuration =
{
.bulk_in_ep = &bulk_in_ep_desc,
.bulk_out_ep = &bulk_out_ep_desc,
.rx_buffer_size = 1024,
.tx_buffer_size = 1024,
.rx_callback = usb_event_cd,

};

esp_err_t ret = usbh_cdc_driver_install(&usbh_cdc_configuration);
assert(ret == ESP_OK);
xTaskCreate(usb_task,"usb_task",4096,NULL,2,NULL);
ESP_LOGI(TAG,"ret:%d",ret);
}

chegewara
Posts: 2375
Joined: Wed Jun 14, 2017 9:00 pm

Re: USB Host

Postby chegewara » Fri Sep 24, 2021 9:35 pm


Unique
Posts: 21
Joined: Tue Jun 08, 2021 5:42 am

Re: USB Host

Postby Unique » Sat Sep 25, 2021 1:01 am

配置过程和例程是一样的,只是修改了端点地址和接收缓冲区大小。
出现default HCD_PIPE_EVENT_ERROR_XFER的原因一般有哪些呢?


另外,

Unique
Posts: 21
Joined: Tue Jun 08, 2021 5:42 am

Re: USB Host

Postby Unique » Sat Sep 25, 2021 1:24 am

您好,我使用的是移远的EC200N-CN配置过程和您提供的例程是一样的,只是修改了端点地址。另外,当我配置完成后将4G模块关机时,USB会提示连接已断开,这应该能说明USB连接时正常的。

但是没法正常通信,并且会有pipe的报错,这个报错通常跟哪些因素有关呢?

Unique
Posts: 21
Joined: Tue Jun 08, 2021 5:42 am

Re: USB Host

Postby Unique » Sun Sep 26, 2021 12:55 am

问题解决了,是外围USB线上多焊了一个预留的电容。
另外我想请教一下,S2 USB线上的15K下拉电阻以及USB device端标识速率的1.5K上拉电阻是否必要?

ESP_Bob
Posts: 80
Joined: Fri Nov 27, 2020 12:52 pm

Re: USB Host

Postby ESP_Bob » Sun Sep 26, 2021 3:51 am

USB 会根据所选的速率模式,自动配置内部上拉,没有必要再外部配置上拉电阻。ESP32-S2/S3 USB D+, D- 直接与设备 USB 接口相连即可。

Unique
Posts: 21
Joined: Tue Jun 08, 2021 5:42 am

Re: USB Host

Postby Unique » Sun Sep 26, 2021 5:56 am

您好,当我在使用过程中将4G模块关机后,usb会提示disconnect ,再将4g模块开机,这时USB无法通信。这种情况下是需要
1、usbh_cdc_driver_delete后再重新usbh_cdc_driver_install,
还是直接
2、usbh_cdc_driver_install呢?
两种方法我都试了一下,采用第一种方式,会在
while (xEventGroupGetBits(s_usb_event_group) & (USB_TASK_PIPES_KILL_BITS | PORT_TASK_KILL_BIT)) {
ESP_LOGW(TAG, "Waitting for USB Driver uninstall");
vTaskDelay(50 / portTICK_PERIOD_MS);
}
中一直循环。
采用第二种方式会提示
if (usb_driver_is_init()) {
ESP_LOGW(TAG, "USB Driver has inited");
return ESP_ERR_INVALID_STATE;
}
而后依然无法通信

ESP_Bob
Posts: 80
Joined: Fri Nov 27, 2020 12:52 pm

Re: USB Host

Postby ESP_Bob » Mon Sep 27, 2021 11:51 am

4G 模块关机以后 USB 通信将断开。由于当前 USB Host 协议栈还不完善,不支持热插拔等操作。如果重新开机,目前的建议是,通过 IO 控制 4G 模块开机以后,将 ESP32S2 直接 restart。

Unique
Posts: 21
Joined: Tue Jun 08, 2021 5:42 am

Re: USB Host

Postby Unique » Tue Sep 28, 2021 12:51 am

好的,感谢

Unique
Posts: 21
Joined: Tue Jun 08, 2021 5:42 am

Re: USB Host

Postby Unique » Sat Oct 09, 2021 6:35 am

有个问题再请教一下:
使用过程中,无法发送64byte数据,也就是wMaxPacketSize大小的数据,看网上STM32的解决方案是当数据长度正好为64Byte时,补发一包0字节的数据,告诉USB控制器数据已经发送完成了。但是我尝试过之后发现在ESP32 S2上不可行。
请问有其他的解决方案吗?

Code: Select all

void network_lte_send(const void* src, size_t size)
{
  static const char *TAG = "USB输出";
  switch (LTE_trans_mode_default)
  {
  case LTE_trans_usb:
    if(size == 64)
    {
      ESP_LOGI(TAG,"64字节");
      usbh_cdc_write_bytes(src,size);
      usbh_cdc_write_bytes(NULL,0);
    }
    else
    {
      usbh_cdc_write_bytes(src,size);
    }
    break;
  case LTE_trans_uart:
    uart_write_bytes(UART_NUM_0,src,size);
  default:
    break;
  }
}

Who is online

Users browsing this forum: No registered users and 35 guests