ESP32S3 USB CDC设备通信缓冲区问题
Posted: Mon Jun 13, 2022 1:46 am
环境 win11 ESP IDF4.4.1 ESP32S3
测试用例代码如下:
void tinyusb_cdc_rx_callback(int itf, cdcacm_event_t *event)
{
/* initialization */
size_t rx_size = 0;
static uint32_t recv_total_len = 0;
static uint32_t count = 0;
/* read */
esp_err_t ret = tinyusb_cdcacm_read(itf, buf, CONFIG_TINYUSB_CDC_RX_BUFSIZE, &rx_size);
if (ret == ESP_OK) {
buf[rx_size] = '\0';
ESP_LOGI(TAG, "Got data (%d bytes): %s", rx_size, buf);
} else {
ESP_LOGE(TAG, "Read error");
}
}
在官方的CDC测试用例代码中,我尝试修改了RX TX FIFO大小,但是这个回调函数每次读取到的数据最大也就是64字节。修改了很多地方对这个值都没有影像。数据无论发送多快都是每次只接收到64字节。并且在一次回调中多次调用tinyusb_cdcacm_read接口,但是从第二次调用开始都会返回失败。
我想达到的目的是:加大缓冲区大小,尽量减少调用这个回调函数,减少cpu负载。
I (497) TinyUSB: TinyUSB Driver installed
I (497) example: USB initialization DONE
I (797) example: Line state changed! dtr:0, rst:0
I (857) example: Line state changed! dtr:0, rst:0
I (5697) example: Line state changed! dtr:0, rst:0
I (5707) example: Line state changed! dtr:0, rst:0
I (6597) example: Got data (64 bytes): test575275727527522752775242752427575375752752275242737527527521
I (6607) example: Got data (64 bytes): 2753753546546456456456456456456789789789643786789789789789789789
I (6617) example: Got data (50 bytes): 789546456456213123123123123123123123123123123123c7
I (8797) example: Got data (64 bytes): test575275727527522752775242752427575375752752275242737527527521
I (8807) example: Got data (64 bytes): 2753753546546456456456456456456789789789643786789789789789789789
I (8817) example: Got data (50 bytes): 789546456456213123123123123123123123123123123123c7
测试用例代码如下:
void tinyusb_cdc_rx_callback(int itf, cdcacm_event_t *event)
{
/* initialization */
size_t rx_size = 0;
static uint32_t recv_total_len = 0;
static uint32_t count = 0;
/* read */
esp_err_t ret = tinyusb_cdcacm_read(itf, buf, CONFIG_TINYUSB_CDC_RX_BUFSIZE, &rx_size);
if (ret == ESP_OK) {
buf[rx_size] = '\0';
ESP_LOGI(TAG, "Got data (%d bytes): %s", rx_size, buf);
} else {
ESP_LOGE(TAG, "Read error");
}
}
在官方的CDC测试用例代码中,我尝试修改了RX TX FIFO大小,但是这个回调函数每次读取到的数据最大也就是64字节。修改了很多地方对这个值都没有影像。数据无论发送多快都是每次只接收到64字节。并且在一次回调中多次调用tinyusb_cdcacm_read接口,但是从第二次调用开始都会返回失败。
我想达到的目的是:加大缓冲区大小,尽量减少调用这个回调函数,减少cpu负载。
I (497) TinyUSB: TinyUSB Driver installed
I (497) example: USB initialization DONE
I (797) example: Line state changed! dtr:0, rst:0
I (857) example: Line state changed! dtr:0, rst:0
I (5697) example: Line state changed! dtr:0, rst:0
I (5707) example: Line state changed! dtr:0, rst:0
I (6597) example: Got data (64 bytes): test575275727527522752775242752427575375752752275242737527527521
I (6607) example: Got data (64 bytes): 2753753546546456456456456456456789789789643786789789789789789789
I (6617) example: Got data (50 bytes): 789546456456213123123123123123123123123123123123c7
I (8797) example: Got data (64 bytes): test575275727527522752775242752427575375752752275242737527527521
I (8807) example: Got data (64 bytes): 2753753546546456456456456456456789789789643786789789789789789789
I (8817) example: Got data (50 bytes): 789546456456213123123123123123123123123123123123c7