【usb 总线枚举失败! 《usb function driver》问题如何排查!】

sypanyue   2009-12-25 21:53 楼主
【平台:】 2440+wince5.0
【目的】:实现CE 设备在USB与PC连线的情况下显示为 移动设备(U盘)的功能! 因为我的BSP中的usb function的driver只有serial的功能 无法通过简单的注册表更改实现切换!所以不得不自己移植sb function driver!(我是从samsug 官方bsp下的usbfn 移植到当前BSP下,)因为他的release note 有说明:
  The USB Mass Storage Function driver was implemented.
The USB driver was updated to support the USB Mass Storage Function. And, the usbmsfn.dll was added in the files folder. So, it can support both the Serial and the Mass Storage Function Class.
【现象:】
用 usb view 软件查看CE DEVICE 得到如下信息:


  1. /*
  2. Device Descriptor:
  3. bcdUSB:             0x0000
  4. bDeviceClass:         0x00
  5. bDeviceSubClass:      0x00
  6. bDeviceProtocol:      0x00
  7. bMaxPacketSize0:      0x00 (0)
  8. idVendor:           0x0000
  9. idProduct:          0x0000
  10. bcdDevice:          0x0000
  11. iManufacturer:        0x00
  12. iProduct:             0x00
  13. iSerialNumber:        0x00
  14. bNumConfigurations:   0x00

  15. ConnectionStatus: [color=#FF0000]DeviceFailedEnumeration[/color]
  16. Current Config Value: 0x00
  17. Device Bus Speed:     Low
  18. Device Address:       0x00
  19. Open Pipes:              0
  20. */



DeviceFailedEnumeration 说明是枚举失败了!

-------------------------------------
下面是在function 的功能为mass storage的时候的打印信息:

UsbFnMdd!DllEntry: Attach
-->UfnPdd_DllEntry()
->UfnPdd_Init()
SC2440UsbFn!UfnPdd_Init: ++
pdd->unVersion=0x50000
RegOpenKeyEx success 0, 1, Mass_Storage_Class, 38
RegQueryValueEx success
USB MSF Function Class Enabled : Mass_Storage_Class
no sysintr index specified
SC2440UsbFn!UfnPdd_Init: Using irq 0x19
SC2440UsbFn!UfnPdd_Init: Using IO Base 0xb1200000
SC2440UsbFn!UfnPdd_Init: Using SysIntr 0x28
SC2440UsbFn!UfnPdd_Init: Using IST priority 0d100
MapRegisterSett
SC2440UsbFn!MapRegisterSet: ++
SC2440UsbFn!MapRegisterSet: VirtualCopy Succeeded, pVMem:400000
SC2440UsbFn!MapRegisterSet: --
SC2440UsbFn!ResetDevice: ++
SC2440UsbFn!ResetEndpoint: ++
SC2440UsbFn!ResetEndpoint: --
SC2440UsbFn!ResetEndpoint: ++
SC2440UsbFn!DisableEndpointInterrupt: ++
SC2440UsbFn!DisableEndpointInterrupt: --
SC2440UsbFn!ResetEndpoint: --
SC2440UsbFn!ResetEndpoint: ++
SC2440UsbFn!DisableEndpointInterrupt: ++
SC2440UsbFn!DisableEndpointInterrupt: --
SC2440UsbFn!ResetEndpoint: --
SC2440UsbFn!ResetEndpoint: ++
SC2440UsbFn!DisableEndpointInterrupt: ++
SC2440UsbFn!DisableEndpointInterrupt: --
SC2440UsbFn!ResetEndpoint: --
SC2440UsbFn!ResetEndpoint: ++
SC2440UsbFn!DisableEndpointInterrupt: ++
SC2440UsbFn!DisableEndpointInterrupt: --
SC2440UsbFn!ResetEndpoint: --
SC2440UsbFn!ResetDevice: --
SC2440UsbFn!UfnPdd_Init: --
judge->UFN_PDD_INTERFACE_VERSION=0x50000
UsbFnMdd!UFN_Init: PDD has 5 endpoints
UsbFnMdd!UFN_Init: PDD supports speeds 0x1
SC2440UsbFn!UfnPdd_IOControl: ++
SC2440UsbFn!UfnPdd_IOControl: --
UsbFnMdd!CUfnBus::GetDefaultClientName: Using default client key named "DefaultClientDriver"
UsbFnMdd!CUfnBus::CreateChild: Using client driver key "\Drivers\USB\FunctionDrivers\Mass_Storage_Class"
UsbMsFn!DllEntry: Attached
bot.cpp-->Init()
-->BOT_InternalInit
UsbMsFn!BOT_InternalInit: ++
UsbMsFn!BOT_Configure: ++
UsbMsFn!BOT_ReadConfigurationValue: ++
UsbMsFn!BOT_ReadConfigurationValue: --
UsbMsFn!BOT_Configure: --
SC2440UsbFn!UfnPdd_IsConfigurationSupportable: ++
SC2440UsbFn!UfnPdd_IsConfigurationSupportable: --
SC2440UsbFn!UfnPdd_IsEndpointSupportable: ++
SC2440UsbFn!UfnPdd_IsEndpointSupportable: --
SC2440UsbFn!UfnPdd_IsEndpointSupportable: ++
SC2440UsbFn!UfnPdd_IsEndpointSupportable: --
UsbFnMdd!IsInterfaceSupportable: Endpoint index 0 can be supported by physical endpoint 1
SC2440UsbFn!UfnPdd_IsEndpointSupportable: ++
SC2440UsbFn!UfnPdd_IsEndpointSupportable: --
UsbFnMdd!IsInterfaceSupportable: Endpoint index 1 can be supported by physical endpoint 2
UsbFnMdd!UfnMdd_RegisterDevice: Device registered
---->now Read transfer thread priority from registry
UsbMsFn!BOT_ReadConfigurationValue: ++
UsbMsFn!BOT_ReadConfigurationValue: --
UsbMsFn!BOT_InternalInit: BOT transfer thread priority = 100
---->now call CeSetThreadPriority()
UsbMsFn!BOT_TransferThread: ++
---->now call BOT_DeviceNotify()   
//这里并没有实际进入BOT_DeviceNotify()函数! 次函数在BOT_InternalInit()中被调用
SC2440UsbFn!UfnPdd_InitEndpoint: ++
SC2440UsbFn!UfnPdd_IsEndpointSupportable: ++
SC2440UsbFn!UfnPdd_IsEndpointSupportable: --
SC2440UsbFn!UfnPdd_InitEndpoint: --
SC2440UsbFn!UfnPdd_IOControl: ++
usb->SetPowerState(.
usb->HW_USBClocks.
HW_USBClocks::D0
SC2440UsbFn!UfnPdd_IOControl: --
->UfnPdd_Start
SC2440UsbFn!UfnPdd_Start: ++
SC2440UsbFn!UfnPdd_Start: ++
-dwSysIntr=28
USBD enable interrutp
::: SYSINTR_USBD    OEMInterruptDone
SC2440UsbFn!UfnPdd_Start: --
<-UfnPdd_Start
UsbFnMdd!UfnMdd_Start: Function controller running
UsbMsFn!BOT_InternalInit: --
<--BOT_InternalInit
<-BOT_InternalInit,,,dwRet==true
usb->enter interrupt sevice routine.
UsbFnMdd!CUfnBus::ActivateChild: Activated client driver "Mass_Storage_Class"
SC2440UsbFn!ISTMain: ++
SC2440UsbFn!EnableEndpointInterrupt: ++
SC2440UsbFn!EnableEndpointInterrupt: --


---
USBD的中断可以相应! 但目前没有任何反应在PC端!

现在不知道该怎么排查和解决了?  请坛友帮忙!非常感谢! 只有65分了

回复评论 (38)

//注册表设置如下:

[HKEY_LOCAL_MACHINE\Drivers\BuiltIn\SC2440USBFN]
   "Dll"="sc2440usbfn.dll"
   "Prefix"="UFN"
   "Priority256"=dword:64
   "IoBase"=dword:B1200000
   "IoLen"=dword:1000     ; Use one page
   "Irq"=dword:19   //Irq 是USBD的中断号 是25与Datasheet对应
   "Order"=dword:2
   "BusIoctl"=dword:2a0048
   "IClass"=multi_sz:"{E2BDC372-598F-4619-BC50-54B3F7848D35}=%b","{6F40791D-300E-44E4-BC38-E0E63CA8375C}=%b"       
               
[HKEY_LOCAL_MACHINE\Drivers\USB\FunctionDrivers]
           "DefaultClientDriver"=- ; erase previous default
           "DefaultClientDriver"="Mass_Storage_Class"

[HKEY_LOCAL_MACHINE\Drivers\USB\FunctionDrivers\Mass_Storage_Class]
           "Dll"="usbmsfn.dll"
           ;USB Host端通过该值来枚举设备,06h表示Mass Storage。
           "InterfaceSubClass"=dword:06          
           ;USB设备所支持的传输协议,50h表示bulk-only。
           "InterfaceProtocol"=dword:50   
           "DeviceName"="DSK1:" ; for SD/MMC : 3, for SMC : 1
           "FriendlyName"="Mass Storage"
             "idVendor"=dword:045E
             "Manufacturer"="Generic Manufacturer (PROTOTYPE--Remember to change idVendor)"
             "idProduct"=dword:FFFF
           "Product"="Generic Mass Storage (PROTOTYPE--Remember to change idVendor)"
             "bcdDevice"=dword:0
             "Removable"=dword:0  ; all partition: 0, only one partition : 1

Sysintr 在驱动中直接静态指定的! 是
#define SYSINTR_USBD                (SYSINTR_FIRMWARE+12)
Q:多问下:SYSINTR_FIRMWARE的值具体是多少 是否指定!
点赞  2009-12-25 21:59
"DeviceName"="DSK1:"
这个DSK1存在吗?
点赞  2009-12-25 23:14
[HKEY_LOCAL_MACHINE\Drivers\BuiltIn\FlashDrv]
        "Prefix"="DSK"
        "Dll"="FLASHDRV.dll"
        "FSD"="FATFS.DLL"       
        "Order"=dword:0
        "Index"=dword:1
        "Ioctl"=dword:4
        "Profile"="FlashDrv"
        "FriendlyName"="MS Flash Driver"
        "IClass"=multi_sz:"{A4E7EDDA-E575-4252-9D6B-4195D48BB865}"
  "MountFlags"=dword:11
        "BootPhase"=dword:1
        "Flags"=dword:1000  ;***

OS起来之在 Driver\BuiltIn\FlashDrv\
点赞  2009-12-26 08:40
看了下! USB的插拔事件是由线程ISTMain(监控的!


  1. // interrupt service routine.
  2. static
  3. DWORD
  4. WINAPI
  5. ISTMain(
  6.         LPVOID lpParameter
  7.         )
  8. {

  9. RETAILMSG(1, (TEXT("usb->enter interrupt sevice routine.\r\n")));
  10.     SETFNAME();
  11.     FUNCTION_ENTER_MSG();

  12.     PCTRLR_PDD_CONTEXT pContext = (PCTRLR_PDD_CONTEXT) lpParameter;
  13.     ValidateContext(pContext);

  14.     CeSetThreadPriority(pContext->hIST, pContext->dwISTPriority);

  15.     while (!pContext->fExitIST) {
  16.         pContext->fRestartIST = FALSE;

  17.         // Enable Suspend Mode in the Power Register
  18. //        SetClearReg(pContext, PWR_REG_OFFSET, SUSPEND_MODE_ENABLE_CTRL, SET);

  19.         // Disable All Endpoint interrupts
  20.         WriteReg(pContext, EP_INT_EN_REG_OFFSET, 0); // Disable All

  21.         // Enable Device interrupts
  22.         WriteReg(pContext, USB_INT_EN_REG_OFFSET, (USB_RESET_INTR));// | USB_SUSPEND_INTR));

  23.         // Enable Endpoint interrupt 0
  24.         EnableEndpointInterrupt(pContext, 0);

  25.         while (TRUE) {
  26.             DWORD dwWait = WaitForSingleObject(pContext->hevInterrupt, INFINITE);
  27.             if (pContext->fExitIST || pContext->fRestartIST) {
  28.                 break;
  29.             }

  30.             if (dwWait == WAIT_OBJECT_0) {
  31.                 HandleUSBEvent(pContext);
  32.                 InterruptDone(pContext->dwSysIntr);
  33.             }
  34.             else {
  35.                 RETAILMSG(ZONE_INIT, (_T("%s WaitForMultipleObjects failed. Exiting IST.\r\n"),
  36.                     pszFname));
  37.                 break;
  38.             }
  39.         }
  40.          RETAILMSG(ZONE_INIT, (_T("%s now  Send detach, moved code for reset interrupt +chandolp+ .\r\n"),  pszFname));
  41.         // Send detach, moved code for reset interrupt +chandolp+
  42.         pContext->pfnNotify(pContext->pvMddContext,
  43.                           UFN_MSG_BUS_EVENTS, UFN_DETACH);

  44.         pContext->fSpeedReported = FALSE;
  45.         pContext->attachedState = UFN_DETACH;
  46.         pContext->isattachedusbcable = FALSE;
  47.                
  48.         // Disable Device  interrupts - write Zeros to Disable
  49.         WriteReg(pContext, USB_INT_EN_REG_OFFSET, 0 );

  50.         // Disable endpoint interrupts - write Zeros to Disable
  51.         WriteReg(pContext, EP_INT_EN_REG_OFFSET, 0);
  52.         
  53.         // Clear any outstanding device & endpoint interrupts
  54.         // USB Device Interrupt Status - Write a '1' to Clear
  55.         WriteReg(pContext, USB_INT_REG_OFFSET,
  56.             (USB_RESET_INTR | USB_RESUME_INTR | USB_SUSPEND_INTR));
  57.         // End point Interrupt Status - Write a '1' to Clear
  58.         WriteReg(pContext, EP_INT_REG_OFFSET, CLEAR_ALL_EP_INTRS);

  59.     }

  60.     FUNCTION_LEAVE_MSG();

  61.     return 0;
  62. }



但 pContext->pfnNotify(pContext->pvMddContext,  UFN_MSG_BUS_EVENTS, UFN_DETACH);没有调用
点赞  2009-12-26 11:41
Sysintr 在驱动中直接静态指定的! 是
#define SYSINTR_USBD (SYSINTR_FIRMWARE+12)
Q:多问下:SYSINTR_FIRMWARE的值具体是多少 是否指定!

LZ是用的哪个BSP?

1、Sysintr 不一定是静态给定的,一般是动态的,在map.c文件有其数组的定义的
2、SYSINTR_FIRMWARE在不同的BSP里面,可能也是不一样的。。。如果是用的YL2440A的话,应该是如下:
#define SYSINTR_DEVICES     8
#define SYSINTR_FIRMWARE    (SYSINTR_DEVICES+8)

#define SYSINTR_OHCI            (SYSINTR_FIRMWARE+1)  // 17

点赞  2009-12-26 15:56
OK! i get it

那么 USB枚举失败 是在哪里出现问题了?

点赞  2009-12-28 08:45
恩  好  好
点赞  2009-12-28 10:30


  1. // Process a SC2440 interrupt.
  2. static
  3. VOID
  4. HandleUSBEvent(
  5.                PCTRLR_PDD_CONTEXT pContext
  6.                )
  7. {
  8.     SETFNAME();
  9.     FUNCTION_ENTER_MSG();
  10.     ValidateContext(pContext);

  11.     BYTE bEpIrqStat = ReadReg(pContext, EP_INT_REG_OFFSET);
  12.     BYTE bUSBBusIrqStat = ReadReg(pContext, USB_INT_REG_OFFSET);
  13. //因为这里bEpIrqStat,bUSBBusIrqStat读到的老是0,所以,下面的分支都进不去,
  14.         bUSBBusIrqStat=0x4;

  15.    RETAILMSG(1, (TEXT(" Hnt\r\n")));

  16.   //  while (bEpIrqStat || bUSBBusIrqStat) {
  17.         if (bUSBBusIrqStat) {
  18.             RETAILMSG(1, (_T("%s USB_INT_REG = 0x%02x\r\n"),
  19.                 pszFname, bUSBBusIrqStat));
  20.             HandleUSBBusIrq(pContext, bUSBBusIrqStat);
  21.         }

  22.         if (bEpIrqStat) {
  23.             RETAILMSG(1, (_T("%s EP_INT_REG = 0x%02x\r\n"),
  24.                 pszFname, bEpIrqStat));

  25.             if (bEpIrqStat & EP0_INT_INTR) {
  26.                   RETAILMSG(ZONE_COMMENT, (_T("%s now call HandleEndpoint0Event()\r\n"),pszFname));
  27.                 HandleEndpoint0Event(pContext);
  28.             }
  29.             
  30.             // Process All Other (besides EP0) Endpoints
  31.             for (DWORD dwEndpoint = 1; dwEndpoint < ENDPOINT_COUNT; ++dwEndpoint) {
  32.                 // Check the Interrupt Mask
  33.                 // Check the Interrupt Status
  34.                 RETAILMSG(ZONE_COMMENT, (_T("%s now call EpToIrqStatBit()\r\n"),pszFname));
  35.                 BYTE bEpBit =  EpToIrqStatBit(dwEndpoint);
  36.                 if (bEpIrqStat & bEpBit) {
  37.                     HandleEndpointEvent(pContext, dwEndpoint, bEpIrqStat);
  38.                 }
  39.    
  40.                 }
  41.         }
  42.         bEpIrqStat = ReadReg(pContext, EP_INT_REG_OFFSET);
  43.         bUSBBusIrqStat = ReadReg(pContext, USB_INT_REG_OFFSET);
  44.    // }
  45.    
  46.     FUNCTION_LEAVE_MSG();
  47. }


点赞  2009-12-28 11:36
study
点赞  2009-12-28 12:19
study
点赞  2009-12-28 13:41
关注中。。。。。。。。。。。。。
点赞  2009-12-28 13:41
这么高深啊!实在不懂啊 ,只能来添个人气了 呵呵,混点积分!
点赞  2009-12-28 13:52
mark
点赞  2009-12-28 17:42
做起来有点麻烦!

BYTE bEpIrqStat = ReadReg(pContext, EP_INT_REG_OFFSET);
    BYTE bUSBBusIrqStat = ReadReg(pContext, USB_INT_REG_OFFSET);

这个读值 肯定是有问题的!
    经过处理过的地址是0x350000!  感觉很奇妙!
点赞  2009-12-28 17:46
谢谢分享
点赞  2009-12-28 18:13
Mark!
点赞  2009-12-28 18:48
批发零售一比一 LV、GUCCI、香奈儿等品牌包包,有新款式上市赶快来看看吧!别错过好时机哦!质量保证、价格实惠。QQ:630701041  、 651178055网址:www.lvsss.com
点赞  2009-12-28 19:26
谢谢楼主分享
点赞  2009-12-28 19:49
学习下!
点赞  2009-12-28 22:27
12下一页
电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 京公网安备 11010802033920号
    写回复