CH32V307 USB鍵盤示例不能接掃碼槍【緊急】

接USB鍵盤正常,接一個USB的掃碼槍就不正常了

理論上USB鍵盤和掃碼槍是一個東西。

這個當(dāng)一掃碼時,掃碼槍先發(fā)一個8字節(jié)包,其中第2個字節(jié)是控制大小寫的,即0x39,然后收到這個后自動回復(fù)

if( keybufdata[0x02] == 0x39 )

?{

????endp0outdata[ 0 ] ^= 0x02;

????lockflag = 1;

},就在自動回復(fù)的代碼中返回了0x2a錯誤

錯誤碼如下:#define ERR_USB_TRANSFER? ? ?0x20

用的是【\HOST_KM】示例,沒有做任何修改,USB HS/FS都試了,都有這個問題,

緊急求救,之前一直用鍵盤試,感覺沒問題,誰知道插這個掃碼槍就出現(xiàn)此毛病。

SystemClk:144000000
USBFS?HOST?KM?Test
New?Device?In
Enum?Succeed
Device?Desc
12?01?10?01?00?00?00?40?10?20?38?76?00?00?01?02?03?01?
Configuration?Desc
09?02?22?00?01?01?00?80?c8?09?04?00?00?01?03?01?01?00?09?21?10?01?00?01?22?3f?00?07?05?83?03?08?00?01?
Device?Status?00
Device?Speed??01
Device?Type???01
Device?Addr???02
InterFace?Type?01
EndpIn???00
Addr?????03
Type?????03
Size?????08
InterVal?01
Recv?00?00?39?00?00?00?00?00?
err?2a
Recv?00?00?00?00?00?00?00?00?
Device?Out


以下是HOST-KM代碼,默認(rèn)的示例:

int?main(void)
{
????UINT8??s;
????UINT16?i,?j,?k;
????UINT16?desclen;
????UINT8??lockflag?=?0;
????UINT8??len;
????UINT8??endp0outdata[16];
????UINT8??keybufdata[16];
????USART_Printf_Init(115200);
????Delay_Init();
????printf("SystemClk:%d\r\n",SystemCoreClock);
????printf("USBFS?HOST?KM?Test\r\n");
????Timer3_Init(?);

????USBOTG_HostInit(ENABLE);
????while(1)
????{
????????s?=?ERR_SUCCESS;
????????if?(?USBOTG_H_FS->INT_FG?&?USBHD_UIF_DETECT?)
????????{
????????????USBOTG_H_FS->INT_FG?=?USBHD_UIF_DETECT?;
????????????s?=?AnalyzeRootHub(?);
????????????HostCtl[0].DeviceState?=?s;
????????????if?(?s?==?ERR_USB_CONNECT?)
????????????{
????????????????printf(?"New?Device?In\r\n"?);
????????????????/*?準(zhǔn)備設(shè)備操作相關(guān)的存儲空間?*/
????????????????Clear_HOST_CTL_Struct(?0?);
????????????????lockflag?=?0;
????????????????FoundNewDev?=?1;
????????????????for(?i=0;?i<16;?i++?)
????????????????{
????????????????????keybufdata[i]?=?0;
????????????????????endp0outdata[i]?=?0;
????????????????}
????????????????endp0outdata[?0?]?=?0x01;
????????????}
????????????if(?s?==?ERR_USB_DISCON?)
????????????{
????????????????printf(?"Device?Out\r\n"?);
????????????????HostCtl[0].DeviceState?=?0xFF;
????????????????HostCtl[0].DeviceType??=?0xFF;
????????????????USBOTG_H_FS->HOST_RX_DMA?=?(UINT32)&endpRXbuff[0];?????????????????//host?rx?DMA?address
????????????????USBOTG_H_FS->HOST_TX_DMA?=?(UINT32)&endpTXbuff[0];?????????????????//host?tx?DMA?address
????????????}
????????}

????????if?(?FoundNewDev?||?s?==?ERR_USB_CONNECT?)
????????{
????????????FoundNewDev?=?0;
????????????Delay_Ms(?200?);
????????????s?=?USBOTG_HostEnum(?endpRXbuff?);
????????????HostCtl[0].DeviceState?=?s;
????????????if?(?s?==?ERR_SUCCESS?)
????????????{
????????????????TIM_Cmd(TIM3,?ENABLE);
????????????????printf(?"Enum?Succeed\r\n"?);

????????????????printf(?"Device?Desc\n"?);
????????????????desclen?=?DeviceDescriptor[0];
????????????????for(?i=0;?i=?HostCtl[0].Interface[i].InEndpInterval[j]?)
????????????????????????{
????????????????????????????HostCtl[0].Interface[i].InEndpTimeCount[j]?=?0;
????????????????????????????/*?使用單獨的緩沖區(qū)地址?*/
????????????????????????????USBOTG_H_FS->HOST_RX_DMA?=?(UINT32)keybufdata;????????????????????????????????//設(shè)置接收DMA地址
????????????????????????????s?=?USBHostTransact(?USB_PID_IN?<<?4?|?HostCtl[0].Interface[i].InEndpAddr[j],?HostCtl[0].Interface[i].InEndpTog[j],?0?);
????????????????????????????if?(?s?==?ERR_SUCCESS?)
????????????????????????????{
????????????????????????????????HostCtl[0].Interface[i].InEndpTog[j]?^=?USBHD_UH_R_TOG;
????????????????????????????????if(?USBOTG_H_FS->RX_LEN?>?0?)
????????????????????????????????{
????????????????????????????????????printf(?"Recv?"?);
????????????????????????????????????for(?k=0;?kRX_LEN;?k++?)
????????????????????????????????????{
????????????????????????????????????????printf(?"%02x?",?keybufdata[k]?);
????????????????????????????????????}
????????????????????????????????????printf(?"\n"?);
????????????????????????????????????/*?CapsLock?*/
//??????????????????????????????????NUMLOCK?0X01
//??????????????????????????????????CAPLOCK?0X02
//??????????????????????????????????SCROLLLOCK?0X04
????????????????????????????????????if(?keybufdata[0x02]?==?0x39?)
????????????????????????????????????{
???????????????????????????????????????endp0outdata[?0?]?^=?0x02;
???????????????????????????????????????lockflag?=?1;
????????????????????????????????????}
????????????????????????????????????/*?ScrollLock?*/
????????????????????????????????????else?if(?keybufdata[0x02]?==?0x47?)
????????????????????????????????????{
???????????????????????????????????????endp0outdata[?0?]?^=?0x04;
???????????????????????????????????????lockflag?=?1;
????????????????????????????????????}
????????????????????????????????????/*?NumLock?*/
????????????????????????????????????else?if(?keybufdata[0x02]?==?0x53?)
????????????????????????????????????{
???????????????????????????????????????endp0outdata[?0?]?^=?0x01;
???????????????????????????????????????lockflag?=?1;
????????????????????????????????????}
????????????????????????????????????if(?lockflag?)
????????????????????????????????????{
????????????????????????????????????????lockflag?=?0;
????????????????????????????????????????/*?SetReport?*/
????????????????????????????????????????CopySetupReqPkg(?HIDSetReport?);
????????????????????????????????????????USBOTG_H_FS->HOST_TX_DMA?=?(UINT32)endpTXbuff;
????????????????????????????????????????USBOTG_H_FS->HOST_TX_LEN?=?8;
????????????????????????????????????????s?=?HostCtrlTransfer(?endp0outdata,?&len?);
????????????????????????????????????????if?(?s?!=?ERR_SUCCESS?)
????????????????????????????????????????{
???????????????????????????????????????????printf(?"err?%02x\n",?s?);
????????????????????????????????????????}
????????????????????????????????????}
????????????????????????????????}
????????????????????????????}
????????????????????????}
????????????????????}
????????????????}
????????????}
????????}
?????}
}



