搜索
bottom↓
回复: 20

USB键盘--枚举失败---c8051f340

[复制链接]

出0入0汤圆

发表于 2014-8-5 21:09:28 | 显示全部楼层 |阅读模式
枚举过程中发现不成功:

以下是各个描述符的说明
//-----------------------------------------------------------------------------
// F3xx_USB0_Descriptor.c
//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
// Includes
//-----------------------------------------------------------------------------
#include "F3xx_USB0_Register.h"
#include "F3xx_USB0_InterruptServiceRoutine.h"
#include "F3xx_USB0_Descriptor.h"

//-----------------------------------------------------------------------------
// Descriptor Declarations
//-----------------------------------------------------------------------------

const device_descriptor code DEVICEDESC =
{
   18,                                 // bLength
   0x01,                               // bDescriptorType
   0x1001,                             // bcdUSB
   0x00,                               // bDeviceClass
   0x00,                               // bDeviceSubClass
   0x00,                               // bDeviceProtocol
   EP0_PACKET_SIZE,                    // bMaxPacketSize0
  0x2231,// 0xC410,                             // idVendor
  0x4523,// 0xB981,                             // idProduct
   0x0000,                             // bcdDevice
   0x01,                               // iManufacturer
   0x02,                               // iProduct
   0x00,                               // iSerialNumber
   0x01                                // bNumConfigurations
}; //end of DEVICEDESC

// From "USB Device Class Definition for Human Interface Devices (HID)".
// Section 7.1:
// "When a Get_Descriptor(Configuration) request is issued,
// it returns the Configuration descriptor, all Interface descriptors,
// all Endpoint descriptors, and the HID descriptor for each interface."
const hid_configuration_descriptor code HIDCONFIGDESC =
{

{ // configuration_descriptor hid_configuration_descriptor
   0x09,                               // Length
   0x02,                               // Type
   0x2200,                             // Totallength (= 9+9+9+7)
   0x01,                               // NumInterfaces
   0x01,                               // bConfigurationValue
   0x00,                               // iConfiguration
   0x80,                               // bmAttributes
   0x32                                // MaxPower (in 2mA units)
},

{ // interface_descriptor hid_interface_descriptor
   0x09,                               // bLength
   0x04,                               // bDescriptorType
   0x00,                               // bInterfaceNumber
   0x00,                               // bAlternateSetting
   0x01,                               // bNumEndpoints
   0x03,                               // bInterfaceClass (3 = HID)
   0x01,                               // bInterfaceSubClass
   0x01,                               // bInterfaceProcotol
   0x00                                // iInterface
},

{ // class_descriptor hid_descriptor
   0x09,                               // bLength
   0x21,                               // bDescriptorType
   0x0101,                             // bcdHID
   0x00,                               // bCountryCode
   0x01,                               // bNumDescriptors
   0x22,                               // bDescriptorType
   HID_REPORT_DESCRIPTOR_SIZE_LE       // wItemLength (tot. len. of report
                                       // descriptor)
},

// IN endpoint (mandatory for HID)
{ // endpoint_descriptor hid_endpoint_in_descriptor
   0x07,                               // bLength
   0x05,                               // bDescriptorType
   0x81,                               // bEndpointAddress
   0x03,                               // bmAttributes
   EP1_PACKET_SIZE_LE,                 // MaxPacketSize (LITTLE ENDIAN)
   1000                                  // bInterval
},

// OUT endpoint (optional for HID)
{ // endpoint_descriptor hid_endpoint_out_descriptor
   0x07,                               // bLength
   0x05,                               // bDescriptorType
   0x01,                               // bEndpointAddress
   0x03,                               // bmAttributes
   EP2_PACKET_SIZE_LE,                 // MaxPacketSize (LITTLE ENDIAN)
   1000                                  // bInterval
}

};

const hid_report_descriptor code HIDREPORTDESC =
{
    0x05, 0x01,                    // USAGE_PAGE (Generic Desktop)
    0x09, 0x06,                    // USAGE (Keyboard)
    0xa1, 0x01,                    // COLLECTION (Application)
    0x05, 0x07,                    //   USAGE_PAGE (Keyboard)
    0x19, 0xe0,                    //   USAGE_MINIMUM (Keyboard LeftControl)
    0x29, 0xe7,                    //   USAGE_MAXIMUM (Keyboard Right GUI)
    0x15, 0x00,                    //   LOGICAL_MINIMUM (0)
    0x25, 0x01,                    //   LOGICAL_MAXIMUM (1)
    0x75, 0x01,                    //   REPORT_SIZE (1)
    0x95, 0x08,                    //   REPORT_COUNT (8)
    0x81, 0x02,                    //   INPUT (Data,Var,Abs)
    0x95, 0x01,                    //   REPORT_COUNT (1)
    0x75, 0x08,                    //   REPORT_SIZE (8)
    0x81, 0x03,                    //   INPUT (Cnst,Var,Abs)
    0x95, 0x05,                    //   REPORT_COUNT (5)
    0x75, 0x01,                    //   REPORT_SIZE (1)
    0x05, 0x08,                    //   USAGE_PAGE (LEDs)
    0x19, 0x01,                    //   USAGE_MINIMUM (Num Lock)
    0x29, 0x05,                    //   USAGE_MAXIMUM (Kana)
    0x91, 0x02,                    //   OUTPUT (Data,Var,Abs)
    0x95, 0x01,                    //   REPORT_COUNT (1)
    0x75, 0x03,                    //   REPORT_SIZE (3)
    0x91, 0x03,                    //   OUTPUT (Cnst,Var,Abs)
    0x95, 0x06,                    //   REPORT_COUNT (6)
    0x75, 0x08,                    //   REPORT_SIZE (8)
    0x15, 0x00,                    //   LOGICAL_MINIMUM (0)
    0x25, 0x65,                    //   LOGICAL_MAXIMUM (101)
    0x05, 0x07,                    //   USAGE_PAGE (Keyboard)
    0x19, 0x00,                    //   USAGE_MINIMUM (Reserved (no event indicated))
    0x29, 0x65,                    //   USAGE_MAXIMUM (Keyboard Application)
    0x81, 0x00,                    //   INPUT (Data,Ary,Abs)
    0xc0                           // END_COLLECTION
};

#define STR0LEN 4

code unsigned char String0Desc [STR0LEN] =
{
   STR0LEN, 0x03, 0x09, 0x04
}; //end of String0Desc

#define STR1LEN sizeof ("SILICON LABORATORIES") * 2

code unsigned char String1Desc [STR1LEN] =
{
   STR1LEN, 0x03,
   'S', 0,
   'I', 0,
   'L', 0,
   'I', 0,
   'C', 0,
   'O', 0,
   'N', 0,
   ' ', 0,
   'L', 0,
   'A', 0,
   'B', 0,
   'O', 0,
   'R', 0,
   'A', 0,
   'T', 0,
   'O', 0,
   'R', 0,
   'I', 0,
   'E', 0,
   'S', 0
}; //end of String1Desc

#define STR2LEN sizeof ("C8051F320 Development Board") * 2

code unsigned char String2Desc [STR2LEN] =
{
   STR2LEN, 0x03,
   'C', 0,
   '8', 0,
   '0', 0,
   '5', 0,
   '1', 0,
   'F', 0,
   '3', 0,
   'x', 0,
   'x', 0,
   ' ', 0,
   'D', 0,
   'e', 0,
   'v', 0,
   'e', 0,
   'l', 0,
   'o', 0,
   'p', 0,
   'm', 0,
   'e', 0,
   'n', 0,
   't', 0,
   ' ', 0,
   'B', 0,
   'o', 0,
   'a', 0,
   'r', 0,
   'd', 0
}; //end of String2Desc

unsigned char* const STRINGDESCTABLE [] =
{
   String0Desc,
   String1Desc,
   String2Desc
};       



Bus Hound 5.00 capture. Complements of www.perisoft.net

  Device - Device ID (followed by the endpoint for USB devices)
            (20) Intel(R) ICH9 Family USB Universal Host Controller - 2935
            (21) USB Root Hub
            (30) USB 人体学输入设备
  Phase  - Phase Type
            CTL   USB control transfer      
            DI    Data in                    
            DO    Data out                  
            NSTS  NT status                  
            USTS  USB status                 
  Data   - Hex dump of the data transferred
  Descr  - Description of the phase
  Cmd... - Position in the captured data
//以下是枚举成USB键盘的过程  最后SET CONFIG 失败

