cancel
Showing results for 
Search instead for 
Did you mean: 

USB custom HID error: Report Descriptor was not byte aligned

AdrianoMunin
Associate

Hi,

I am doing a Button Box for my sim racing for controlling in game car settings. The project is very simple, is just 8 push buttons that the PC need to recognize as gamepad.

So, for this project I followed the ST Tutorial of How to implement a USB device custom HID class, until there it's all ok, but when I try to change the CUSTOM_HID_ReportDesc_FS (inside usbd_custom_hid_if.c) for the computer recognize the device as a gamepad, I get the error on windows "Report Descriptor was not byte aligned." and the error code 10. I already read a lot of documentations about USB descriptors, and followed a tutorial explaining how to program the report descriptor, and used the HID descriptor tool to generate it, so can someone help me saying where is the error?

/** Usb HID report descriptor. */
__ALIGN_BEGIN static uint8_t CUSTOM_HID_ReportDesc_FS[USBD_CUSTOM_HID_REPORT_DESC_SIZE] __ALIGN_END =
{
  /* USER CODE BEGIN 0 */
		0x05, 0x01, //Usage Page (Generic Desktop)
		0x09, 0x05, //Usage (Game Pad)
		0xA1, 0x01, //Collection (Application)
		0xA1, 0x00, //Collection (Physical)
		0x05, 0x09, //Usage Page (Button)
		0x19, 0x01, //Usage Minimum (1)
		0x29, 0x01, //Usage Maximum (1)
		0x15, 0x00, //Logical Minimum (0)
		0x25, 0x01, //Logical Maximum (1)
		0x75, 0x64, //Report Size (64)
		0x95, 0x01, //Report Count (1)
		0x81, 0x00, //Input (Data, Var, Abs)
		0xC0,		//End Collection*/
 
		/* Here is the Working HID Report Desc.
		 0x06, 0x00, 0xff, 	// Usage Page(Undefined )
		 0x0B, 0x05, 		// USAGE (Undefined)
		 0xa1, 0x01, 		// COLLECTION (Application)
		 0x15, 0x00, 		// LOGICAL_MINIMUM (0)
		 0x26, 0xff, 0x00, 	// LOGICAL_MAXIMUM (255)
		 0x75, 0x08, 		// REPORT_SIZE (8)
		 0x95, 0x40, 		// REPORT_COUNT (64)
		 0x0B, 0x05, 		// USAGE (Undefined)
		 0x81, 0x02, 		// INPUT (Data,Var,Abs)
 
		 0x95, 0x40, 		// REPORT_COUNT (64)
		 0x0B, 0x05, 		// USAGE (Undefined)
		 0x91, 0x02, 		// OUTPUT (Data,Var,Abs)
		 0x95, 0x01, 		// REPORT_COUNT (1)
		 0x0B, 0x05, 		// USAGE (Undefined)
		 0xb1, 0x02, 		// FEATURE (Data,Var,Abs)
		*/
		
  /* USER CODE END 0 */
  0xC0    /*     END_COLLECTION	             */
};

4 REPLIES 4
Pavel A.
Evangelist III

8 push buttons? Report size=1 count=8

In this case I am testing with just one for validate, so after working I will put all the 8 buttons​.

Duf Soar
Associate

Maybe I was too late, and my English is not good, sorry.

It says "Report Descriptor was not byte aligned".

Your report size was 0x64, in bit that was 100. that was wrong, it should end in a multiple of eight. because 1byte = 8bit.

For example, part of the standard keyboard HID report descriptor is

  0x05, 0x08, // USAGE_PAGE (LEDs)
 
  0x19, 0x01, // USAGE_MINIMUM (Num Lock)
 
  0x29, 0x05, // USAGE_MAXIMUM (Kana)
 
  0x75, 0x01, // REPORT_SIZE (1)
 
  0x95, 0x05, // REPORT_COUNT (5)
 
  0x91, 0x02, // OUTPUT (Data,Var,Abs)
 
  0x75, 0x03, // REPORT_SIZE (3)
 
  0x95, 0x01, // REPORT_COUNT (1)
 
  0x91, 0x03, // OUTPUT (Cnst,Var,Abs)

As you can see, it adds the 3-bit const data of the previous 5-bit LED to align the byte.

Your "Input" may be wrong, "0x00" means this is an array, but in my opinion, it should be a variable.

The button can be a Sel type, I think in your case it should be a bit field, and a bit field's REPORT_SIZE should be 1, and the REPORT_COUNT should be equal to the number of selections in the set.

Your Usage, if you only need one Usage (like only one button) then you don't need to use the "Usage Minimum" and "Usage Maximum", just use one "Usage".

I wasn't sure if there was anything else wrong, so I suggest you use the "HID Descriptor Tool" to make the HID Report Descriptor. because at least its comment was right. others will be easier to Figure out what's wrong in your descriptor.

Recommend reading: "HID Usage Tables", "Device Class Definition for Human Interface Devices (HID)".

The tool and the HID Usage Tables can be found on the official USB-IF website.

I may not be able to give you a reply, because I am not a frequent visitor to this website.

Here is the one I just made

  0x05, 0x01,                    // USAGE_PAGE (Generic Desktop)
  0x09, 0x05,                    // USAGE (Game Pad)
  0xa1, 0x00,                    // COLLECTION (Physical)
  0x05, 0x09,                    //   USAGE_PAGE (Button)
  0x19, 0x01,                    //   USAGE_MINIMUM (Button 1)
  0x29, 0x08,                    //   USAGE_MAXIMUM (Button 8)
  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)
  0xc0                           // END_COLLECTION

I have tested, it won't send an error.

this supports up to 8 buttons. every button in this case is a bit, total data is a byte.