Skip to main content
Visitor II
May 12, 2025
Solved

The maxium length of buffer for USB HID SetReport

  • May 12, 2025
  • 1 reply
  • 602 views

Hi,

I would like to know why when I sent the 202 bytes from pc to dev-board via USB HID, the buffer size would only get 32 byte each time, (byte[0]-byte[31])*several times until finished print out all 202 bytes?

Couldn't it recieved whole 202 bytes then print out continuously from byte[0] to byte[201]?

ux_device_keyboard.c

/**
 * @brief USBD_HID_Keyboard_SetReport
 * This function is invoked when the host sends a HID SET_REPORT
 * to the application over Endpoint 0.
 * @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_SetReport(UX_SLAVE_CLASS_HID *hid_instance,
 UX_SLAVE_CLASS_HID_EVENT *hid_event)
{
 UINT status = UX_SUCCESS;

 /* USER CODE BEGIN USBD_HID_Keyboard_SetReport */
 UX_PARAMETER_NOT_USED(hid_instance);
 UX_PARAMETER_NOT_USED(hid_event);

 //Receive Output report from PC
 if (hid_event == UX_NULL || hid_event->ux_device_class_hid_event_length < 2)
 return UX_ERROR;

 uint8_t report_id = hid_event->ux_device_class_hid_event_buffer[0];
 uint8_t *data = &hid_event->ux_device_class_hid_event_buffer[1];
 UINT data_len = hid_event->ux_device_class_hid_event_length - 1;

 if (report_id == 0x02 && data_len <= MAX_HID_OUTPUT_REPORT_SIZE)
 {
 // Copy the data to global buffer for later processing
 memcpy(g_output_report_buffer, data, data_len);
 g_output_report_length = data_len;
 g_output_report_ready = 1;
 }
 /* USER CODE END USBD_HID_Keyboard_SetReport */

 return status;
}

 

And the desriptor alos has been changed like 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 (HID Device)*/\
 0x09, 0xFF, /* USAGE (ASIC USAGE) */\
 0xa1, 0x01, /* COLLECTION (Application) */\
 0x15, 0x00, /* LOGICAL_MINIMUM (0) */\
 0x25, 0xff, /* LOGICAL_MAXIMUM (255) */\
 0x75, 0x08, /* REPORT_SIZE (8) */\
 0x85, 0x01, /* REPORT_ID (1). This defines input to the host side */\
 0x95, 0x10, /* REPORT_COUNT (16) */\
 0x09, 0x01, /* USAGE (ASIC USAGE) */\
 0x75, 0x08, /* REPORT_SIZE (8)*/\
 0x81, 0x02, /* INPUT (Data,Var,Abs) (note: output from host) */\
 0x85, 0x02, /* REPORT_ID (2). This defines output from the host side */\
 0x95, 0xC9, /* REPORT_COUNT (201) */\
 0x09, 0x01, /* USAGE (ASIC USAGE) */\
 0x75, 0x08, /* REPORT_SIZE (8)*/\
 0x91, 0x02, /* OUTPUT (Data,Var,Abs) (note: input to host) */\
 /* USER CODE END USBD_HID_KEYBOARD_ReportDesc */
 0xc0 /* End Collection */
};

 

    This topic has been closed for replies.
    Best answer by TDK

    This is not something you can change.

    1 reply

    Super User
    May 12, 2025

    USB FS packets are max 64 bytes in length. I assume the 32-byte packet size is some subset of those 64 bytes, probably HID-specific.

    If you want them as a contiguous buffer, you'll have to reassemble them on the receiving side.

    CYHAuthor
    Visitor II
    May 13, 2025

    Hi Guru,

    Thank you for the reply.

    Do you know if I would like to modified the setting from .ioc file, which item I should modified? I would like to try to make the maxium be 64, as larger as it can.

     

    TDKAnswer
    Super User
    May 13, 2025

    This is not something you can change.