Device  Phase  Data                                                                                                    Description       Cmd.Phase.Ofs(rep)
------  -----  ------------------------------------------------------------------------------------------------------  ----------------  ------------------
  21.0  CTL    a3 00 00 00  01 00 04 00                                                                                GET STATUS               1.1.0(2)     
  21.0  DI     01 01 01 00                                                                                                    ....                     1.2.0        
  21.0  CTL    23 01 10 00  01 00 00 00                                                                                CLEAR FEATURE            3.1.0        
  21.0  CTL    a3 00 00 00  01 00 04 00                                                                                GET STATUS               4.1.0(2)     
  21.0  DI     01 01 00 00                                                                                                     ....                     4.2.0        
  21.0  CTL    23 03 04 00  01 00 00 00                                                                                SET FEATURE              6.1.0        
  21.0  CTL    a3 00 00 00  01 00 04 00                                                                                GET STATUS               7.1.0        
  21.0  DI     03 01 10 00                                                                                                    ....                     7.2.0        
  21.0  CTL    23 01 14 00  01 00 00 00                                                                                CLEAR FEATURE            8.1.0        
  21.0  CTL    a3 00 00 00  01 00 04 00                                                                                GET STATUS               9.1.0(2)     
  21.0  DI     03 01 00 00                                                                                                     ....                     9.2.0        
  21.0  CTL    23 03 04 00  01 00 00 00                                                                                SET FEATURE             11.1.0        
  21.0  CTL    a3 00 00 00  01 00 04 00                                                                                GET STATUS              12.1.0        
  21.0  DI     03 01 10 00                                                                                                     ....                    12.2.0        
  21.0  CTL    23 01 14 00  01 00 00 00                                                                                CLEAR FEATURE           13.1.0        
  21.0  CTL    80 06 00 02  00 00 ff 00                                                                                GET DESCRIPTOR          14.1.0        
  21.0  DI     09 02 22 00  01 01 00 80  32 09 04 00  00 01 03 01  01 00 09 21  01 01 00 01  22 44 00 07  05 81 03 40  ..".....2.......        14.2.0        
  21.0  CTL    a3 00 00 00  02 00 04 00                                                                                GET STATUS              15.1.0        
  21.0  DI     00 01 00 00                                                                                             ....                    15.2.0        
  30.0  CTL    80 06 00 01  00 00 12 00                                                                                GET DESCRIPTOR          16.1.0        
  30.0  DI     12 01 10 01  00 00 00 40  22 31 45 23  00 00 01 02  00 01                                               .......@"1E#....        16.2.0        
  30.0  CTL    80 06 00 02  00 00 09 00                                                                                GET DESCRIPTOR          17.1.0        
  30.0  DI     09 02 22 00  01 01 00 80  32                                                                            ..".....2               17.2.0        
  30.0  CTL    80 06 00 02  00 00 22 00                                                                                GET DESCRIPTOR          18.1.0        
  30.0  DI     09 02 22 00  01 01 00 80  32 09 04 00  00 01 03 01  01 00 09 21  01 01 00 01  22 44 00 07  05 81 03 40  ..".....2.......        18.2.0        
  30.0  CTL    00 09 01 00  00 00 00 00                                                                                SET CONFIG              19.1.0        
  30.0  USTS   00 20 00 c0                                                                                                  set config fail         19.2.0        
  21.0  CTL    23 01 01 00  01 00 00 00                                                                                CLEAR FEATURE           20.1.0        
  21.0  CTL    80 00 00 00  00 00 02 00                                                                                GET STATUS              21.1.0(2)     
  21.0  DI     01 00                                                                                                             ..                      21.2.0        
  30.0  CTL    80 06 00 02  00 00 22 00                                                                                GET DESCRIPTOR          23.1.0        
  30.0  DO     00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  ................        23.2.0        
  30.0  NSTS   11 00 00 80                                                                                                 busy                    23.3.0        


请高人帮忙指点一二!非常感谢

阿莫论坛20周年了!感谢大家的支持与爱护!!

一只鸟敢站在脆弱的枝条上歇脚,它依仗的不是枝条不会断,而是自己有翅膀,会飞。

出0入0汤圆

 楼主| 发表于 2014-8-5 21:11:04 | 显示全部楼层
图片显示设备枚举不成功,有问号“?”

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x

出0入0汤圆

 楼主| 发表于 2014-8-5 21:11:41 | 显示全部楼层
不知道问题在哪里?

出0入0汤圆

 楼主| 发表于 2014-8-5 21:13:24 | 显示全部楼层
图片显示设备枚举不成功,用BUS HOUND 截图

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x

出0入0汤圆

 楼主| 发表于 2014-8-5 21:17:47 | 显示全部楼层
USBLYER 2.1 截图

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x

出0入0汤圆

