阅读:2161回复:27
[求助]关于usbn9603开发中设备枚举问题
我目前再开发usbn9603的固件,由于刚学,所以困难重重。现在遇到的问题是,usb设备在处理主机请求的时候采用的是中断方式,但是主机发送标准设备请求时,usbn9603总是给予alt的状态相应,没有触发rx0,tx0事件。不知为什么,我用的固件是该网站提供的usbn9604固件,部分代码如下,清高手帮忙看看,不胜感激!!
int main_usb(void) { ... ... USBN9603_init(); while(1) { ... ... } return 0; } void USBN9603_init(void) { ////初始化9603/// write_usb(CCONF, CLKDIV_SLOW-1); /* Give a software reset, then set ints to active high push pull */ write_usb(MCNTRL, SRST) ; /* Wait for end of the initiated reset */ while(read_usb(MCNTRL) & SRST); write_usb(MCNTRL, INT_H_P | VGE); /*mask all USB node events*/ DISABLE_NODE_INTS //write MAMSK /* Set up interrupt masks */ ENABLE_NAK_INTS(NAK_OUT0) /* NAK OUT FIFO 0 evnt */ ENABLE_TX_INTS(TX_FIFO0|TX_FIFO1|TX_FIFO2|TX_FIFO3) // ENABLE_RX_INTS(RX_FIFO0|RX_FIFO1) ENABLE_ALT_INTS(ALT_SD3|ALT_RESET) //can indicates the suspend state,reset can make into opstate /* Enable all below interrupts */ ENABLE_NODE_INTS(INTR_E|RX_EV|NAK|TX_EV|ALT) reset_usb(); GOTO_STATE(OPR_ST) ATTACH_NODE for (i = 0; i < 0xffff; i++); } void reset_usb(void) { /* set default address for endpoint 0*/ SET_EP_ADDRESS(EPC0, 0x0) /*set usb default device address (FAR register)*/ SET_USB_DEVICE_ADDRESS(0x0) /*enable USB device address (FAR register)*/ USB_DEVICE_ADDRESS_ENABLE /*enable responce to the default address regardless to the value of the EPC0 and FAR registers*/ /* Reset all endpoints */ /* for (i=1; i<MAX_NUM_OF_ENDPOINTS; i++) { if (uja_dev_endpoints != NULL) usb_dev_disable_ep(uja_dev_endpoints); } */ FLUSHTX0 //ep0 FLUSHTX1 //ep1 FLUSHTX3 //ep5 FLUSHRX0 //ep0 FLUSHRX1 //ep2 /* Global initalizations */ clear_control_buffer(&control_send_buffer); clear_control_buffer(&control_receive_buffer); endpoint_status_init(); direct_send_active = 0; wating_rx_data = 0; /* Enable the receiver */ ENABLE_RX0 } /*中断处理函数*/ void usb_node_handler(void) { byte usbn_event; // Clear the interrupt of gpio for usb dev_irq_control->IRQ_MASK&=(~IRQ_GPIO); while( (usbn_event = (read_usb(MAEV) & read_usb(MAMSK))) ) { if (usbn_event & RX_EV) { USBN9603_rx_event_handler(); } if (usbn_event & ALT) USBN9603_alt_event_handler(); if (usbn_event & TX_EV) USBN9603_tx_event_handler(); if (usbn_event & NAK) { if (read_usb(NAKEV) & 0x10) {//NAK OUT FLUSHTX0; FLUSHRX0; //re enable receving DISABLE_TX(ENDPOINT_0); ENABLE_RX(ENDPOINT_0); } } } } 我觉得在中断处理函数中,不应该用while的大循环了吧? |
|
沙发#
发布于:2004-04-14 20:44
回楼上:那为什么我检测到中断后从MAEV里读出一个0x08出来,以上过程跟frame number有什么关系?
|
|
板凳#
发布于:2004-04-14 17:50
看来是我对USBN9604/9603的工作过程还是没有理解透彻了? “代码里有个0到0xffff的延时需要吗?”,这个延时没有必要,你理解的初始化工作过程是对的,没有问题。 |
|
|
地板#
发布于:2004-04-14 17:18
get config出来了。 是的 另:说实话,你打印的那些东西我看不太懂 :(也就看出个大概步骤来 |
|
地下室#
发布于:2004-04-14 16:19
看来是我对USBN9604/9603的工作过程还是没有理解透彻了?
我的工作是要在FPGA上实现一个与USBN9604的接口,我的想法是这样的:FPGA上电之后,我写的模块就开始向USBN9604的寄存器里写一系列控制信息,也就是源代码里USBN9604_init()这个函数里做的事情,当USBN9604_init()里最后一步ATTACH_NODE做完之后,就可以等待9604发过来的中断了(代码里有个0到0xffff的延时需要吗?datasheet里好像没有要求吧);我用的是查询方式来等待中断,隔段时间检查一下中断,如果有中断就去读MAEV这个寄存器,没有就继续等待...这个初始化工作过程是不是这样的?请各位指点! |
|
5楼#
发布于:2004-04-14 09:56
USBN9603的文档中有介绍,如果你要发送的控制数据正好为8的倍数的话,那么在你发送完数据后,要发送一个zero length packet告知数据已经发送完了,如果不是8的倍数,那么usbn9603会根据寄存器中数据不足8(未填满发送缓冲区)来判断数据已经发送完。
在USBN9603的例子程序中,有一个数据结构来记录是否发送zero length packet,在tx_event_handler中会根据该记录来发送zero length packet,用usbn9603_tx_enable(). 好好看看源代码(最好用source insight软件来看) |
|
6楼#
发布于:2004-04-13 22:02
set addr之后要发一个空包?为什么在9603的例程里面没看到这个步骤?在FAR里写完默认地址0x0和AD_EN之后就是FLUSH和ENABLE_RX0了,哪里有发空包?
|
|
7楼#
发布于:2004-04-09 10:59
get config出来了。
leadphone我想请教你一个问题。在原来9603的固件程序中,函数 usbn9604_rx_event_handler()中,在标准请求处理分支中(switch),有一句endpoint_stat[0]->toggle_bit =0x01; 为什么在这里要把toggle 位重置为1啊。是不是每次进行标准请求设置的时候,都要进行toggle的的重新同步啊。 |
|
8楼#
发布于:2004-04-09 10:42
谢谢leadphone的耐心回答。
我按照你的建议查找了0x12回送包后的程序,没有发现什么问题。 我现在把它打印出来,请你帮我看看。我分解了一下: (1)第一次get description host请求包: /---------------RX_FIFO0,setup request--------------------- the HEX COMMAND :80*06*00*01*00*00*40*00* /---------------------in standard req handler------------------ NUM :6 in std dev get desc in dev desc 设备第一次应答get description包: The control buffer: the HEX COMMAND :12*01*10*01*00*00*00*08* /----------------------In TX event------------------------- The control buffer: the HEX COMMAND :00*04*5D*C3*00*01*01*02* ALT 中断请求: in alt event handler the ALT MASK the HEX COMMAND :50* the ALT VALUE the HEX COMMAND :4A* in alt event handler the ALT MASK the HEX COMMAND :50* the ALT VALUE the HEX COMMAND :42* in alt event handler the ALT MASK the HEX COMMAND :50* the ALT VALUE the HEX COMMAND :4A* (2)set address 请求过程: /---------------RX_FIFO0,setup request--------------------- the HEX COMMAND :00*05*02*00*00*00*00*00* /---------------------in standard req handler------------------ NUM :5 in the dev set address /----------------------In TX event------------------------- (3)第二次get description 过程: /---------------RX_FIFO0,setup request--------------------- the HEX COMMAND :80*06*00*01*00*00*12*00* /---------------------in standard req handler------------------ NUM :6 in std dev get desc in dev desc 第二次应该get description过程: The control buffer: the HEX COMMAND :12*01*10*01*00*00*00*08* /----------------------In TX event------------------------- The control buffer: the HEX COMMAND :00*04*5D*C3*00*01*01*02* /----------------------In TX event------------------------- The control buffer: the HEX COMMAND :00*01* /----------------------In TX event------------------------- 第二次应答的描述符包完毕。 in alt event handler the ALT MASK the HEX COMMAND :50* 我查看了描述符的内容,发送的内容好像没有什么错误,而且。从 TX的事件处理程序来看,这些数据也是发送成功的。 leadphone帮我看看描述符包有什么问题。内容如上示,16进制表示,每字节用*号隔开,共18个字节。我想问一下,usb1.1的bcd数是:0x0110,还是0x0101呢。 |
|
9楼#
发布于:2004-04-08 17:26
SET ADDR应该已经OK,因为你的串口数据已经显示主机发出了80 06 00 01 00 00 12 00的SETUP包,肯定是这后面的请求没有回送正确。才致使HOST又重新枚举
HOST通常是3次枚举,都不成功则放弃。而每次枚举都是从头开始,所以你每次都看到了SET ADDR 不要再怀疑前面的工作了,从长度0X12的回送包开始往后捋,找问题。这一步回送正确了才GET_CONFIG |
|
10楼#
发布于:2004-04-08 15:55
还是不能进行下面的列举过程。在进行了set address后,连续进行3次set address,get description过程,但是就是不出现get configuration过程啊。然后就是系统不停的ALT中断。看来我的程序还有地方没有设对。
如果set address对了的话,应该不会再连续发送set address 和get description请求了吧。 |
|
11楼#
发布于:2004-04-08 14:35
谢谢leadphone!!!
|
|
12楼#
发布于:2004-04-08 14:24
恭喜你,你的SET_ADDR已经过了,往下走吧。
我把一些地方用串口打印了,比前面的信息多一些。 |
|
13楼#
发布于:2004-04-08 14:21
9604提供的FW中SET ADDR部分对寄存器操作了,将AD_EN和HOST分配的地址一起写入FAR寄存器,然后进入TX0发一个空包。空包发完之后SET ADDR才算OK。
如果有枚举过程中有ALT中断,那么就是某一步没有搞对。你不会是在ARM7上连ICE单步走得吧?调USB不能单步执行的。 另外,你还是仔细消化消化9604的FW,然后修改。完全从头来的话会很累。9604的FW全部理解下来也不是非常困难,加点信心。 现在SET ADDRESS还没有搞定,toggle位我检查了,0,1交替,没有错误。很奇怪的是,为什么总是出现很多的ALT中断啊。而且系统在几次发送SET ADDRESS请求后,就会进入不停的ALT中断中。有没有什么方法检验SET ADDRESS是否成功。 |
|
14楼#
发布于:2004-04-08 14:17
我把一些地方用串口打印了,比前面的信息多一些。
如下: 2004年03月10日13时56分34秒 start usb init !!!! end usb init !!!! /---------------RX_FIFO0,setup request--------------------- the HEX COMMAND :80*06*00*01*00*00*40*00* /---------------------in standard req handler------------------ NUM :6 in std dev get desc in dev desc ************the tx toggle is 1 /----------------------In TX event------------------------- ---tx ,event ack success ----tx,event additional data ************the tx toggle is 0 in alt event handler /---------------RX_FIFO0,setup request--------------------- the HEX COMMAND :00*05*02*00*00*00*00*00* /---------------------in standard req handler------------------ NUM :5 in the dev set address ************the tx toggle is 1 /----------------------In TX event------------------------- ---tx ,event ack success ---tx ,event else /---------------RX_FIFO0,setup request--------------------- the HEX COMMAND :80*06*00*01*00*00*12*00* /---------------------in standard req handler------------------ NUM :6 in std dev get desc in dev desc ************the tx toggle is 0 /----------------------In TX event------------------------- ---tx ,event ack success ----tx,event additional data ************the tx toggle is 1 /----------------------In TX event------------------------- ---tx ,event ack success ----tx,event additional data ************the tx toggle is 0 /----------------------In TX event------------------------- ---tx ,event ack success ---tx ,event else in alt event handler in alt default in alt wkup in alt default in alt eop in alt default in alt default in alt reset in alt event handler in alt default in alt wkup in alt default in alt default in alt default in alt default in alt reset in alt event handler in alt default in alt wkup in alt default in alt eop in alt default in alt default in alt reset /---------------RX_FIFO0,setup request--------------------- the HEX COMMAND :80*06*00*01*00*00*40*00* /---------------------in standard req handler------------------ NUM :6 in std dev get desc in dev desc ************the tx toggle is 1 /----------------------In TX event------------------------- ---tx ,event ack success ----tx,event additional data ************the tx toggle is 0 in alt event handler in alt default in alt wkup in alt default in alt eop in alt default in alt default in alt reset in alt event handler in alt default in alt wkup in alt default in alt default in alt default in alt default in alt reset in alt event handler in alt default in alt wkup in alt default in alt eop in alt default in alt default in alt reset /---------------RX_FIFO0,setup request--------------------- the HEX COMMAND :00*05*02*00*00*00*00*00* /---------------------in standard req handler------------------ NUM :5 in the dev set address ************the tx toggle is 1 /----------------------In TX event------------------------- ---tx ,event ack success ---tx ,event else /---------------RX_FIFO0,setup request--------------------- the HEX COMMAND :80*06*00*01*00*00*12*00* /---------------------in standard req handler------------------ NUM :6 in std dev get desc in dev desc ************the tx toggle is 0 /----------------------In TX event------------------------- ---tx ,event ack success ----tx,event additional data ************the tx toggle is 1 /----------------------In TX event------------------------- ---tx ,event ack success ----tx,event additional data ************the tx toggle is 0 /----------------------In TX event------------------------- ---tx ,event ack success ---tx ,event else in alt event handler in alt default in alt wkup in alt default in alt eop in alt default in alt default in alt reset in alt event handler in alt default in alt wkup in alt default in alt default in alt default in alt default in alt reset in alt event handler in alt default in alt wkup in alt default in alt eop in alt default in alt default in alt reset 在上面的语句中,我打印了收到的setup请求包的内容。 分析看,前面的步骤是正确的。 1。首先GET description.注意其包长度字段中的期望值是40。 2。发送完GET description的应答后,host发送set address请求。 检查其包格式也是正确的。地址为2。 3。然后host再次请求get description,这次请求的是具体的设备描述,注意长度字段为0x12,也是我在1中发送过去的值,说明步骤1是正确的,host正确的收到了包。 这里想弄清的是是不是在步骤2进行正确以后才会进行步骤3,并且在步骤3中使用的地址是用默认的地址0,还是步骤2中设置的地址。 还有设置地址时,除了写入FAR寄存器地址值,ENABLE,并且返回一个零长度应答包,外还有什么要注意的吗。 |
|
15楼#
发布于:2004-04-08 14:15
谢谢这位大哥帮忙! 1:是否嵌套和你的CPU有关吧? 2:加上吧 3:USB CABLE就是USB线 |
|
16楼#
发布于:2004-04-08 13:40
用的是ARM7.
|
|
17楼#
发布于:2004-04-08 11:01
这个可能和你用的MCU有关系,你用的是51吗?
|
|
|
18楼#
发布于:2004-04-08 10:35
现在SET ADDRESS还没有搞定,toggle位我检查了,0,1交替,没有错误。很奇怪的是,为什么总是出现很多的ALT中断啊。而且系统在几次发送SET ADDRESS请求后,就会进入不停的ALT中断中。有没有什么方法检验SET ADDRESS是否成功。
tuoxie: 你的代码太少了,我没有太明白,setaddress不对寄存器操作,做是在tx0中,是什么意思。能不能说详细点。 我有USBN9604的源代码,但是我不想直接在上面使用,因为这样即使调过了,好像还有很多地方不清楚。所以我现在希望从头开始做,这样虽然会遇到很多问题,但解决问题的过程也就是理解的过程,希望各位能多多帮助,给予意见。 |
|
19楼#
发布于:2004-04-07 20:48
case SET_ADDRESS:
/*save the new address, but don't actually store*/ /*it into FAR until later (when status handshake*/ /*completes during tx_0). Note that the 9602 */ /*has a DEF bit in EPC0 designed for this purp- */ /*ose, but it only works if the default address */ /*is initially in effect. Therefore it can't */ /*be used for multiple SET_ADDRESS commands in */ /*sequence. This will work regardless of init- */ /*ial address. */ setaddr = (usb_buf[2] | AD_EN); break; 我也在搞usbn9603,setaddress的时候不对寄存器操作的,做是在tx0里 |
|
上一页
下一页