Can't get HID Report Description to work for mouse wheel only - Page 1
Forum section: electronics / general

author: evglabs
author_rank: Contributor
timestamp: October 13, 2020, 12:07:08 am
content: I'm trying to teach myself USB HID with an STM32. Right now I'm stuck trying to get a custom Report Description to work.Here's what's working right now:Report Description:Code:0x05, 0x01, // Usage Page (Generic Desktop Ctrls)0x09, 0x02, // Usage (Mouse)0xA1, 0x01, // Collection (Application)0x09, 0x01, // Usage (Pointer)0xA1, 0x00, // Collection (Physical)0x05, 0x01, // Usage Page (Generic Desktop Ctrls)0x09, 0x30, // Usage (X)0x09, 0x31, // Usage (Y)0x09, 0x38, // Usage (Wheel)0x15, 0x81, // Logical Minimum (-127)0x25, 0x7F, // Logical Maximum (127)0x75, 0x08, // Report Size (8)0x95, 0x03, // Report Count (3)0x81, 0x06, // Input (Data,Var,Rel,No Wrap,Linear,Preferred State,No Null Position)0xC0, // End Collection0xC0, // End CollectionReport Description size:Code:#define USBD_CUSTOM_HID_REPORT_DESC_SIZE 0x1Estruct declared in main.cCode:struct mouseHID_t {int8_t x;int8_t y;int8_t wheel;};struct mouseHID_t mouseHID;code in while loop:Code:while (1){if (HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_9) == 0){mouseHID.wheel = 1;USBD_CUSTOM_HID_SendReport(&hUsbDeviceFS, &mouseHID, sizeof(struct mouseHID_t));mouseHID.wheel = 0;}}When I push a button on my board it will scroll the mouse wheel up. If I change the report description to remove the x & y usage, change the description size to say 0x1A (26) and change the mouseHID struct to remove the x & y, the board no longer scrolls the mouse wheel.The furthest I've been able to run it down to is in "USBD_CUSTOM_HID_SendReport" the statement "if (hhid->state == CUSTOM_HID_IDLE)" never equals true as the hhid->state == CUSTOM_HID_BUSY.Changes I make so anyone can check my work:Code:0x05, 0x01, // Usage Page (Generic Desktop Ctrls)0x09, 0x02, // Usage (Mouse)0xA1, 0x01, // Collection (Application)0x09, 0x01, // Usage (Pointer)0xA1, 0x00, // Collection (Physical)0x05, 0x01, // Usage Page (Generic Desktop Ctrls)0x09, 0x38, // Usage (Wheel)0x15, 0x81, // Logical Minimum (-127)0x25, 0x7F, // Logical Maximum (127)0x75, 0x08, // Report Size (8)0x95, 0x01, // Report Count (1)0x81, 0x06, // Input (Data,Var,Rel,No Wrap,Linear,Preferred State,No Null Position)0xC0, // End Collection0xC0, // End Collection#define USBD_CUSTOM_HID_REPORT_DESC_SIZE 0x1A

author: Renate
author_rank: Super Contributor
timestamp: October 15, 2020, 12:36:16 pm
content: I can't spot any mistake in your code.The classic error of course is to change something in your HID descriptor by editting the comment and forgeting to change the hex value!I don't know anything about the STM32 or the library you're using, but I take it that CUSTOM_HID_BUSY means that the buffers are full and nothing is accepting your reports.What is your host that you are using? Linux or Windows?Windows is pretty bad for seeing a USB device that it has identified previously and something important has changed and getting all confused.The worst is when you change the number of interfaces.Usually when I do development and make major changes I purge the registry of the instance so that the new instance is totally new.That stuff is in HKLM\System\CurrentControlSet\Enum\USB under VID & PID.I have a utility for listing/clearing that stuff.The question is where is it bombing.Is the host suspending it right after receiving the HID report descriptor?Is the host suspending at the first HID report?You should definitely use your USB hardware protocol analyzer.Ha! I just looked at some code that I wrote for AVR8 that uses scroll wheel only.The HID report descriptor is about the same as yours.