发表于 2014-8-6 10:55:10 | 显示全部楼层
and001 发表于 2014-8-5 21:13
图片显示设备枚举不成功,用BUS HOUND 截图

GetDescriptor(Configuration)只回復了32-byte數據
但是在Configuration的wTotalLength中宣告的是34-byte數據

這一點可以先確認下程序上是否存在問題嗎?

出0入0汤圆

 楼主| 发表于 2014-8-6 13:55:57 | 显示全部楼层
NemoGu 发表于 2014-8-6 10:55
GetDescriptor(Configuration)只回復了32-byte數據
但是在Configuration的wTotalLength中宣告的是34-byte ...

请高人明示! 我真没弄明白。。。

没看到那里回复是32字节? 我的描述符里总共长度是34字节(0x22)? 32字节是哪个地方体现的呢?谢谢帮忙

出0入0汤圆

发表于 2014-8-6 15:06:59 | 显示全部楼层
HT82K629A都不用编程就实现了,或者HT68FB240需要编程。

出0入0汤圆

 楼主| 发表于 2014-8-6 18:18:04 | 显示全部楼层
NemoGu 发表于 2014-8-6 10:55
GetDescriptor(Configuration)只回復了32-byte數據
但是在Configuration的wTotalLength中宣告的是34-byte ...

请高人指点迷津!非常感谢!

出0入0汤圆

发表于 2014-8-6 21:47:39 | 显示全部楼层
and001 发表于 2014-8-6 18:18
请高人指点迷津!非常感谢!

參見圖中紅框標註

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x

出0入0汤圆

 楼主| 发表于 2014-8-7 09:17:52 | 显示全部楼层
NemoGu 发表于 2014-8-6 21:47
參見圖中紅框標註

我看到第一个红框和第二个红框只有一处是不同的: 一个是“0XFF" 一个是"0X22"

之前的”0xff“的理解是因为主机不知道有多长的数据所以按最长来收”0XFF“

自从设备已经告诉主机是34个字节,然后主机才发命令收34字节”0x22“

我没看出来有什么问题,请高人帮忙明示!!

非常感谢!

我的理解BUS BOUND软件估计还有其他的数据包没让我们看到?我们没看到真正的错误包?!

出0入0汤圆

发表于 2014-8-7 12:33:26 | 显示全部楼层
本帖最后由 NemoGu 于 2014-8-7 12:38 编辑
and001 发表于 2014-8-7 09:17
我看到第一个红框和第二个红框只有一处是不同的: 一个是“0XFF" 一个是"0X22"

之前的”0xff“的理解是 ...


可能是BusHound沒有講Configuration Descriptor顯示完整

這裡面的數據是不是完整的枚舉過程呢?

出0入0汤圆

 楼主| 发表于 2014-8-7 13:19:18 | 显示全部楼层
是的!我需要的也是34个字节!!
过程是否显示完整就不知道了?

出0入0汤圆

 楼主| 发表于 2014-8-7 14:38:08 | 显示全部楼层
2fen 发表于 2014-8-6 15:06
HT82K629A都不用编程就实现了,或者HT68FB240需要编程。

很性感的头像呀!!

出0入0汤圆

 楼主| 发表于 2014-8-8 16:20:04 | 显示全部楼层
NemoGu 发表于 2014-8-7 12:33
可能是BusHound沒有講Configuration Descriptor顯示完整

這裡面的數據是不是完整的枚舉過程呢? ...

谢谢高人帮忙指点,问题已经找到:因为是 void Set_Configuration() 函数中有一个语句写错导致HOST一直等待--- 而出错!

非常感谢大家的支持...

大家一起共同进步!!!   

结贴   

出0入0汤圆

 楼主| 发表于 2014-8-8 16:22:58 | 显示全部楼层
我是打算用C8051F340想模拟一个USB键盘!如果大家有兴趣我弄完后发出来给大家参考!?
都是从别人的 代码改写过来的---学习之用!

出0入0汤圆

发表于 2014-8-9 11:34:34 | 显示全部楼层
bushound显示不全,是因为设置原因,可以设置最大长度。

你这问题已经说了,是程序问题,肯定是setconfig响应不对。

出0入0汤圆

 楼主| 发表于 2014-8-13 09:14:51 | 显示全部楼层
本帖最后由 and001 于 2014-8-13 09:16 编辑
sme 发表于 2014-8-9 11:34
bushound显示不全,是因为设置原因,可以设置最大长度。

