主题 : 关于一个自制板子模拟U盘不能识别问题 复制链接 | 浏览器收藏 | 打印
级别: 新手上路
UID: 13462
精华: 0
发帖: 33
金钱: 165 两
威望: 33 点
贡献值: 0 点
综合积分: 66 分
注册时间: 2010-01-25
最后登录: 2018-02-08
楼主  发表于: 2010-03-04 17:44

 关于一个自制板子模拟U盘不能识别问题

之前发过帖后来发现是usb口接错了,用的非复用口所以肯定不行了
2.6.24内核, 2440板
现在是可以进入中断,然后reset也可以调用,但是之后就没了,似乎ep0中断没有
调试过程如下:
# insmod s3c2410_udc.ko
s3c2410_udc: debugfs dir creation failed -19
s3c2440-usbgadget s3c2440-usbgadget: S3C2440: increasing FIFO to 128 bytes
smdk2410_udc:Pull-up disable
s3c2410_udc_p_disable
# insmod g_file_storage.ko file=/dev/mydev/mmc stall=0 removable=1
usb_gadget_register_driver() 'g_file_storage'
fsg_bind
g_file_storage gadget: File-backed Storage Gadget, version: 7 August 2007
g_file_storage gadget: Number of LUNs=1
g_file_storage gadget-lun0: ro=0, file: /usr/mydev/mmc
s3c2410_udc_enable called
smdk2410_udc:Pull-up enable
s3c2410_udc_p_enable
fsg_main_thread

//把把板子的usb口插入电脑后板子这边的信息,pc上提示无法识别的设备
# S3C2410_UDC_EP_INT_EN_REG=1f
usbs=04, usbds=00, pwr=08 ep0csr=00
USB reset csr 0 pwr 8
S3C2410_UDC_EP_INT_EN_REG=1f
usbs=00, usbds=00, pwr=08 ep0csr=00
irq: 41 s3c2410_udc_done.
S3C2410_UDC_EP_INT_EN_REG=1f
usbs=04, usbds=00, pwr=08 ep0csr=00
USB reset csr 0 pwr 8
S3C2410_UDC_EP_INT_EN_REG=1f
usbs=00, usbds=00, pwr=08 ep0csr=00
irq: 41 s3c2410_udc_done.
S3C2410_UDC_EP_INT_EN_REG=1f
usbs=04, usbds=00, pwr=08 ep0csr=00
USB reset csr 0 pwr 8
S3C2410_UDC_EP_INT_EN_REG=1f
usbs=00, usbds=00, pwr=08 ep0csr=00
irq: 41 s3c2410_udc_done.
S3C2410_UDC_EP_INT_EN_REG=1f
usbs=04, usbds=00, pwr=08 ep0csr=00
USB reset csr 0 pwr 8
S3C2410_UDC_EP_INT_EN_REG=1f
usbs=00, usbds=00, pwr=08 ep0csr=00
irq: 41 s3c2410_udc_done.


看看代码
reset之后不会进入resume和suspend(设置过了)
但是之后的ep部分也不行,这个不行吧,EP_INT_REG中ep0也是0,在觅开始要用ep0的,看数据手册上说的置位条件有IN_PKT_RDY,这个只要ep0 fifo有数据来就有了的吧?
我这个理解有没有错
如果没错为什么会ep0没反应了