用的示例是【CH32V307\EVT\EXAM\USB\USBFS\HOST_KM】


image.png

這里返回了錯誤0x2a


非常感謝客服,下班了也有人接技術(shù)電話。


最新情況:

換了兩把掃描槍,有問題的是得力的,沒有問題的是霍尼韋爾

兩個插電腦上都是正常的。

可以肯定的是示例沒有考慮到某一塊的兼容性,明天再繼續(xù)查找問題。

客戶用這個板子我們不能限定他使用什么掃描槍。

希望能得到官方回復(fù)。



兩者區(qū)別是:

得力先發(fā)送0x39/CAPS LOCK,再發(fā)送正常的文本,即使發(fā)送純文本也會發(fā)送該條消息。

霍尼韋爾則是利用的HID的本身的前2個字節(jié)來確定大小寫

霍尼韋爾掃碼:abcABC收到的HID消息

Recv?00?00?00?00?00?00?00?00?
Recv?00?00?04?00?00?00?00?00?
Recv?00?00?00?00?00?00?00?00?
Recv?00?00?05?00?00?00?00?00?
Recv?00?00?00?00?00?00?00?00?
Recv?00?00?06?00?00?00?00?00?
Recv?00?00?00?00?00?00?00?00?
Recv?02?00?00?00?00?00?00?00?
Recv?02?00?04?00?00?00?00?00?
Recv?02?00?00?00?00?00?00?00?
Recv?00?00?00?00?00?00?00?00?
Recv?02?00?05?00?00?00?00?00?
Recv?02?00?00?00?00?00?00?00?
Recv?00?00?00?00?00?00?00?00?
Recv?02?00?06?00?00?00?00?00?
Recv?02?00?00?00?00?00?00?00?
Recv?00?00?00?00?00?00?00?00?
Recv?00?00?00?00?00?00?00?00?
Recv?00?00?28?00?00?00?00?00?
Recv?00?00?00?00?00?00?00?00?
Recv?03?00?00?00?00?00?00?00?
Recv?03?00?0d?00?00?00?00?00?
Recv?03?00?00?00?00?00?00?00?
Recv?00?00?00?00?00?00?00?00

得力的消息:

Recv 00 00 39 00 00 00 00 00?

然后回復(fù)時就報錯了。


加了調(diào)試日志,發(fā)現(xiàn)在

ch32vf30x_usbfs.host.c文件中

【USBHostTransact】函數(shù)中

image.png

此行代碼報超時錯誤,并且只要在插上USB掃碼槍后,即使沒有掃碼動作也報超時錯誤。掃碼時報這個錯誤后就造成掃碼槍直接復(fù)位了。


有問題型號:

image.png


正常型號:

image.png



兩者插了數(shù)個電腦,掃碼都是正常。


您好,可以通過USB分析儀抓一下307與掃碼槍的數(shù)據(jù)交互過程,如果有新的問題可以加我微信溝通。V:19951759326


只有登錄才能回復(fù),可以選擇微信賬號登錄

国产91精品新入口,国产成人综合网在线播放,九热这里只有精品,本道在线观看,美女视频a美女视频,韩国美女激情视频,日本美女pvp视频