STM32WB55; USB OutReport; not recieving data
Hello, I've been trying to setup bi-directional communication with USB-HID on a custom board with STM32WB55CEU. I can send data to the PC from the STM just fine. My usb stack runs, enumerates and reports correctly. However, when trying to send Data from the PC back to the STM, I always receive garbage packages.
Here's my device descriptor for the Outreport:
0x09, 0x03, // USAGE (Vendor Usage 3)
0x75, 0x08, // REPORT_SIZE (8)
0x95, 0x04, // REPORT_COUNT (4)
0x91, 0x02, // OUTPUT (Data,Var,Abs)So 4 Bytes. I also tried this with and without adding a Report ID, which did not change the results whatsoever.
I have also tried running the code with defining USB_CUSTOMHID_REPORT_BUFFER_EVENT_ENABLED; both in main.h and in usbd_customhid.c and usbd_customhid.h to no changes.
I also tried changing CUSTOM_HID_EPOUT_SIZE to 0x04 and 0x05, same with USBD_CUSTOMHID_OUTREPORT_BUF_SIZE. Including all of the combinations with and without report ID and with and without enabling the buffer define.
Here is my OutReport callback:
static int8_t CUSTOM_HID_OutEvent_FS(uint8_t event_idx, uint8_t state)
{
/* USER CODE BEGIN 6 */
/* Start next USB packet transfer once data processing is completed */
USBD_CUSTOM_HID_ReceivePacket(&hUsbDeviceFS);
uint8_t *buffer = (uint8_t*) ((uint32_t) event_idx);
uint8_t a = buffer[0];
uint8_t b = buffer[1];
uint8_t c = buffer[2];
uint8_t d = buffer[3];
USBD_CUSTOM_HID_HandleTypeDef* hhid = (USBD_CUSTOM_HID_HandleTypeDef*)hUsbDeviceFS.pClassData;
uint8_t *buffer2 = hhid->Report_buf;
uint8_t e = buffer2[0];
uint8_t f = buffer2[1];
uint8_t g = buffer2[2];
uint8_t h = buffer2[3];
if(buffer[0] ==0x01|| buffer2[0]==0x01){
HAL_GPIO_TogglePin(LED_GPIO_Port, LED_Pin);
}
return (USBD_OK);
/* USER CODE END 6 */
}I tried putting both USBD_CUSTOM_HID_ReceivePacket(), before AND after handling the data, but this did not change anything. The callback does trigger correctly, so the stack works for triggering OutReports, and I would inspect the contents of the buffers with breakpoint. The first method of accessing buffer I saw from this: https://stm32world.com/wiki/STM32_USB_Custom_HID. This method however, always produces the same seemingly random bytes. The second buffer2 on the other hand, accessing it the "proper" way, would always just mirror the contents of event_idx and state, which leads me to believe the hhid->Report_buf is never initialized and is just reading the first memory in stack. The contents of the 2 buffers never were even close to the bytes I was sending.
I send the HID report on my Linux computer through <hidapi/hidapi.h>, compiled with hidapi-hidraw and this code:
char report[4] = { 0x01,0x02,0x03,0x04};
int res = hid_write(handle, report, 4*sizeof(char));
I honestly don't know what else to try or where else to look. This seems like a hyperspecific issue and I have no clue why it's happening. I find it odd that the callback triggers but without the correct data, how does that even happen? I would appreciate the help.
