44b0+ch375外置固件设备方式问题

按照论坛上的贴子修改的程序,程序如附件所示,用串口取到的消息如下: Ch375 init ... init successed! Set device mode done! 外置固件从机模式 InterruptStatus:07 中断状态,此时表示USB总线复位 InterruptStatus:07 InterruptStatus:07 InterruptStatus:07 InterruptStatus:07 InterruptStatus:07 InterruptStatus:0c [80] [06] [00] [01] [00] [00] [40] [00] 收到setup包 12 01 10 01 00 00 00 08 InterruptStatus:08 6EP0_IN 表示6号命令的ep0_in事务 8f 05 80 93 00 02 00 00 InterruptStatus:00 EP0_OUT InterruptStatus:00 EP0_OUT InterruptStatus:00 EP0_OUT InterruptStatus:00 EP0_OUT InterruptStatus:0c [00] [05] [38] [00] [00] [00] [00] [00] ---设置USB新地址 InterruptStatus:08 5EP0_IN new adderss:56 InterruptStatus:0c [80] [06] [00] [01] [00] [00] [12] [00] ---重新请求描述符 12 01 10 01 00 00 00 08 InterruptStatus:08 6EP0_IN 8f 05 80 93 00 02 00 00 InterruptStatus:08 6EP0_IN 00 01 InterruptStatus:08 6EP0_IN         设备描述符已经传完了,接着复位了 InterruptStatus:00 EP0_OUT InterruptStatus:07 ------------下面开始又重复一次,三次过后,电脑提示无法识别

InterruptStatus:07 InterruptStatus:07 InterruptStatus:07 InterruptStatus:07 InterruptStatus:07 InterruptStatus:07 InterruptStatus:07 InterruptStatus:07 InterruptStatus:0c [80] [06] [00] [01] [00] [00] [40] [00] 12 01 10 01 00 00 00 08 InterruptStatus:08 6EP0_IN 8f 05 80 93 00 02 00 00 InterruptStatus:00 EP0_OUT InterruptStatus:00 EP0_OUT InterruptStatus:00 EP0_OUT InterruptStatus:0c [00] [05] [39] [00] [00] [00] [00] [00] InterruptStatus:08 5EP0_IN new adderss:57 InterruptStatus:0c [80] [06] [00] [01] [00] [00] [12] [00] 12 01 10 01 00 00 00 08 InterruptStatus:08 6EP0_IN 8f 05 80 93 00 02 00 00 InterruptStatus:08 6EP0_IN 00 01 InterruptStatus:08 6EP0_IN InterruptStatus:00 EP0_OUT InterruptStatus:07 InterruptStatus:07 InterruptStatus:07 InterruptStatus:07 InterruptStatus:07 InterruptStatus:07 InterruptStatus:07 InterruptStatus:07 InterruptStatus:07 InterruptStatus:0c [80] [06] [00] [01] [00] [00] [40] [00] 12 01 10 01 00 00 00 08 InterruptStatus:08 6EP0_IN 8f 05 80 93 00 02 00 00 InterruptStatus:00 EP0_OUT InterruptStatus:00 EP0_OUT InterruptStatus:00 EP0_OUT InterruptStatus:00 EP0_OUT InterruptStatus:00 EP0_OUT InterruptStatus:0c [00] [05] [3a] [00] [00] [00] [00] [00] InterruptStatus:08 5EP0_IN new adderss:58 InterruptStatus:0c [80] [06] [00] [01] [00] [00] [12] [00] 12 01 10 01 00 00 00 08 InterruptStatus:08 6EP0_IN 8f 05 80 93 00 02 00 00 InterruptStatus:08 6EP0_IN 00 01 InterruptStatus:08 6EP0_IN InterruptStatus:00 EP0_OUT

-----这就提示无法识别了,从现象来看,好像电脑这边为什么会老是复位呢?另外EP0_OUT和SETUP之间有什么关系呢,总之还请做过CH375外置从机程序的同行们指点一下,翻来复去都测一周多了,先谢谢了。

附件没传上来,代码发上来。

unsigned char USBDISK[2*1024*1024];

unsigned char SystemBuffer[520]; unsigned char UsbBuffer[2048]; unsigned char SystemStatus; unsigned int UsbReadPoint,UsbWritePoint; unsigned char dCBWTag[4]; unsigned int dCBWDataTransferLength; unsigned char CBWCBLength; unsigned int LBA_adder,Block,Page; unsigned short BlockLength; unsigned char SendFlag,NewAddr=0;