你这问题已经说了!是程序问题,肯定是setconfig ...


楼上说得对!
但现在虽然枚举成功了,其实当前又碰到新问题,就是不知道什么条件可以让端点0产生中断,我发现我的程序SendPacket () 调用后不能让程序进入USB端点1产生输入中断?

//-----------------------------------------------------------------------------
// Usb_ISR
//-----------------------------------------------------------------------------
//
// Called after any USB type interrupt, this handler determines which type
// of interrupt occurred, and calls the specific routine to handle it.
//
//-----------------------------------------------------------------------------
void Usb_ISR (void) interrupt 8        // Top-level USB ISR
{

   unsigned char bCommon, bIn, bOut;
   POLL_READ_BYTE (CMINT, bCommon);    // Read all interrupt registers
   POLL_READ_BYTE (IN1INT, bIn);       // this read also clears the register
   POLL_READ_BYTE (OUT1INT, bOut);

      if (bCommon & rbRSUINT)          // Handle Resume interrupt
      {
         Usb_Resume ();
      }
      if (bCommon & rbRSTINT)          // Handle Reset interrupt
      {
         Usb_Reset ();
      }
      if (bIn & rbEP0)                 // Handle SETUP packet received
      {                                // or packet transmitted if Endpoint 0
         Handle_Control();             // is in transmit mode
      }
      if (bIn & rbIN1)                 // Handle In Packet sent, put new data
      {                                // on endpoint 1 fifo
         Handle_In1 ();    //进不了此中断函数???
      }
      if (bOut & rbOUT2)               // Handle Out packet received, take
      {                                // data off endpoint 2 fifo
         Handle_Out2 ();
      }
      if (bCommon & rbSUSINT)          // Handle Suspend interrupt
      {
         Usb_Suspend ();
      }
}

我在主函数中强行运行了  SendPacket ()

//-----------------------------------------------------------------------------
// SendPacket
//-----------------------------------------------------------------------------
//
// Return Value - None
// Parameters - Report ID that's used to call the appropriate IN handler
//
// This function can be called by other routines to force an IN packet
// transmit.  It takes as an input the Report ID of the packet to be
// transmitted.
//-----------------------------------------------------------------------------

void SendPacket (unsigned char ReportID)
{
   bit EAState;
   unsigned char ControlReg;

   EA = 0;
   SendPacketBusy = 1;

   // Read contol register for EP 2
   POLL_READ_BYTE (EINCSR1, ControlReg);

   if (EP_STATUS[2] == EP_HALT)        // If endpoint is currently halted,
                                       // send a stall
   {
      POLL_WRITE_BYTE (EINCSR1, rbInSDSTL);
   }

   else if(EP_STATUS[2] == EP_IDLE)
   {
      // the state will be updated inside the ISR handler
      EP_STATUS[2] = EP_TX;

      if (ControlReg & rbInSTSTL)      // Clear sent stall if last
                                       // packet returned a stall
      {
         POLL_WRITE_BYTE (EINCSR1, rbInCLRDT);
      }

      if (ControlReg & rbInUNDRUN)     // Clear underrun bit if it was set
      {
         POLL_WRITE_BYTE (EINCSR1, 0x00);
      }
      EA = 1;

      ReportHandler_IN_Foreground (ReportID);

      // Put new data on Fifo
      // Disable USB interrupts
      EIE1 &= ~0x02;                       // Disable USB0 Interrupts

      Fifo_Write_Foreground (FIFO_EP2, IN_BUFFER.Length,
                    (unsigned char *)IN_BUFFER.Ptr);
      POLL_WRITE_BYTE (EINCSR1, rbInINPRDY);
                                       // Set In Packet ready bit,
                                       // indicating fresh data on FIFO 2
      EIE1 |= 0x02;                       // Enable USB0 Interrupts
   }                                   

   EA = 1;
}

完了后还是没看到 进入USB端点1的输入中断???
晕。。。

出0入0汤圆

发表于 2014-9-27 22:41:16 | 显示全部楼层
是不是驱动有问题?

出0入0汤圆

 楼主| 发表于 2014-9-28 14:51:41 | 显示全部楼层
wuwei520 发表于 2014-9-27 22:41
是不是驱动有问题?

没问题了!已经好了

出0入0汤圆

发表于 2014-10-21 16:38:24 | 显示全部楼层
求分享USB虚拟键盘程序!
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-5-18 18:32

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

快速回复 返回顶部 返回列表