* s3c2410_udc_irq - interrupt handler
*/
static irqreturn_t s3c2410_udc_irq(int irq, void *_dev)
{
struct s3c2410_udc *dev = _dev;
int usb_status;
int usbd_status, usbd_status2;
int pwr_reg;
int ep0csr,ep1csr;
int i;
u32 idx;
unsigned long flags;
//add
unsigned int en_int_ep=udc_read(S3C2410_UDC_EP_INT_EN_REG);
printk("S3C2410_UDC_EP_INT_EN_REG=%x\n",en_int_ep);

spin_lock_irqsave(&dev->lock, flags);

/* Driver connected ? */
if (!dev->driver) {
/* Clear interrupts */
udc_write(udc_read(S3C2410_UDC_USB_INT_REG),
S3C2410_UDC_USB_INT_REG);
udc_write(udc_read(S3C2410_UDC_EP_INT_REG),
S3C2410_UDC_EP_INT_REG);
}

/* Save index */
idx = udc_read(S3C2410_UDC_INDEX_REG);

/* Read status registers */
usb_status = udc_read(S3C2410_UDC_USB_INT_REG);
usbd_status = udc_read(S3C2410_UDC_EP_INT_REG);
pwr_reg = udc_read(S3C2410_UDC_PWR_REG);

udc_writeb(base_addr, S3C2410_UDC_INDEX_EP0, S3C2410_UDC_INDEX_REG);
ep0csr = udc_read(S3C2410_UDC_EP0_CSR_REG);
ep1csr = udc_read(S3C2410_UDC_IN_CSR1_REG);
// dprintk(DEBUG_NORMAL, "usbs=%02x, usbds=%02x, pwr=%02x ep0csr=%02x\n",
// usb_status, usbd_status, pwr_reg, ep0csr);
#ifdef C_TEST
printk("usbs=%02x, usbds=%02x, pwr=%02x ep0csr=%02x,ep1csr=%02x\n",
usb_status, usbd_status, pwr_reg, ep0csr,ep1csr);
#endif
/*
* Now, handle interrupts. There's two types :
* - Reset, Resume, Suspend coming -> usb_int_reg
* - EP -> ep_int_reg
*/

/* RESET */
if (usb_status & S3C2410_UDC_USBINT_RESET) {
/* two kind of reset :
* - reset start -> pwr reg = 8
* - reset end -> pwr reg = 0
**/
// dprintk(DEBUG_NORMAL, "USB reset csr %x pwr %x\n",
// ep0csr, pwr_reg);
#ifdef C_TEST
printk("USB reset csr %x pwr %x\n",
ep0csr, pwr_reg);
#endif
dev->gadget.speed = USB_SPEED_UNKNOWN;
udc_write(0x00, S3C2410_UDC_INDEX_REG);
udc_write((dev->ep[0].ep.maxpacket & 0x7ff) >> 3,
S3C2410_UDC_MAXP_REG);
dev->address = 0;

dev->ep0state = EP0_IDLE;
dev->gadget.speed = USB_SPEED_FULL;

/* clear interrupt */
udc_write(S3C2410_UDC_USBINT_RESET,
S3C2410_UDC_USB_INT_REG);

udc_write(idx, S3C2410_UDC_INDEX_REG);
spin_unlock_irqrestore(&dev->lock, flags);
return IRQ_HANDLED;
}

usbd_status2=udc_read(S3C2410_UDC_EP_INT_REG);
printk("usbd_status2=%02x\n", usbd_status2);

/* RESUME */
if (usb_status & S3C2410_UDC_USBINT_RESUME) {
// dprintk(DEBUG_NORMAL, "USB resume\n");
printk("USB resume\n");
/* clear interrupt */
udc_write(S3C2410_UDC_USBINT_RESUME,
S3C2410_UDC_USB_INT_REG);

if (dev->gadget.speed != USB_SPEED_UNKNOWN
&& dev->driver
&& dev->driver->resume)
dev->driver->resume(&dev->gadget);
}

/* SUSPEND */
if (usb_status & S3C2410_UDC_USBINT_SUSPEND) {
// dprintk(DEBUG_NORMAL, "USB suspend\n");
printk("USB suspend\n");
/* clear interrupt */
udc_write(S3C2410_UDC_USBINT_SUSPEND,
S3C2410_UDC_USB_INT_REG);

if (dev->gadget.speed != USB_SPEED_UNKNOWN
&& dev->driver
&& dev->driver->suspend)
dev->driver->suspend(&dev->gadget);

dev->ep0state = EP0_IDLE;
}

/* EP */
/* control traffic */
/* check on ep0csr != 0 is not a good idea as clearing in_pkt_ready
* generate an interrupt
*/
if (usbd_status & S3C2410_UDC_INT_EP0) {
// dprintk(DEBUG_VERBOSE, "USB ep0 irq\n");
#ifdef C_TEST
printk("USB ep0 irq\n");
#endif
/* Clear the interrupt bit by setting it to 1 */
udc_write(S3C2410_UDC_INT_EP0, S3C2410_UDC_EP_INT_REG);
s3c2410_udc_handle_ep0(dev);
}

/* endpoint data transfers */
for (i = 1; i < S3C2410_ENDPOINTS; i++) {
u32 tmp = 1 << i;
if (usbd_status & tmp) {
// dprintk(DEBUG_VERBOSE, "USB ep%d irq\n", i);
printk("USB ep%d irq\n", i);
/* Clear the interrupt bit by setting it to 1 */
udc_write(tmp, S3C2410_UDC_EP_INT_REG);
s3c2410_udc_handle_ep(&dev->ep);
}
}

// dprintk(DEBUG_VERBOSE, "irq: %d s3c2410_udc_done.\n", irq);
printk("irq: %d s3c2410_udc_done.\n", irq);
/* Restore old index */
udc_write(idx, S3C2410_UDC_INDEX_REG);

spin_unlock_irqrestore(&dev->lock, flags);

return IRQ_HANDLED;
}
[ 此帖被kasim在2010-03-22 15:43重新编辑 ]
级别: 新手上路
UID: 13462
精华: 0
发帖: 33
金钱: 165 两
威望: 33 点
贡献值: 0 点
综合积分: 66 分
注册时间: 2010-01-25
最后登录: 2018-02-08
1楼  发表于: 2010-03-08 10:00
有做过的说下撒,我现在ep0的中断中断响应不来,响应寄存器的那一位移植是0, 然后ep0_csr和in_csr1_reg 中的IN_PKT_RDY, OUT_PKT_RDY也都一直是0,现在程序进到usb的中断后先reset,然后跳过resume,suspend,但是没法进到 handle_ep0 中去呀
想问下,看到很多人的usb device中有一个gpio口,这个只是用于切换没影响吧?我板子上没引出这个io口
还有windows下需要安装什么驱动吗??
级别: 新手上路
UID: 6271
精华: 0
发帖: 14
金钱: 70 两
威望: 14 点
贡献值: 0 点
综合积分: 28 分
注册时间: 2009-05-25
最后登录: 2010-06-28
2楼  发表于: 2010-03-15 20:53
友善的技术支持不是一般的差,我也是你这样的问题。但在他的u-boot的usb驱动EP0能中断,在我的就不能刻,而且你看下u-boot最后的usb device使能还有GPIO端口,搞不懂
级别: 新手上路
UID: 13462
精华: 0
发帖: 33
金钱: 165 两
威望: 33 点
贡献值: 0 点
综合积分: 66 分
注册时间: 2010-01-25
最后登录: 2018-02-08
3楼  发表于: 2010-03-22 15:18
我的问题结局掉了

