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 */
};
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.
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 */
}
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.
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.