Get Report Callback data is different from bus hound sniff data
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-06-14 10:05 AM
Hi,
I would like to consult the USB HID GetReport feature.
The issue is that the printout data from MCU log is different from bus hound displayed result.
Bus hound is trial version, the data length indeed is 16.
This is the log I set to printout from USBD_HID_Keyboard_SetReport
#define UX_DEVICE_CLASS_HID_EVENT_BUFFER_LENGTH 32
static uint8_t g_last_input_report[17]; // adjust size to match your report
static UINT g_last_input_report_len = 0;
/**
* @brief USBD_HID_Keyboard_GetReport
* This function is invoked when host is requesting event through
* control GET_REPORT request.
* @PAram hid_instance: Pointer to the hid class instance.
* @PAram hid_event: Pointer to structure of the hid event.
* @retval status
*/
UINT USBD_HID_Keyboard_GetReport(UX_SLAVE_CLASS_HID *hid_instance,
UX_SLAVE_CLASS_HID_EVENT *hid_event) {
printf(">>> USBD_HID_Keyboard_GetReport invoked\r\n");
static uint32_t get_report_counter = 0;
printf("=== GET_REPORT #%lu at %lu ms ===\r\n", ++get_report_counter, HAL_GetTick());
if (hid_event == UX_NULL || g_last_input_report_len == 0)
return UX_ERROR;
//Type1:Input ;; Type3:Feature
printf(">>> GetReport Request: type=%lu, id=0x%02lX\r\n, Buffer len: %lu\r\n",
hid_event->ux_device_class_hid_event_report_type,
hid_event->ux_device_class_hid_event_report_id,
g_last_input_report_len);
if (hid_event->ux_device_class_hid_event_report_id== 0x01&&
hid_event->ux_device_class_hid_event_report_type == UX_DEVICE_CLASS_HID_REPORT_TYPE_INPUT)
{
if (g_last_input_report_len <= UX_DEVICE_CLASS_HID_EVENT_BUFFER_LENGTH) {
memcpy(hid_event->ux_device_class_hid_event_buffer,
g_last_input_report, g_last_input_report_len);
hid_event->ux_device_class_hid_event_length =
g_last_input_report_len;
printf("GetReport:");
for (UINT i = 0; i < g_last_input_report_len; i++) {
printf("%02X,", g_last_input_report[i]);
}
printf("\r\n");
return UX_SUCCESS;
}
}
printf("ERROR: Conditions not met, returning UX_ERROR\r\n");
return UX_ERROR;
}
Also add the log in _ux_device_class_hid_report_get
However, in here is still show the different data from bus hound capture though it is still aligned the data in GetReport Callback.
The HID descriptor is set as below
__ALIGN_BEGIN uint8_t USBD_HID_KEYBOARD_ReportDesc[]
__ALIGN_END =
{
/* USER CODE BEGIN USBD_HID_KEYBOARD_ReportDesc */
//Wedy Change for customized report
0x06, 0x00, 0xFF, // USAGE PAGE (Vendor Defined)
0x09, 0xFF, // USAGE (Vendor Usage)
0xA1, 0x01, // COLLECTION (Application)
// Feature Report - Report ID 1
0x85, 0x01, // REPORT_ID (1)
0x15, 0x00, // LOGICAL_MINIMUM (0)
0x25, 0xFF, // LOGICAL_MAXIMUM (255)
0x75, 0x08, // REPORT_SIZE (8)
0x95, 0x10, // REPORT_COUNT (16)
0x09, 0x01, // USAGE (Vendor Specific)
0x81, 0x02, // INPUT (Data,Var,Abs)
// Feature Report - Report ID 1 (16 bytes)
0x85, 0x01, // REPORT_ID (1)
0x95, 0x10, // REPORT_COUNT (16)
0x09, 0x02, // USAGE (Vendor Specific)
0xB1, 0x02, // FEATURE (Data,Var,Abs)
// Output Report - Report ID 2
0x85, 0x02, // REPORT_ID (2)
0x95, 0x11, // REPORT_COUNT (17)
0x09, 0x01, // USAGE (Vendor Specific)
0x91, 0x02, // OUTPUT (Data,Var,Abs)
/* USER CODE END USBD_HID_KEYBOARD_ReportDesc */
0xc0 /* End Collection */
};
- Labels:
-
STM32U0 Series
-
USB
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-06-16 4:08 AM
Hi @CYH
Which STM32U0 are you using? Would you attach minimum firmware to replicate the issue on a reference board?
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-06-16 7:08 AM
Hi @FBL ,
Thank you for your reply.
I am using STM32U083C-DK as test platform but with STM32U083HCY6 pin configuration.
The minimum firmware you are saying is the source code, right?
Please kindly check the attach files as your reference.
int main(void)
{
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_USBX_Device_Init();
MX_USART2_UART_Init();
/* USER CODE BEGIN 2 */
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
//Set up the device descriptor
USBX_Device_Process(NULL);
}
/* USER CODE END 3 */
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-06-16 10:42 AM
Hi @CYH
Here are some suggestions :
First, ensure buffer alignment in USBD_HID_Keyboard_SendReport to prevent unaligned memory access
uint8_t full_report[1 + 15] __attribute__((aligned(8)));
Second, before copying g_last_input_report into the hid_event buffer, ensure the buffer size does not exceed the allowed limit in USBD_HID_Keyboard_GetReport
if (g_last_input_report_len > UX_DEVICE_CLASS_HID_EVENT_BUFFER_LENGTH) {
printf("Error: Buffer overflow detected\r\n");
return UX_ERROR;
}
In USBD_HID_Keyboard_SetReport, verify the size of the data being copied into g_output_report_buffer to ensure it does not exceed the maximum allowed size:
if (data_len > MAX_HID_OUTPUT_REPORT_SIZE) {
printf("Error: Output report too large\r\n");
return UX_ERROR;
}
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-06-16 6:46 PM
Hi @FBL ,
Thank you for your suggestion.
However, after modification the result still failed.
As the image show above, I found that even I didn't set g_last_input_report for GetReport, there still have data be reported whenever host try to get report from ID 1, and the value seems could be changed randomly.
Besides that, I found that after I set the g_last_input_report which expected to be 01 D4........, though the reported data is not expected, but the value seems keep the same each time.
Not sure whether it is any hint for you to help with the analysis.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-06-18 11:09 AM
Hi @CYH
Here some suggestions:
- Implement software debouncing (e.g., require stable button state for 20-50 ms).
- Send a zeroed report immediately after key press to simulate key release to avoid data reported continuously.
VOID USBX_DEVICE_HID_CUSTOMER_Task(VOID) {
static ULONG last_tick = 0;
ULONG current_tick;
UX_SLAVE_DEVICE *device;
UX_SLAVE_CLASS_HID_EVENT hid_event;
device = &_ux_system_slave->ux_system_slave_device;
ux_utility_memory_set(&hid_event, 0, sizeof(UX_SLAVE_CLASS_HID_EVENT));
current_tick = HAL_GetTick();
if ((device->ux_slave_device_state == UX_DEVICE_CONFIGURED) && (hid_keyboard != UX_NULL))
{
if (ux_utility_time_elapsed(last_tick, current_tick) < BUTTON_DETECT_WAIT)
{
return; // Wait for debounce period
}
last_tick = current_tick;
if (User_Button_State) // Button pressed (edge detection recommended)
{
GetKeyData(&hid_event); // Fill HID report for key press
if (ux_device_class_hid_event_set(hid_keyboard, &hid_event) == UX_SUCCESS)
{
// Prepare key release report (all zeros)
memset(hid_event.ux_device_class_hid_event_buffer, 0, hid_event.ux_device_class_hid_event_length);
ux_device_class_hid_event_set(hid_keyboard, &hid_event);
User_Button_State = 0U; // Reset button state after event sent
}
else
{
// Handle error (optional)
}
}
}
}
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-06-19 8:41 PM
Hi @FBL ,
Thank you for your comment.
However, there is no button design in my application, and it is not sending the actual keycode, therefore, does it still need to send the data zero to simulate? If so.... the get report data also need to have zero data input?
Actually, as you saw from the descriptor I provided above... I am just using the _ux_device_class_hid_event_set to output the data to host and also leave the same data for get report.
In this case, if I set zero.... then how to leave the data I want for system when get report?
Do you have suggestion for the my case?
