2025-05-15 7:21 AM
Hello,
I'm new to the USB protocol and currently facing an issue with USBX.
I'm working on a project using ThreadX and the USBX stack, trying to develop a Custom HID device with two endpoints: one IN and one OUT.
I generated the code using STM32CubeMX, and then modified:
the HID descriptor,
the USBD_Custom_HID_Activate and USBD_Custom_HID_Deactivate functions,
as well as the thread entry:
static VOID app_ux_device_thread_entry(ULONG thread_input)
{
/* USER CODE BEGIN app_ux_device_thread_entry */
TX_PARAMETER_NOT_USED(thread_input);
HAL_PWREx_EnableVddUSB(); // Enable USB power
/* Initialize USB DRD_FS controller */
MX_USB_PCD_Init();
/* Configure USB packet memory area (PMA) for endpoints */
HAL_PCDEx_PMAConfig(&hpcd_USB_DRD_FS, 0x00, PCD_SNG_BUF, 0x0C); // EP0
HAL_PCDEx_PMAConfig(&hpcd_USB_DRD_FS, 0x80, PCD_SNG_BUF, 0x4C); // EP1 IN
HAL_PCDEx_PMAConfig(&hpcd_USB_DRD_FS, 0x81, PCD_SNG_BUF, 0x8C); // EP2 IN
HAL_PCDEx_PMAConfig(&hpcd_USB_DRD_FS, 0x02, PCD_SNG_BUF, 0xCC); // EP2 OUT
/* Initialize the device controller driver */
ux_dcd_stm32_initialize((ULONG)USB_DR
However, I noticed that the USBD_Custom_HID_SetReport and USBD_Custom_HID_GetReport functions are never called by the program, even though I have defined the necessary flags:
#define UX_DEVICE_CLASS_HID_INTERRUPT_OUT_SUPPORT
#define UX_DEVICE_BIDIRECTIONAL_ENDPOINT_SUPPORT
Board: STM32H573I-DK
RTOS: ThreadX
USB Stack: USBX middleware
USB Class: Custom HID Device
Report Size: 64 bytes (defined in the HID report descriptor)
I also tested sending data using the USB HID Demonstrator (v1.0.2) software.
The GET_FEATURE command works, but SET_REPORT does not seem to trigger any callback on the firmware side.
USB HID Demonstrator available here.
How can I receive the data sent by the host to my OUT endpoint?
Why are the SetReport and GetReport callback functions never triggered?
Is there any specific configuration required in CubeMX or during USBX initialization?
Thank you in advance for your help.
Best regards,
Solved! Go to Solution.
2025-05-26 6:22 AM
Hello,
My colleague and I managed to solve the problem. It was related to the initialization of the endpoint addresses.
Indeed, the addresses need to be adjusted according to the size of the chosen buffer. In our case, the buffer size was 64 bytes, so every address had to be a multiple of 64.
Here are the four relevant lines in the app_usbx_device.c file:
HAL_PCDEx_PMAConfig(&hpcd_USB_DRD_FS, 0x00, PCD_SNG_BUF, 0x40);
HAL_PCDEx_PMAConfig(&hpcd_USB_DRD_FS, 0x80, PCD_SNG_BUF, 0x80);
HAL_PCDEx_PMAConfig(&hpcd_USB_DRD_FS, USBD_HID_CUSTOM_EPOUT_ADDR, PCD_SNG_BUF, 0xC0);
HAL_PCDEx_PMAConfig(&hpcd_USB_DRD_FS, USBD_HID_CUSTOM_EPIN_ADDR, PCD_SNG_BUF, 0x100);
Now, the callback functions USBD_Custom_HID_SetReport and USBD_Custom_HID_GetReport are properly triggered.
Thank you.
2025-05-16 1:11 PM
To receive IN or OUT report requests in the device, the host must make these request. Otherwise the device won't see anything. Can you show the host code sending these requests?
2025-05-19 2:30 AM
Hi @Pavel A. ,
To send data to my board, I use the WebAuthn site, which allows simulating the registration of a FIDO2 security key. My STM32H573 is configured to be enumerated as a "HID-compliant FIDO" device. I have attached my descriptor file below.
During registration, the site is supposed to send data to the authenticator device via the CTAP protocol on the OUT endpoint.
I have also tested with STMicroelectronics' USB HID Demonstrator tool and can see that data is successfully transmitted from the STM32 board to the host. However, when I send data using the SET_REPORT command, the associated callback function is not invoked; only the SET_FEATURE function works.
2025-05-19 8:15 AM - edited 2025-05-19 8:16 AM
Hmm. When an output report is sent to device, do you see any data received by the device at the USB level (any endpoint received any data)? Or the problem is that a host cannot be convinced to send output reports?
2025-05-19 9:20 AM
I observed with Wireshark that when I initiate the enrollment step with WebAuthn, the host sends data to the OUT endpoint :
The issue is that the USBD_Custom_HID_SetReport callback function in my program is not being called.
If you have any insights or suggestions to resolve this problem, I would appreciate your assistance.
2025-05-19 12:16 PM
Try to debug, it looks like the problem is in software.
2025-05-20 1:30 AM
While debugging, I noticed that the ux_device_class_hid_receiver_thread goes into a semaphore wait state and remains blocked, even when registering on WebAuthn. Yet, with Wireshark I can clearly see data arriving on the OUT endpoint.
I placed a breakpoint on the return statement of the USBD_Custom_HID_SetReport function in the file ux_device_customhid.c, but it never gets triggered.
In the file app_usbx_device.c, I have correctly initialized the OUT endpoint:
#ifdef UX_DEVICE_CLASS_HID_INTERRUPT_OUT_SUPPORT
custom_hid_parameter.ux_device_class_hid_parameter_receiver_initialize = ux_device_class_hid_receiver_initialize;
custom_hid_parameter.ux_device_class_hid_parameter_receiver_event_max_number = USBD_Custom_HID_EventMaxNumber();
custom_hid_parameter.ux_device_class_hid_parameter_receiver_event_max_length = USBD_Custom_HID_EventMaxLength();
custom_hid_parameter.ux_device_class_hid_parameter_receiver_event_callback = USBD_Custom_HID_SetReport;
#endif /* UX_DEVICE_CLASS_HID_INTERRUPT_OUT_SUPPORT */
Please find below the USBX files from my project.
2025-05-26 6:22 AM
Hello,
My colleague and I managed to solve the problem. It was related to the initialization of the endpoint addresses.
Indeed, the addresses need to be adjusted according to the size of the chosen buffer. In our case, the buffer size was 64 bytes, so every address had to be a multiple of 64.
Here are the four relevant lines in the app_usbx_device.c file:
HAL_PCDEx_PMAConfig(&hpcd_USB_DRD_FS, 0x00, PCD_SNG_BUF, 0x40);
HAL_PCDEx_PMAConfig(&hpcd_USB_DRD_FS, 0x80, PCD_SNG_BUF, 0x80);
HAL_PCDEx_PMAConfig(&hpcd_USB_DRD_FS, USBD_HID_CUSTOM_EPOUT_ADDR, PCD_SNG_BUF, 0xC0);
HAL_PCDEx_PMAConfig(&hpcd_USB_DRD_FS, USBD_HID_CUSTOM_EPIN_ADDR, PCD_SNG_BUF, 0x100);
Now, the callback functions USBD_Custom_HID_SetReport and USBD_Custom_HID_GetReport are properly triggered.
Thank you.