This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

USB HID

Hi all,

I would like to consult a technical issue here. I am trying to develop a simple USB HID communication between PC and device board with STM32F400. On the host side (PC) I am using Visual Studio to build my application using a DLL for USB HID. The communication works fine but only for reports until 255 bytes long. When I try to set higher output report value (e.g. 1023 bytes) in uVision I can still recieve only reports 255 bytes long. I debugged this with ULINK2 and examined the "usbd_hid_set_report" function. The parameter len is still 255 even though USBD_HID_OUTREPORT_MAX_SZ is set to 1023 and the array sent from PC has 1023 bytes. I can also check this value on the PC side by reading the descriptor and the value reported by the USB device (STM32F400) is still 255 bytes even though it should be 1023 bytes. Do you have any idea where I am going wrong? Max allowed value for USBD_HID_OUTREPORT_MAX_SZ is 65535 bytes according to the documentation.

Any ideas?

Best regards,
Steven.

Parents
  • > I can also check this value on the PC side by reading the descriptor and the value reported by the USB device (STM32F400) is still 255 bytes even though it should be 1023 bytes.

    Your finding suggests a problem on the report descriptor definition.

    You are talking about RL-USB library
    In this library, the HID report descriptor is defined in usb_lib.c

    C:\Keil\ARM\RV31\INC\usb_lib.c
    
    __weak \ 
    const U8 USBD_HID_ReportDescriptor[] = {
      HID_UsagePageVendor( 0x00                      ),
      HID_Usage          ( 0x01                      ),
      HID_Collection     ( HID_Application           ),
        HID_LogicalMin   ( 0                         ), /* value range: 0 - 0xFF */
        HID_LogicalMaxS  ( 0xFF                      ),
        HID_ReportSize   ( 8                         ), /* 8 bits */
        HID_ReportCount  ( USBD_HID_INREPORT_MAX_SZ  ),
        HID_Usage        ( 0x01                      ),
        HID_Input        ( HID_Data | HID_Variable | HID_Absolute ),
        HID_ReportCount  ( USBD_HID_OUTREPORT_MAX_SZ ),       // <-------
        HID_Usage        ( 0x01                      ),
        HID_Output       ( HID_Data | HID_Variable | HID_Absolute ),
        HID_ReportCount  ( USBD_HID_FEATREPORT_MAX_SZ),
        HID_Usage        ( 0x01                      ),
        HID_Feature      ( HID_Data | HID_Variable | HID_Absolute ),
      HID_EndCollection,
    };
    

    The source of your problem lies in HID_ReportCount() macro
    It is defined in C:\Keil\ARM\RL\USB\INC\usb_hid.h

    #define HID_ReportCount(x) 0x95,x

    This macro accepts no more than 255 bytes.

    You may override above definition by having this code on your file.

    #define HID_ReportCountS(x)    0x96, 0x00FF & (x), (0xFF00 & (x)) >> 16
    
    const U8 USBD_HID_ReportDescriptor[] = {
      HID_UsagePageVendor( 0x00                      ),
      HID_Usage          ( 0x01                      ),
      HID_Collection     ( HID_Application           ),
        HID_LogicalMin   ( 0                         ), /* value range: 0 - 0xFF */
        HID_LogicalMaxS  ( 0xFF                      ),
        HID_ReportSize   ( 8                         ), /* 8 bits */
        HID_ReportCount  ( USBD_HID_INREPORT_MAX_SZ  ),
        HID_Usage        ( 0x01                      ),
        HID_Input        ( HID_Data | HID_Variable | HID_Absolute ),
    #if USBD_HID_OUTREPORT_MAX_SZ < 0xFF
        HID_ReportCount  ( USBD_HID_OUTREPORT_MAX_SZ ),
    #else
        HID_ReportCountS ( USBD_HID_OUTREPORT_MAX_SZ ),
    #endif
        HID_Usage        ( 0x01                      ),
        HID_Output       ( HID_Data | HID_Variable | HID_Absolute ),
        HID_ReportCount  ( USBD_HID_FEATREPORT_MAX_SZ),
        HID_Usage        ( 0x01                      ),
        HID_Feature      ( HID_Data | HID_Variable | HID_Absolute ),
      HID_EndCollection,
    };
    

    Tsuneo

Reply
  • > I can also check this value on the PC side by reading the descriptor and the value reported by the USB device (STM32F400) is still 255 bytes even though it should be 1023 bytes.

    Your finding suggests a problem on the report descriptor definition.

    You are talking about RL-USB library
    In this library, the HID report descriptor is defined in usb_lib.c

    C:\Keil\ARM\RV31\INC\usb_lib.c
    
    __weak \ 
    const U8 USBD_HID_ReportDescriptor[] = {
      HID_UsagePageVendor( 0x00                      ),
      HID_Usage          ( 0x01                      ),
      HID_Collection     ( HID_Application           ),
        HID_LogicalMin   ( 0                         ), /* value range: 0 - 0xFF */
        HID_LogicalMaxS  ( 0xFF                      ),
        HID_ReportSize   ( 8                         ), /* 8 bits */
        HID_ReportCount  ( USBD_HID_INREPORT_MAX_SZ  ),
        HID_Usage        ( 0x01                      ),
        HID_Input        ( HID_Data | HID_Variable | HID_Absolute ),
        HID_ReportCount  ( USBD_HID_OUTREPORT_MAX_SZ ),       // <-------
        HID_Usage        ( 0x01                      ),
        HID_Output       ( HID_Data | HID_Variable | HID_Absolute ),
        HID_ReportCount  ( USBD_HID_FEATREPORT_MAX_SZ),
        HID_Usage        ( 0x01                      ),
        HID_Feature      ( HID_Data | HID_Variable | HID_Absolute ),
      HID_EndCollection,
    };
    

    The source of your problem lies in HID_ReportCount() macro
    It is defined in C:\Keil\ARM\RL\USB\INC\usb_hid.h

    #define HID_ReportCount(x) 0x95,x

    This macro accepts no more than 255 bytes.

    You may override above definition by having this code on your file.

    #define HID_ReportCountS(x)    0x96, 0x00FF & (x), (0xFF00 & (x)) >> 16
    
    const U8 USBD_HID_ReportDescriptor[] = {
      HID_UsagePageVendor( 0x00                      ),
      HID_Usage          ( 0x01                      ),
      HID_Collection     ( HID_Application           ),
        HID_LogicalMin   ( 0                         ), /* value range: 0 - 0xFF */
        HID_LogicalMaxS  ( 0xFF                      ),
        HID_ReportSize   ( 8                         ), /* 8 bits */
        HID_ReportCount  ( USBD_HID_INREPORT_MAX_SZ  ),
        HID_Usage        ( 0x01                      ),
        HID_Input        ( HID_Data | HID_Variable | HID_Absolute ),
    #if USBD_HID_OUTREPORT_MAX_SZ < 0xFF
        HID_ReportCount  ( USBD_HID_OUTREPORT_MAX_SZ ),
    #else
        HID_ReportCountS ( USBD_HID_OUTREPORT_MAX_SZ ),
    #endif
        HID_Usage        ( 0x01                      ),
        HID_Output       ( HID_Data | HID_Variable | HID_Absolute ),
        HID_ReportCount  ( USBD_HID_FEATREPORT_MAX_SZ),
        HID_Usage        ( 0x01                      ),
        HID_Feature      ( HID_Data | HID_Variable | HID_Absolute ),
      HID_EndCollection,
    };
    

    Tsuneo

Children