我現(xiàn)在使用CH376做USB_DEVICE模式,希望能被PC枚舉為HID類設備,現(xiàn)在程序中追到了USB_INT_EP0_SETUP命令,也正常進入USB_INT_EP0_SETUP處理子程序,并判斷出是獲取配置命令,即DEF_USB_GET_DESCR,而且正確執(zhí)行DEF_USB_GET_DESCR程序,從PC上位機接收到 80 06 00 01 00 00 40 00 的數(shù)據(jù),然后上傳設備描述符: 12 01 10 01 00 00 00 08 但是通過示波器觀察,程序會重復收到USB_INT_EP0_SETUP命令,然后重復執(zhí)行USB_INT_EP0_SETUP子程序。我把這段代碼貼出來,麻煩大家?guī)臀铱聪履睦锍隽藛栴}:
========================================================= 處理USB_INT_EPO_SETUP事務開始 ======================================================== PROCESS_USB_INT_EP0_SETUP: JSR SELECT_CH376_ENABLE ;;片選使能 LDA #CMD_RD_USB_DATA ;;發(fā)送讀命令 JSR SPI_DATA_TRANSMIT ;;發(fā)送數(shù)據(jù) JSR SPI_DATA_RECEIVE ;;接收讀出來的數(shù)據(jù) LDA SPI_DATA_BUFFER ;;第一個數(shù)據(jù)是長度 STA DOWN_DATA_LENGTH ;;保存長度 LDY #00H ;;循環(huán)接收數(shù)據(jù) PROCESS_USB_INT_EP0_SETUP_LOOP: JSR SPI_DATA_RECEIVE LDA SPI_DATA_BUFFER STA DATA_BUFFER_START,Y ;;以DATA_BUFFER_START為起始地址保存 INY CPY DOWN_DATA_LENGTH ;;接收完畢? BNE PROCESS_USB_INT_EP0_SETUP_LOOP ;;循環(huán)接收 JSR SELECT_CH376_DISABLE ;;接收完畢則禁止片選使能 PROCESS_USB_INT_EP0_SETUP_DONE: LDA DOWN_DATA_LENGTH CMP #08H ;;數(shù)據(jù)長度不為8則不理睬 BNE PROCESS_USB_INT_EP0_SETUP_ERR LDX #06H LDA DATA_BUFFER_START,X ;;取出控制傳輸?shù)拈L度 AND #7FH ;;長度不超過128字節(jié) STA CONTINUOUS_DATA_LENGTH ;;保存控制傳輸長度 LDA DATA_BUFFER_START ;;判斷請求類型 BNE PROCESS_USB_INT_EP0_SETUP_NEXT1 JMP CH376_USB_REQ_STANDARD ;;00H則跳轉(zhuǎn)到標準請求 PROCESS_USB_INT_EP0_SETUP_NEXT1: BIT #01000000B ;;是廠商請求么? BNE CH376_USB_REQ_FACT BIT #00100000B ;;USB類請求? BNE CH376_USB_REQ_CLASS AND #E0H BIT #10000000B ;;標準請求? BEQ CH376_USB_REQ_RET_ERR ;;其他請求不支持 JMP CH376_USB_REQ_STANDARD CH376_USB_REQ_FACT: JMP INT_END ;;暫不處理 CH376_USB_REQ_CLASS: JMP INT_END ;;暫不處理 PROCESS_USB_INT_EP0_SETUP_ERR: LDA CH376_STATUS_FLAG ORA #10000000B STA CH376_STATUS_FLAG PROCESS_USB_INT_EP0_SETUP_END: JMP INT_END ==================================================== 處理USB_INT_EPO_SETUP事務結(jié)束 ====================================================
======================================================= CH376_USB_REQ_STANDARD標準請求處理開始 ====================================================== CH376_USB_REQ_STANDARD: LDX #01H ;;偏移地址為1 LDA DATA_BUFFER_START,X STA USB_SETUP_REQUEST_CODE ;;保存請求 CMP #DEF_USB_GET_STATUS BNE CH376_USB_REQ_STANDARD_NEXT1 JMP CH376_USB_GET_STATUS CH376_USB_REQ_STANDARD_NEXT1: CMP #DEF_USB_CLR_FEATURE BNE CH376_USB_REQ_STANDARD_NEXT2 JMP CH376_USB_CLR_FEATURE CH376_USB_REQ_STANDARD_NEXT2: CMP #DEF_USB_SET_ADDRESS BNE CH376_USB_REQ_STANDARD_NEXT3 JMP CH376_USB_SET_ADDRESS CH376_USB_REQ_STANDARD_NEXT3: CMP #DEF_USB_GET_DESCR BNE CH376_USB_REQ_STANDARD_NEXT4 JMP CH376_USB_GET_DESCR CH376_USB_REQ_STANDARD_NEXT4: CMP #DEF_USB_GET_CONFIG BNE CH376_USB_REQ_STANDARD_NEXT5 JMP CH376_USB_GET_CONFIG CH376_USB_REQ_STANDARD_NEXT5: CMP #DEF_USB_SET_CONFIG BNE CH376_USB_REQ_STANDARD_NEXT6 JMP CH376_USB_SET_CONFIG CH376_USB_REQ_STANDARD_NEXT6: CMP #DEF_USB_GET_INTERF BNE CH376_USB_REQ_RET_ERR JMP CH376_USB_GET_INTERF ======================================================= 結(jié)束 =======================================================
================================================= CH376_USB_GET_DESCR子程序 ================================================= CH376_USB_GET_DESCR: LDX #03H ;;偏移地址為03 LDA DATA_BUFFER_START,X CMP #01H ;;獲取設備描述符 BNE CH376_USB_GET_DESCR_CASE1 STZ DESCR_OFFSET JSR CH376_UP_DESCR_CODE JMP CH376_USB_SETUP_RET CH376_USB_GET_DESCR_CASE1: ;;獲取配置描述符 CMP #02H BNE CH376_USB_GET_DESCR_END LDA #USB_CFG_DESCR_TAB-USB_DEV_DESCR_TAB STA DESCR_OFFSET JSR CH376_UP_DESCR_CODE JMP CH376_USB_SETUP_RET CH376_USB_GET_DESCR_END: JMP CH376_USB_REQ_RET_ERR
=========================================================== CH376_UP_DESCR_CODE: ;;把設備描述符復制到DATA_BUFFER_START開始的存儲空間 LDY DESCR_OFFSET CH376_UP_DESCR_CODE_LOOP: LDA USB_DEV_DESCR_TAB,Y STA DATA_BUFFER_START,Y INY CPY #08H BNE CH376_UP_DESCR_CODE_LOOP JSR CH376_EPO_UPLOAD ;;上傳描述符 RTS
;-------------------------------------------- CH376_EPO_UPLOAD: LDA CONTINUOUS_DATA_LENGTH ;;加載控制傳輸長度 CMP #08H BMI CH376_EPO_UPLOAD_LENGTH ;;比較CONTINUOUS_DATA_LENGTH和08H的大小,比08H小則跳轉(zhuǎn) SEC SBC #08H STA CONTINUOUS_DATA_LENGTH ;;比08大,減去08后重新保存長度 LDA #08H ;;發(fā)送08個數(shù)據(jù) CH376_EPO_UPLOAD_LENGTH: STA UP_DATA_LENGTH ;;比08小,發(fā)送CONTINUOUS_DATA_LENGTH個數(shù)據(jù) JSR SELECT_CH376_ENABLE LDA #CMD_WR_USB_DATA3 JSR SPI_DATA_TRANSMIT ;;發(fā)送寫命令 LDA UP_DATA_LENGTH JSR SPI_DATA_TRANSMIT ;;發(fā)送長度 LDY #00H ;;循環(huán)發(fā)送 CH376_EPO_UPLOAD_LOOP: LDA DATA_BUFFER_START,Y JSR SPI_DATA_TRANSMIT INY CPY UP_DATA_LENGTH BNE CH376_EPO_UPLOAD_LOOP JSR SELECT_CH376_DISABLE RTS