//================外置固件设备模式=================== unsigned char mVarSetupRequest; // USB请求码 unsigned char mVarSetupLength; // 后续数据长度 unsigned char * VarSetupDescr; // 描述符偏移地址 unsigned char VarUsbAddress=0; // 暂存主机分来的地址 unsigned char CH375CONFLAG; // 配置标志

mREQUEST_PACKET Request; unsigned char DevDes[]={ 0x12 //描述符大小 , 0x01 //常数DEVICE , 0x10 //USB规范版本信息 , 0x01 , 0x00 //类别码, , 0x00 //子类别码 , 0x00 //协议码 , 0x08 //端点0的最大信息包大小 , 0x8f //厂商ID , 0x05 , 0x80 //产品ID , 0x93 , 0x00 //设备版本信息 , 0x02 , 0x00 //索引值 , 0x00 , 0x00 , 0x01 //可能配置的数目 }; //配置描述符 unsigned char ConDes[]={ 0x09, //描述符大小 0x02, //配置描述符 0x2e, 0x00, //此配置所返回的所有数据大小 0x01, //此配置支持的接口数 0x01, //Set_Configration中的参数 0x00, //描述此配置的字符串索引值 0x80, //供电模式的选择 0x32, //设备从总线提取的最大电流50ma 0x09, //描述符大小 0x04, //接口描述符 0x00, //该接口编号 0x00, //该接口使用的端点数,不算端点0 0x04, //该接口使用的端点数,不算端点0 0x08, //接口类型 Mass Storage Class 0x06, //接口子类型 存储介质 0x50, //协议代码 BULK-ONLY TRANSPORT 0x00, //描述该接口的字符串索引值 0x07,0x05,0x82, 0x02, 0x40, 0x00, 0x00, 0x07,0x05,0x02, 0x02, 0x40, 0x00, 0x00, 0x07,0x05,0x81, 0x03, 0x08, 0x00, 0x01, 0x07,0x05,0x01, 0x02, 0x08, 0x00, 0x00, }; //端点0数据上传 void mCh375Ep0Up(void) { unsigned char i,len; if(mVarSetupLength) { //长度不为0传输具体长度的数据 if(mVarSetupLength<=8) { len=mVarSetupLength; mVarSetupLength=0; } //长度小于8则长输要求的长度 else { len=8; mVarSetupLength-=8; } //长度大于8则传输8个,切总长度减8 CH375_WR_CMD_PORT(CMD_WR_USB_DATA3); //发出写端点0的命令 CH375_WR_DAT_PORT(len); //写入长度 for(i=0;i!=len;i++) { Uart_Printf("%02x ",Request.buffer[i]); CH375_WR_DAT_PORT(Request.buffer[i]); //循环写入数据 } Uart_Printf("\n"); } else { CH375_WR_CMD_PORT(CMD_WR_USB_DATA3); //发出写端点0的命令 CH375_WR_DAT_PORT(0); //上传0长度数据,这是一个状态阶段 } }

//复制描述符以便上传 void mCh375DesUp(void) { unsigned char k; for (k=0; k!=8; k++ ) { Request.buffer[k]=*VarSetupDescr; //依次复制8个描述符, VarSetupDescr++; } } //===================================================

//INIT ch375 void CH375_Init( void ) { unsigned char i, k; unsigned char RD_Data; Uart_Printf("Ch375 init ...\n"); for( k=10; k!=0; k-- ) { CH375_COMM=CMD_RESET_ALL; EZUSB_Delay(100); CH375_COMM=CMD_CHECK_EXIST; EZUSB_Delay(1); i = 0xa5; CH375_DATA= i; EZUSB_Delay(1); i = ~i; RD_Data = CH375_DATA; EZUSB_Delay(1); if ( RD_Data != i ) { for ( i=5; i!=0; i-- ) CH375_COMM=CMD_RESET_ALL; EZUSB_Delay(100); } else { Uart_Printf("init successed!\n"); break; } } if( k==0 ) { Uart_Printf("init falure!\n"); } //CH375_COMM=CMD_GET_IC_VER; //EZUSB_Delay(100); //Uart_Printf("Ver=%d\n",CH375_DATA); CH375_WR_CMD_PORT( CMD_SET_USB_MODE ); CH375_WR_DAT_PORT( 1 ); /* 设置为使用外置固件的USB设备方式 */ for ( ;; ) { /* 等待操作成功,通常需要等待10uS-20uS */ if ( CH375_RD_DAT_PORT( )==CMD_RET_SUCCESS ) break; } Uart_Printf("Set device mode done!\n"); }

// CH375中断服务程序,CH375的INT#引脚连接到eint0 void __irq CH375Interrupt(void) { unsigned char InterruptStatus; unsigned char length, len,c1,CH375FLAGERR; unsigned char cbw_error; unsigned int point; unsigned char tmp,command; rI_ISPC=BIT_EINT0; CH375_WR_CMD_PORT(CMD_GET_STATUS); //获取中断状态并取消中断请求 CH375FLAGERR =0; InterruptStatus = CH375_RD_DAT_PORT(); //获取中断状态 Uart_Printf("InterruptStatus:%02x\n",InterruptStatus); switch( InterruptStatus ) //分析中断状态 { case USB_INT_EP2_OUT: // 批量端点下传成功 CH375_WR_CMD_PORT( CMD_RD_USB_DATA ); //从当前USB中断的端点缓冲区读取数据块,并释放缓冲区 length = CH375_RD_DAT_PORT(); //首先读取后续数据长度 if ( length != 0 ) //如果长度为0则不处理 { for (len=0;len { SystemBuffer[len] = CH375_RD_DAT_PORT(); Uart_Printf("%02x ",SystemBuffer[len]); } Uart_Printf("\n"); } break; case USB_INT_EP2_IN: //批量端点上传成功 CH375_WR_CMD_PORT( CMD_UNLOCK_USB ); //释放缓冲区 break; //========================================================================== case USB_INT_EP0_SETUP: //控制端点建立成功 CH375_WR_CMD_PORT(CMD_RD_USB_DATA); length=CH375_RD_DAT_PORT(); for( len=0;len { Request.buffer[len] = CH375_RD_DAT_PORT(); // 取出数据 Uart_Printf("[%02x] ",Request.buffer[len]); } Uart_Printf("\n"); // 取出数据 if(length==0x08) { mVarSetupLength=Request.buffer[6]; //控制传输数据长度最大设置为128 //if((c1=Request.r.bmReuestType)&0x40) //{ //厂商请求,未处理 //} //if((c1=Request.r.bmReuestType)&0x20) //{// printf("b\n"); //类请求,未处理 // if(Request.buffer[1]==0x0a) // {//printf("c\n"); // } //SET_IDLE // else if(Request.buffer[1]==0x09) // { // // } //} if(!((c1=Request.r.bmReuestType)&0x60)) { //标准请求 mVarSetupRequest=Request.r.bRequest; //暂存标准请求码 switch(Request.r.bRequest) { // 分析标准请求 case DEF_USB_CLR_FEATURE: //清除特性 if((c1=Request.r.bmReuestType&0x1F)==0X02) { //不是端点不支持 switch(Request.buffer[4]) { case 0x82: CH375_WR_CMD_PORT(CMD_SET_ENDP7); //清除端点2上传 CH375_WR_DAT_PORT(0x8E); //发命令清除端点 break; case 0x02: CH375_WR_CMD_PORT(CMD_SET_ENDP6); CH375_WR_DAT_PORT(0x80); //清除端点2下传 break; case 0x81: CH375_WR_CMD_PORT(CMD_SET_ENDP5); //清除端点1上传 CH375_WR_DAT_PORT(0x8E); break; case 0x01: CH375_WR_CMD_PORT(CMD_SET_ENDP4); //清除端点1下传 CH375_WR_DAT_PORT(0x80); break; default: break; } } else { CH375FLAGERR=1; //不支持的清除特性,置错误标志 } break; case DEF_USB_GET_STATUS: //获得状态 Request.buffer[0]=0; Request.buffer[1]=0; //上传状态 break; case DEF_USB_SET_ADDRESS: //设置地址 VarUsbAddress=Request.buffer[2]; //暂存USB主机发来的地址 break; case DEF_USB_GET_DESCR: //获得描述符 if(Request.buffer[3]==1) //设备描述符上传 { VarSet


附加问一句,CH375内置从机固件是用U盘还是模拟软盘,我使用过内置固件方式,用到BULK-ONLY中0x23,0x25,0x28甚至还有0x5a,好像挺复杂,不知道有没有使用375内置固件的实例呢?


上传描述符的流程没什么问题 不知道你串口波特率是多少,尽量调高一点,57600试试


首先谢谢您的回复,实际上我串口波特率就是57600,从现象来看是USB总线为什么在得到设备描述符后,没有接着获取配置描述符,相反而莫名其妙的出现USB总线复位,


您在监控程序的过程中加入了许多的打印输出,这样就无法保证PC机枚举的时间的及时性,PC机枚举的时候时间方面是有要求的,你加了许多的打印输出,这样就相当与许多的延时,PC机在相应的时间内没有获取到描述符,所以就回不断的复位,直到告之无法识别此设备,所以建议您这个时候将所有的打印输出去掉再试一下,如果程序没有问题的话,PC机应该能找到设备!


楼上所述很正确。


只有登录才能回复,可以选择微信账号登录