author: evglabs
author_rank: Contributor
timestamp: October 15, 2020, 04:53:40 pm
content: I think you're right about the "CUSTOM_HID_BUSY" meaning the buffer is full.I am using Windows, and am leaning towards it being a Windows issue. I works fine on linux soI'll have to try the registry purging, I wasn't aware of that, thanks.QuoteAh yes, let me just open my wallet to buy one... oh rightThat's good to hear about your report being similar, at least I do understand that part!

author: Renate
author_rank: Super Contributor
timestamp: October 15, 2020, 06:14:21 pm
content: Well, if Windows hates a USB device it will suspend it.You can see that by the disconnect bong a few seconds after you plug it in.It will also be visible in devmgmt.msc (Device Manager).Your STM32 library should tell you somehow when you get suspended also.Just delete the corresponding tree in the registry.It does no harm. I sometimes delete EVERYTHING.It just means that Windows will have to scratch its head a little the next time you reboot.USB devices without serial strings create a new instance every time you plug them into a different USB port.(I hate devices without serial strings.)

author: LootMaster
author_rank: Regular Contributor
timestamp: October 15, 2020, 06:15:13 pm
content: I have one of these USB analyzer Beagle-12, I never got to use it yet. Good thing I got it on ebay used.Anyways, there is an example well written pdf for this exact implementation on the ST website.Change the keyboard example for the mouse, and report size from 8 to 4.Theres a video about it.Also, depending on the VBUS setting if you have it or not or if you blew it or not depending if you have a divider or not, then it might not work.Edit: Why don't you just use the HID, its a default functionnal mouse

author: Renate
author_rank: Super Contributor
timestamp: October 15, 2020, 08:42:39 pm
content: Quote from: LootMaster on October 15, 2020, 06:15:13 pmWhaaaaat? Use it!

author: LootMaster
author_rank: Regular Contributor
timestamp: October 15, 2020, 09:21:26 pm
content: Heh... I could make the libraries work without any tool...It was for an OTG scenario...Wich I abandoned.

author: evglabs
author_rank: Contributor
timestamp: October 16, 2020, 03:25:59 am
content: QuoteNo particular reason, I'm just trying to teach myself this whole USB thing and trying to do something off the tutorials from ST to test my understanding.

author: Renate
author_rank: Super Contributor
timestamp: October 16, 2020, 11:55:13 am
content: So, it looks like it's more complicated.Windows doesn't seem to accept a scroll wheel unless it's part of a mouse in which case it requires X and Y too.(It is true that I had a report descriptor with only a wheel, but apparently it didn't work!)Edit: I tried going around this using the "Consumer Controls" (0x0c), "AC Scroll" (0x0235).I think that this used to work in earlier Windows, but apparently MS stripped out most of the AC out of the HID driver.I believe it's supported in Logitech drivers or fancy-schmancy intelliwhatever Microsoft product drivers.Still, it's a pain.

author: mon2
author_rank: Frequent Contributor
timestamp: October 18, 2020, 04:58:42 pm
content: Validate your descriptor table using this free tool:https://www.thesycon.de/eng/usb_descriptordumper.shtmland post your results.

author: Renate
author_rank: Super Contributor
timestamp: October 18, 2020, 06:56:27 pm
content: Mmm, I didn't even try that utility, but does it actually dump the HID report descriptors?It seems that prying the actual HID report descriptors (not "preparsed data") out of MS's cold hands is difficult.(In Linux it's easy to extract HID report descriptors.)Moreover, dumping and validating are two different things.MS's old usbview.exe does about the same thing, that is, dump (non HID report) descriptors.There is usb.org's usbdt, which is handy for generating HID report descriptors.I have something that can extract the HID RDs out of my project's ELF file and another utility for dumping that.It does *some* validation.It's mostly useful for verifying that the hex values in my source files agree with the comments in my source files.