我现在使用CH376做USB_DEVICE模式,希望能被PC枚举为HID类设备,现在程序中追到了USB_INT_EP0_SETUP命令,也正常进入USB_INT_EP0_SETUP处理子程序,并判断出是获取配置命令,即DEF_USB_GET_DESCR,而且正确执行DEF_USB_GET_DESCR程序,从PC上位机接收到 80 06 00 01 00 00 40 00 的数据,然后上传设备描述符: 12 01 10 01 00 00 00 08 但是通过示波器观察,程序会重复收到USB_INT_EP0_SETUP命令,然后重复执行USB_INT_EP0_SETUP子程序。我把这段代码贴出来,麻烦大家帮我看下哪里出了问题:
========================================================= 处理USB_INT_EPO_SETUP事务开始 ======================================================== PROCESS_USB_INT_EP0_SETUP: JSR SELECT_CH376_ENABLE ;;片选使能 LDA #CMD_RD_USB_DATA ;;发送读命令 JSR SPI_DATA_TRANSMIT ;;发送数据 JSR SPI_DATA_RECEIVE ;;接收读出来的数据 LDA SPI_DATA_BUFFER ;;第一个数据是长度 STA DOWN_DATA_LENGTH ;;保存长度 LDY #00H ;;循环接收数据 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 ;;循环接收 JSR SELECT_CH376_DISABLE ;;接收完毕则禁止片选使能 PROCESS_USB_INT_EP0_SETUP_DONE: LDA DOWN_DATA_LENGTH CMP #08H ;;数据长度不为8则不理睬 BNE PROCESS_USB_INT_EP0_SETUP_ERR LDX #06H LDA DATA_BUFFER_START,X ;;取出控制传输的长度 AND #7FH ;;长度不超过128字节 STA CONTINUOUS_DATA_LENGTH ;;保存控制传输长度 LDA DATA_BUFFER_START ;;判断请求类型 BNE PROCESS_USB_INT_EP0_SETUP_NEXT1 JMP CH376_USB_REQ_STANDARD ;;00H则跳转到标准请求 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事务结束 ====================================================
======================================================= 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 ======================================================= 结束 =======================================================
================================================= 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小则跳转 SEC SBC #08H STA CONTINUOUS_DATA_LENGTH ;;比08大,减去08后重新保存长度 LDA #08H ;;发送08个数据 CH376_EPO_UPLOAD_LENGTH: STA UP_DATA_LENGTH ;;比08小,发送CONTINUOUS_DATA_LENGTH个数据 JSR SELECT_CH376_ENABLE LDA #CMD_WR_USB_DATA3 JSR SPI_DATA_TRANSMIT ;;发送写命令 LDA UP_DATA_LENGTH JSR SPI_DATA_TRANSMIT ;;发送长度 LDY #00H ;;循环发送 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