最近在使用CH376,单片机为cortex-m3的arm单片机,想试图读取超出64Bytes的config desc,参考了官方的
SETUP_Transfer函数,但一直是失败的,
麻烦各位dalao能不能看看有什么问题
unsigned short MeUsb::SETUP_Transfer( unsigned char *DataBuf, int *plen) { printf("%s:%d\r\n", __func__, __LINE__); unsigned char l, s; unsigned short req_len, real_len = 0; unsigned char *p = DataBuf; endp7_mode = 0x80; //DATA0发送器 endp6_mode = 0xc0; //DATA1接收器 req_len = (unsigned short int)Request.Req.wLength; /* SETUP阶段 */ wr_usb_data(8, Request.Req_buf); toggle_send(); s = issue_token((0 << 4) | DEF_USB_PID_SETUP ); if (s != USB_INT_SUCCESS) { return (0); } /* DATA阶段 */ if (Request.Req_buf[0] & 0x80) //IN数据 { printf("%s:%d\r\n", __func__, __LINE__); while (req_len) { printf("%s:%d\r\n", __func__, __LINE__); toggle_recv(); s = issue_token((0 << 4) | DEF_USB_PID_IN); if ( s == USB_INT_SUCCESS ) { printf("%s:%d\r\n", __func__, __LINE__); l = rd_usb_data( p ); real_len += l; if ( l < max_package ) //短包 { break; } p += l; req_len -= l; } else return (0); } } else //OUT数据 { printf("%s:%d\r\n", __func__, __LINE__); while (req_len) { printf("%s:%d\r\n", __func__, __LINE__); l = (req_len > max_package) ? max_package : req_len; wr_usb_data(l, p); toggle_send(); s = issue_token((0 << 4) | DEF_USB_PID_OUT); if ( s == USB_INT_SUCCESS ) { real_len += l; p += l; req_len -= l; } else return (0); } } /* 状态阶段 */ endp7_mode = endp6_mode = 0xc0; //DATA1 if (Request.Req_buf[0] & 0x80) { wr_usb_data(0, Request.Req_buf); toggle_send(); s = issue_token((0 << 4) | DEF_USB_PID_OUT); } else { toggle_recv(); s = issue_token((0 << 4) | DEF_USB_PID_IN); } if (s != USB_INT_SUCCESS) { return (0); } *plen = real_len; return (s); //成功 }
串口通讯的数据是这样的,不管是get config 还是get status到后面读取数据都是0.,采用自带的指令可以正常获取到desc,但是最高只能到64bytes,有些鼠标键盘的desc已经超过了64bytes了
>>57,AB
>>45
>>5
>>57,AB
>>22
<<14
>>57,AB
>>13
>>5
>>57,AB
>>22
<<14
usb wr:8
>>57,AB
>>2B
>>8
>>80
>>8
>>0
>>0
>>0
>>0
>>1
>>0
toggle send:80
>>57,AB
>>1D
>>80
>>57,AB
>>4F
>>D
issue token:D
>>57,AB
>>22
<<14
>>57,AB
>>1C
>>C0
toggle recv:C0
>>57,AB
>>4F
>>9
issue token:9
>>57,AB
>>22
<<14
>>57,AB
>>27
<<0