发现是一直有reset信号,所以查找了原因
结果是在做板时给usb供电部分出错多了,有器件分压导致电压不足
现在可以找到U盘了,盘符也出现了,但是后续的读写还有问题
*無鈳取玳
级别: 论坛版主
UID: 27
精华: 12
发帖: 5398
金钱: 40120 两
威望: 17929 点
贡献值: 71 点
综合积分: 11036 分
注册时间: 2008-01-16
最后登录: 2014-11-22
4楼  发表于: 2010-03-22 15:42
引用第3楼coschang于2010-03-22 15:18发表的  :
我的问题结局掉了

发现是一直有reset信号,所以查找了原因
结果是在做板时给usb供电部分出错多了,有器件分压导致电压不足
现在可以找到U盘了,盘符也出现了,但是后续的读写还有问题

不要再浪费你自己的时间在这里问这样的问题了(也许我应该说“这样问问题了”?),没人知道你的板子是怎么做的。
对于像这种同样的软件在开发板上OK,自己板子有问题的问题,最基本的第一步是检查自己板子的原理图(如果不会检查,起码可以把你的原理图贴出来,藏着掖着没人帮得了你)
"If you have an apple and I have an apple and we exchange apples, then you and I will
still each have one apple. But if you have an idea and I have an idea and we exchange
these ideas, then each of us will have two ideas."
级别: 新手上路
UID: 13462
精华: 0
发帖: 33
金钱: 165 两
威望: 33 点
贡献值: 0 点
综合积分: 66 分
注册时间: 2010-01-25
最后登录: 2018-02-08
5楼  发表于: 2010-03-26 09:39
不好意思,之前没调过这种结合性问题,不是故意的,我这个没什么好掖着的
usbd的我不会贴图放附件里
我的新问题是  用sd卡加载u盘上去后不能向sd卡复制文件,打开sd卡中目录也出错,有时不出错也非常慢
25    RSET                                                                                2.1.0        
  26    CDB    25 00 00 00  00 00 00 00  00 00                     READ CAPACITY            3.1.0        
  13.0  CTL    a3 00 00 00  03 00 04 00                            GET STATUS               4.1.0(2)    
  13.0  DI     03 01 00 00                                         ....                     4.2.0        
  13.0  CTL    23 03 04 00  03 00 00 00                            SET FEATURE              6.1.0        
  13.0  CTL    a3 00 00 00  03 00 04 00                            GET STATUS               7.1.0        
  13.0  DI     03 01 10 00                                         ....                     7.2.0        
  13.0  CTL    23 01 14 00  03 00 00 00                            CLEAR FEATURE            8.1.0        
  13.0  CTL    a3 00 00 00  03 00 04 00                            GET STATUS               9.1.0(2)    
  13.0  DI     03 01 00 00                                         ....                     9.2.0        
  13.0  CTL    23 03 04 00  03 00 00 00                            SET FEATURE             11.1.0        
  13.0  CTL    a3 00 00 00  03 00 04 00                            GET STATUS              12.1.0        
  13.0  DI     03 01 10 00                                         ....                    12.2.0        
  13.0  CTL    23 01 14 00  03 00 00 00                            CLEAR FEATURE           13.1.0        
  25    NSTS   00 00 00 00                                         success                  2.2.0        
  25.2  DO     55 53 42 43  48 09 89 84  08 00 00 00  80 00 0a 25  USBCH..........%        14.1.0        
               00 00 00 00  00 00 00 00  00 00 00 00  00 00 00     ...............         14.1.16      
  25.1  DI     00 00 00 00  00 00 00 00                            ........                15.1.0        
  25.1  DI     55 53 42 53  48 09 89 84  08 00 00 00  01           USBSH........           16.1.0        
  25.2  DO     55 53 42 43  48 09 89 84  12 00 00 00  80 00 0c 03  USBCH...........        17.1.0        
               00 00 00 12  00 00 00 00  00 00 00 00  00 00 00     ...............         17.1.16      
  25.1  DI     70 00 06 00  00 00 00 0a  00 00 00 00  29 00 00 00  p...........)...        18.1.0        
               00 00                                               ..                      18.1.16      
  25.1  DI     55 53 42 53  48 09 89 84  00 00 00 00  00           USBSH........           19.1.0        
  26    SNS    70 00 06 00  00 00 00 0a  00 00 00 00  29 00 00 00  power on reset           3.2.0        
               00 00                                                                        3.2.16      
  26    CDB    25 00 00 00  00 00 00 00  00 00                     READ CAPACITY           20.1.0        
  25.2  DO     55 53 42 43  48 09 89 84  08 00 00 00  80 00 0a 25  USBCH..........%        21.1.0        
               00 00 00 00  00 00 00 00  00 00 00 00  00 00 00     ...............         21.1.16      
  25.1  DI     00 00 5f ff  00 00 02 00                            .._.....                22.1.0        
  25.1  DI     55 53 42 53  48 09 89 84  00 00 00 00  00           USBSH........           23.1.0        
  26    DI     00 00 5f ff  00 00 02 00                            .._.....                20.2.0        
  26    CDB    25 00 00 00  00 00 00 00  00 00                     READ CAPACITY           24.1.0        
  25.2  DO     55 53 42 43  48 09 89 84  08 00 00 00  80 00 0a 25  USBCH..........%        25.1.0        
               00 00 00 00  00 00 00 00  00 00 00 00  00 00 00     ...............         25.1.16      
  25.1  DI     00 00 5f ff  00 00 02 00                            .._.....                26.1.0        
  25.1  DI     55 53 42 53  48 09 89 84  00 00 00 00  00           USBSH........           27.1.0        
  26    DI     00 00 5f ff  00 00 02 00                            .._.....                24.2.0        
  26    CDB    28 00 00 00  00 00 00 00  01 00                     READ                    28.1.0        
  25.2  DO     55 53 42 43  48 09 89 84  00 02 00 00  80 00 0a 28  USBCH..........(        29.1.0        
               00 00 00 00  00 00 00 01  00 00 00 00  00 00 00     ...............         29.1.16      
  25.1  DI     eb 3c 90 4d  53 44 4f 53  35 2e 30 00  02 08 06 00  .<.MSDOS5.0.....        30.1.0        
               02 00 02 00  60 f8 09 00  3f 00 ff 00  00 00 00 00  ....`...?.......        30.1.16      
  25.1  DI     55 53 42 53  48 09 89 84  00 00 00 00  00           USBSH........           31.1.0        
  26    DI     eb 3c 90 4d  53 44 4f 53  35 2e 30 00  02 08 06 00  .<.MSDOS5.0.....        28.2.0        
               02 00 02 00  60 f8 09 00  3f 00 ff 00  00 00 00 00  ....`...?.......        28.2.16      
  26    CDB    28 00 00 00  00 00 00 00  01 00                     READ                    32.1.0        
  25.2  DO     55 53 42 43  48 09 89 84  00 02 00 00  80 00 0a 28  USBCH..........(        33.1.0        
               00 00 00 00  00 00 00 01  00 00 00 00  00 00 00     ...............         33.1.16      
  25.1  DI     eb 3c 90 4d  53 44 4f 53  35 2e 30 00  02 08 06 00  .<.MSDOS5.0.....        34.1.0        
               02 00 02 00  60 f8 09 00  3f 00 ff 00  00 00 00 00  ....`...?.......        34.1.16      
  25.1  DI     55 53 42 53  48 09 89 84  00 00 00 00  00           USBSH........           35.1.0        
  26    DI     eb 3c 90 4d  53 44 4f 53  35 2e 30 00  02 08 06 00  .<.MSDOS5.0.....        32.2.0        
               02 00 02 00  60 f8 09 00  3f 00 ff 00  00 00 00 00  ....`...?.......        32.2.16      
  26    CDB    25 00 00 00  00 00 00 00  00 00                     READ CAPACITY           36.1.0        
  25.2  DO     55 53 42 43  48 09 89 84  08 00 00 00  80 00 0a 25  USBCH..........%        37.1.0        
               00 00 00 00  00 00 00 00  00 00 00 00  00 00 00     ...............         37.1.16      
  25.1  DI     00 00 5f ff  00 00 02 00                            .._.....                38.1.0        
  25.1  DI     55 53 42 53  48 09 89 84  00 00 00 00  00           USBSH........           39.1.0        
  26    DI     00 00 5f ff  00 00 02 00                            .._.....                36.2.0        
  26    CDB    25 00 00 00  00 00 00 00  00 00                     READ CAPACITY           40.1.0        
  25.2  DO     55 53 42 43  48 09 89 84  08 00 00 00  80 00 0a 25  USBCH..........%        41.1.0        
               00 00 00 00  00 00 00 00  00 00 00 00  00 00 00     ...............         41.1.16      
  25.1  DI     00 00 5f ff  00 00 02 00                            .._.....                42.1.0        
  25.1  DI     55 53 42 53  48 09 89 84  00 00 00 00  00           USBSH........           43.1.0        
  26    DI     00 00 5f ff  00 00 02 00                            .._.....                40.2.0        
  26    CDB    28 00 00 00  00 00 00 00  01 00                     READ                    44.1.0        
  25.2  DO     55 53 42 43  48 09 89 84  00 02 00 00  80 00 0a 28  USBCH..........(        45.1.0        
               00 00 00 00  00 00 00 01  00 00 00 00  00 00 00     ...............         45.1.16      
  25.1  DI     eb 3c 90 4d  53 44 4f 53  35 2e 30 00  02 08 06 00  .<.MSDOS5.0.....        46.1.0        
               02 00 02 00  60 f8 09 00  3f 00 ff 00  00 00 00 00  ....`...?.......        46.1.16      
  25.1  DI     55 53 42 53  48 09 89 84  00 00 00 00  00           USBSH........           47.1.0        
  26    DI     eb 3c 90 4d  53 44 4f 53  35 2e 30 00  02 08 06 00  .<.MSDOS5.0.....        44.2.0        
               02 00 02 00  60 f8 09 00  3f 00 ff 00  00 00 00 00  ....`...?.......        44.2.16      
  26    CDB    00 00 00 00  00 00                                  TEST UNIT READY         48.1.0        
  26    CDB    2a 08 00 00  45 10 00 00  80 00                     WRITE                   49.1.0        
  25.2  DO     55 53 42 43  70 2a 79 84  00 00 00 00  00 00 06 00  USBCp*y.........        50.1.0        
               00 00 00 00  00 00 00 00  00 00 00 00  00 00 00     ...............         50.1.16      
  25.1  DI     55 53 42 53  70 2a 79 84  00 00 00 00  00           USBSp*y......           51.1.0        
  26    SSTS   01                                                  ok                      48.2.0        
  25.2  DO     55 53 42 43  08 30 68 84  00 00 01 00  00 00 0a 2a  USBC.0h........*        52.1.0        
               08 00 00 45  10 00 00 80  00 00 00 00  00 00 00     ...E...........         52.1.16      
  25.2  DO     c4 62 fa 6e  dd 91 70 a6  96 60 49 00  e8 60 66 31  .b.n..p..`I..`f1        53.1.0        
               de 85 3e 5c  08 8b a0 2b  8f 70 a2 da  a5 14 28 09  ..>\...+.p....(.        53.1.16      
  26    CDB    00 00 00 00  00 00                                  TEST UNIT READY         54.1.0        
  26    SSTS   49                                                  timeout                 49.2.0    
附件: usb.rar (26 K) 下载次数:14
级别: 新手上路
UID: 53658
精华: 0
发帖: 3
金钱: 15 两
威望: 3 点
贡献值: 0 点
综合积分: 6 分
注册时间: 2011-08-12
最后登录: 2012-04-16
6楼  发表于: 2011-08-15 09:39
您好我也出现了
s3c2410_udc_irq is here
usbs=04, usbds=00, pwr=08 ep0csr=00
RESET   S3C2410_UDC_USBINT_REST IN S3C2410_UDC_IRQ
RESET   USB reset ep0csr 0 pwr_reg 8
RESET   clear interrupt

s3c2410_udc_irq is here
usbs=00, usbds=00, pwr=08 ep0csr=00
irq:41 s3c2410_udc_done

s3c2410_udc_irq is here
usbs=04, usbds=00, pwr=08 ep0csr=00
RESET   S3C2410_UDC_USBINT_REST IN S3C2410_UDC_IRQ
RESET   USB reset ep0csr 0 pwr_reg 8
RESET   clear interrupt

s3c2410_udc_irq is here
usbs=00, usbds=00, pwr=08 ep0csr=00
irq:41 s3c2410_udc_done

s3c2410_udc_irq is here
usbs=04, usbds=00, pwr=08 ep0csr=00
RESET   S3C2410_UDC_USBINT_REST IN S3C2410_UDC_IRQ
RESET   USB reset ep0csr 0 pwr_reg 8
RESET   clear interrupt

s3c2410_udc_irq is here
usbs=00, usbds=00, pwr=08 ep0csr=00
irq:41 s3c2410_udc_done

请问您具体是怎么解决的啊?!