USB键盘--枚举失败---c8051f340
{:smile:} 枚举过程中发现不成功:以下是各个描述符的说明
//-----------------------------------------------------------------------------
// 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, 0x03, 0x09, 0x04
}; //end of String0Desc
#define STR1LEN sizeof ("SILICON LABORATORIES") * 2
code unsigned char String1Desc =
{
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, 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
NSTSNT status
USTSUSB status
Data - Hex dump of the data transferred
Descr- Description of the phase
Cmd... - Position in the captured data
//以下是枚举成USB键盘的过程最后SET CONFIG 失败
DevicePhaseData Description Cmd.Phase.Ofs(rep)
---------------------------------------------------------------------------------------------------------------------------------------------------
21.0CTL a3 00 00 0001 00 04 00 GET STATUS 1.1.0(2)
21.0DI 01 01 01 00 .... 1.2.0
21.0CTL 23 01 10 0001 00 00 00 CLEAR FEATURE 3.1.0
21.0CTL a3 00 00 0001 00 04 00 GET STATUS 4.1.0(2)
21.0DI 01 01 00 00 .... 4.2.0
21.0CTL 23 03 04 0001 00 00 00 SET FEATURE 6.1.0
21.0CTL a3 00 00 0001 00 04 00 GET STATUS 7.1.0
21.0DI 03 01 10 00 .... 7.2.0
21.0CTL 23 01 14 0001 00 00 00 CLEAR FEATURE 8.1.0
21.0CTL a3 00 00 0001 00 04 00 GET STATUS 9.1.0(2)
21.0DI 03 01 00 00 .... 9.2.0
21.0CTL 23 03 04 0001 00 00 00 SET FEATURE 11.1.0
21.0CTL a3 00 00 0001 00 04 00 GET STATUS 12.1.0
21.0DI 03 01 10 00 .... 12.2.0
21.0CTL 23 01 14 0001 00 00 00 CLEAR FEATURE 13.1.0
21.0CTL 80 06 00 0200 00 ff 00 GET DESCRIPTOR 14.1.0
21.0DI 09 02 22 0001 01 00 8032 09 04 0000 01 03 0101 00 09 2101 01 00 0122 44 00 0705 81 03 40..".....2....... 14.2.0
21.0CTL a3 00 00 0002 00 04 00 GET STATUS 15.1.0
21.0DI 00 01 00 00 .... 15.2.0
30.0CTL 80 06 00 0100 00 12 00 GET DESCRIPTOR 16.1.0
30.0DI 12 01 10 0100 00 00 4022 31 45 2300 00 01 0200 01 .......@"1E#.... 16.2.0
30.0CTL 80 06 00 0200 00 09 00 GET DESCRIPTOR 17.1.0
30.0DI 09 02 22 0001 01 00 8032 ..".....2 17.2.0
30.0CTL 80 06 00 0200 00 22 00 GET DESCRIPTOR 18.1.0
30.0DI 09 02 22 0001 01 00 8032 09 04 0000 01 03 0101 00 09 2101 01 00 0122 44 00 0705 81 03 40..".....2....... 18.2.0
30.0CTL 00 09 01 0000 00 00 00 SET CONFIG 19.1.0
30.0USTS 00 20 00 c0 set config fail 19.2.0
21.0CTL 23 01 01 0001 00 00 00 CLEAR FEATURE 20.1.0
21.0CTL 80 00 00 0000 00 02 00 GET STATUS 21.1.0(2)
21.0DI 01 00 .. 21.2.0
30.0CTL 80 06 00 0200 00 22 00 GET DESCRIPTOR 23.1.0
30.0DO 00 00 00 0000 00 00 0000 00 00 0000 00 00 0000 00 00 0000 00 00 0000 00 00 0000 00 00 00................ 23.2.0
30.0NSTS 11 00 00 80 busy 23.3.0
请高人帮忙指点一二!非常感谢
图片显示设备枚举不成功,有问号“?” 不知道问题在哪里? 图片显示设备枚举不成功,用BUS HOUND 截图 USBLYER 2.1 截图 and001 发表于 2014-8-5 21:13
图片显示设备枚举不成功,用BUS HOUND 截图
GetDescriptor(Configuration)只回復了32-byte數據
但是在Configuration的wTotalLength中宣告的是34-byte數據
這一點可以先確認下程序上是否存在問題嗎? NemoGu 发表于 2014-8-6 10:55
GetDescriptor(Configuration)只回復了32-byte數據
但是在Configuration的wTotalLength中宣告的是34-byte ...
请高人明示! 我真没弄明白。。。
没看到那里回复是32字节? 我的描述符里总共长度是34字节(0x22)? 32字节是哪个地方体现的呢?谢谢帮忙 HT82K629A都不用编程就实现了,或者HT68FB240需要编程。 NemoGu 发表于 2014-8-6 10:55
GetDescriptor(Configuration)只回復了32-byte數據
但是在Configuration的wTotalLength中宣告的是34-byte ...
请高人指点迷津!非常感谢! and001 发表于 2014-8-6 18:18
请高人指点迷津!非常感谢!
參見圖中紅框標註 NemoGu 发表于 2014-8-6 21:47
參見圖中紅框標註
我看到第一个红框和第二个红框只有一处是不同的: 一个是“0XFF" 一个是"0X22"
之前的”0xff“的理解是因为主机不知道有多长的数据所以按最长来收”0XFF“
自从设备已经告诉主机是34个字节,然后主机才发命令收34字节”0x22“
我没看出来有什么问题,请高人帮忙明示!!
非常感谢!
我的理解BUS BOUND软件估计还有其他的数据包没让我们看到?我们没看到真正的错误包?! 本帖最后由 NemoGu 于 2014-8-7 12:38 编辑
and001 发表于 2014-8-7 09:17
我看到第一个红框和第二个红框只有一处是不同的: 一个是“0XFF" 一个是"0X22"
之前的”0xff“的理解是 ...
可能是BusHound沒有講Configuration Descriptor顯示完整
這裡面的數據是不是完整的枚舉過程呢? 是的!我需要的也是34个字节!!
过程是否显示完整就不知道了? 2fen 发表于 2014-8-6 15:06
HT82K629A都不用编程就实现了,或者HT68FB240需要编程。
很性感的头像呀!! NemoGu 发表于 2014-8-7 12:33
可能是BusHound沒有講Configuration Descriptor顯示完整
這裡面的數據是不是完整的枚舉過程呢? ...
谢谢高人帮忙指点,问题已经找到:因为是 void Set_Configuration() 函数中有一个语句写错导致HOST一直等待--- 而出错!
非常感谢大家的支持...
大家一起共同进步!!!
结贴 我是打算用C8051F340想模拟一个USB键盘!如果大家有兴趣我弄完后发出来给大家参考!?
都是从别人的 代码改写过来的---学习之用! bushound显示不全,是因为设置原因,可以设置最大长度。
你这问题已经说了,是程序问题,肯定是setconfig响应不对。 本帖最后由 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 == EP_HALT) // If endpoint is currently halted,
// send a stall
{
POLL_WRITE_BYTE (EINCSR1, rbInSDSTL);
}
else if(EP_STATUS == EP_IDLE)
{
// the state will be updated inside the ISR handler
EP_STATUS = 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的输入中断???
晕。。。 是不是驱动有问题? wuwei520 发表于 2014-9-27 22:41
是不是驱动有问题?
没问题了!已经好了 求分享USB虚拟键盘程序!{:handshake:}{:handshake:}{:handshake:}
页:
[1]