简体   繁体   中英

STM32 USB HID reports

For the past two weeks I have been trying to configure my card (STM32F4) to dialogue with USB HID with a PC under Windows 7. I make success with this descriptor:

__ALIGN_BEGIN static uint8_t HID_ReportDesc[HID_MOUSE_REPORT_DESC_SIZE]  __ALIGN_END =
{
    0x06, 0xFF, 0x00,  // USAGE_PAGE (Vendor Page: 0xFF00)
    0x09, 0x01,        // USAGE (Demo Kit)
    0xa1, 0x01,        // COLLECTION (Application)
    //0x85, 0x01,      //     REPORT_ID (1)
    0x09, 0x02,        //     USAGE (DATA)
    0x15, 0x00,        //     LOGICAL_MINIMUM (0)
    0x26, 0xff,0x00,   //     LOGICAL_MAXIMUM (255)
    0x75, 0x08,        //     REPORT_SIZE (8)
    0x95, 0x04,        //     REPORT_COUNT (4)
    0x81, 0x02,        //     INPUT (Data,Var,Abs,Vol)
    0xc0               // END_COLLECTION
};

Like this, Windows recognizeS my card like a compliant HID component.

Now if I want to send 32 bit data like a uint32, Windows recognizes the card, but it sees an error to tell that it can't start it! My descriptor:

__ALIGN_BEGIN static uint8_t HID_MOUSE_ReportDesc[HID_MOUSE_REPORT_DESC_SIZE]  __ALIGN_END =
{
    0x06, 0xFF, 0x00,           // USAGE_PAGE (Vendor Page: 0xFF00)
    0x09, 0x01,                 // USAGE (Demo Kit)
    0xa1, 0x01,                 // COLLECTION (Application)
    0x09, 0x02,                 //     USAGE (DATA)
    0x15, 0x00,                 //     LOGICAL_MINIMUM (0)
    0x27, 0xff,0xff,0xff,0xff,  //     LOGICAL_MAXIMUM (65535)
    0x75, 0x20,                 //     REPORT_SIZE (32)
    0x95, 0x01,                 //     REPORT_COUNT (1)
    0x81, 0x02,                 //     INPUT (Data,Var,Abs,Vol)
    0xc0                        // END_COLLECTION
};

I didn't understand why it din't work!

After that, I use USBlyser to scan my other USB device on my PC, and I take this descriptor about my spacespilot 3D mouse:

Endpoint Descriptor 83 3 In, Interrupt, 16 ms
Offset Field Size Value Description
0 bLength 1 07h
1 bDescriptorType 1 05h Endpoint
2 bEndpointAddress 1 83h 3 In
3 bmAttributes 1 03h Interrupt
 1..0: Transfer Type  ......11  Interrupt
 7..2: Reserved  000000..
4 wMaxPacketSize 2 0007h 7 bytes
6 bInterval 1 08h 16 ms

Interface 1 HID Report Descriptor Multi-Axis Controller
Item Tag (Value) Raw Data
Usage Page (Generic Desktop) 05 01
Usage (Multi-Axis Controller) 09 08
Collection (Application) A1 01
    Collection (Physical) A1 00
        Report ID (1) 85 01
        Logical Minimum (-500) 16 0C FE
        Logical Maximum (500) 26 F4 01
        Physical Minimum (-32768) 36 00 80
        Physical Maximum (32767) 46 FF 7F
        Usage (X) 09 30
        Usage (Y) 09 31
        Usage (Z) 09 32
        Report Size (16) 75 10
        Report Count (3) 95 03
        Input (Data,Var,Abs,NWrp,Lin,Pref,NNul,Bit) 81 02
    End Collection C0

If I try this, it works fine:

__ALIGN_BEGIN static uint8_t HID_MOUSE_ReportDesc[HID_MOUSE_REPORT_DESC_SIZE]  __ALIGN_END =
{
    0x05, 0x01,      // Usage Page (Generic Desktop)
    0x09, 0x08,            //Usage (Multi-Axis Controller)
    0xa1, 0x01,            // COLLECTION (Application)
    0xa1, 0x00,            // Collection (Physical)
    0x85, 0x01,            // Report ID (1)
    0x16,0x0c,0xfe,        // Logical minimum (-500)
    0x26,0xf4,0x01,        // Logical maximum (500)
    0x35,0x00,             // Physical Minimum (0)
    0x46,0xff,0x00,        // Physical Maximum (255)
    0x09,0x30,             // Usage(X)
    0x09,0x31,             // Usage(Y)
    0x09,0x32,             // Usage(Z)
    0x09,0x33,             // Usage(RX)
    0x09,0x34,             // Usage(RY)
    0x09,0x35,             // //Usage(RZ)
    0x75, 0x08,            //     REPORT_SIZE (16)
    0x95, 0x06,            //     REPORT_COUNT (6)
    0x81, 0x02,            //     INPUT (Data,Var,Abs,Vol)
    0xc0,                  // END_COLLECTION
    0xc0                   // END_COLLECTION
};

But if I try the same descriptor that my 3D mouse:

__ALIGN_BEGIN static uint8_t HID_MOUSE_ReportDesc[HID_MOUSE_REPORT_DESC_SIZE]  __ALIGN_END =
{
    0x05, 0x01,      // Usage Page (Generic Desktop)
    0x09, 0x08,            // Usage (Multi-Axis Controller)
    0xa1, 0x01,            // COLLECTION (Application)
    0xa1, 0x00,            // Collection (Physical)
    0x85, 0x01,            // Report ID (1)
    0x16,0x0c,0xfe,        // Logical minimum (-500)
    0x26,0xf4,0x01,        // Logical maximum (500)
    0x35,0x00,0x80,        // Physical Minimum (-32768)
    0x46,0xff,0x7f,        // Physical Maximum (32767)
    0x09,0x30,             // Usage(X)
    0x09,0x31,             // Usage(Y)
    0x09,0x32,             // Usage(Z)
    0x75, 0x10,            //     REPORT_SIZE (16)
    0x95, 0x03,            //     REPORT_COUNT (3)
    0x81, 0x02,            //     INPUT (Data,Var,Abs,Vol)
    0xc0,                  // END_COLLECTION
    0xc0                   // END_COLLECTION
};

Windows gives me the same error, and it can't start the device!!!

What is wrong? Do I need a special driver for Windows to send 32 bit data (int32)? For information, I use the HID library for my application PC side.

How can I resolve this?

The LOGICAL_MAXIMUM four-byte descriptor tag (0x27) is only valid up to 0x7FFFFFFF as it is describing a maximum for a signed int data field. If you want to describe an unsigned int data field you would need to use the LOGICAL_MAXIMUM 8 byte descriptor tag like this:

0x28, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00

Your second example would work, I think. Except for the typo for the Physical maximum descriptor tag. It should be 0x36, not 0x35.

When I tried your last descriptor (using my Arduino USBComposite library for STM32F1), Windows gave me an error about the descriptor having an unknown item. But when I changed the 0x35 in the Physical Minimum line to 0x36, Windows recognized the item.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM