forked from stm/stm32-mw-usb-device
Fix ST USB Device Library Bug: Most 16-bit Descriptor lengths assumed high bits were 0x00. This caused warnings and weird unexpected behavior when attempting to use descriptors longer than 255 bytes. (#3)
Co-authored-by: Berk Akinci <bakinci@zeevee.com> Co-authored-by: Ali LABBENE <46019491+ALABSTM@users.noreply.github.com>
This commit is contained in:
@@ -45,6 +45,7 @@ EndBSPDependencies */
|
|||||||
/* Includes ------------------------------------------------------------------*/
|
/* Includes ------------------------------------------------------------------*/
|
||||||
#include "usbd_customhid.h"
|
#include "usbd_customhid.h"
|
||||||
#include "usbd_ctlreq.h"
|
#include "usbd_ctlreq.h"
|
||||||
|
#include "usbd_def.h"
|
||||||
|
|
||||||
|
|
||||||
/** @addtogroup STM32_USB_DEVICE_LIBRARY
|
/** @addtogroup STM32_USB_DEVICE_LIBRARY
|
||||||
@@ -167,8 +168,129 @@ __ALIGN_BEGIN static uint8_t USBD_CUSTOM_HID_CfgDesc[USB_CUSTOM_HID_CONFIG_DESC_
|
|||||||
0x11, /* bCUSTOM_HIDUSTOM_HID: CUSTOM_HID Class Spec release number */
|
0x11, /* bCUSTOM_HIDUSTOM_HID: CUSTOM_HID Class Spec release number */
|
||||||
0x01,
|
0x01,
|
||||||
0x00, /* bCountryCode: Hardware target country */
|
0x00, /* bCountryCode: Hardware target country */
|
||||||
0x01, /* bNumDescriptors: Number of CUSTOM_HID class descriptors
|
0x01, /* bNumDescriptors: Number of CUSTOM_HID class descriptors to follow */
|
||||||
to follow */
|
0x22, /* bDescriptorType */
|
||||||
|
LOBYTE(USBD_CUSTOM_HID_REPORT_DESC_SIZE), /* wItemLength: Total length of Report descriptor */
|
||||||
|
HIBYTE(USBD_CUSTOM_HID_REPORT_DESC_SIZE),
|
||||||
|
/******************** Descriptor of Custom HID endpoints ********************/
|
||||||
|
/* 27 */
|
||||||
|
0x07, /* bLength: Endpoint Descriptor size */
|
||||||
|
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: */
|
||||||
|
|
||||||
|
CUSTOM_HID_EPIN_ADDR, /* bEndpointAddress: Endpoint Address (IN) */
|
||||||
|
0x03, /* bmAttributes: Interrupt endpoint */
|
||||||
|
LOBYTE(CUSTOM_HID_EPIN_SIZE), /* wMaxPacketSize: 2 Bytes max */
|
||||||
|
HIBYTE(CUSTOM_HID_EPIN_SIZE),
|
||||||
|
CUSTOM_HID_FS_BINTERVAL, /* bInterval: Polling Interval */
|
||||||
|
/* 34 */
|
||||||
|
|
||||||
|
0x07, /* bLength: Endpoint Descriptor size */
|
||||||
|
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: */
|
||||||
|
CUSTOM_HID_EPOUT_ADDR, /* bEndpointAddress: Endpoint Address (OUT) */
|
||||||
|
0x03, /* bmAttributes: Interrupt endpoint */
|
||||||
|
LOBYTE(CUSTOM_HID_EPOUT_SIZE), /* wMaxPacketSize: 2 Bytes max */
|
||||||
|
HIBYTE(CUSTOM_HID_EPOUT_SIZE),
|
||||||
|
CUSTOM_HID_FS_BINTERVAL, /* bInterval: Polling Interval */
|
||||||
|
/* 41 */
|
||||||
|
};
|
||||||
|
|
||||||
|
/* USB CUSTOM_HID device HS Configuration Descriptor */
|
||||||
|
__ALIGN_BEGIN static uint8_t USBD_CUSTOM_HID_CfgHSDesc[USB_CUSTOM_HID_CONFIG_DESC_SIZ] __ALIGN_END =
|
||||||
|
{
|
||||||
|
0x09, /* bLength: Configuration Descriptor size */
|
||||||
|
USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType: Configuration */
|
||||||
|
LOBYTE(USB_CUSTOM_HID_CONFIG_DESC_SIZ), /* wTotalLength: Bytes returned */
|
||||||
|
HIBYTE(USB_CUSTOM_HID_CONFIG_DESC_SIZ),
|
||||||
|
0x01, /* bNumInterfaces: 1 interface */
|
||||||
|
0x01, /* bConfigurationValue: Configuration value */
|
||||||
|
0x00, /* iConfiguration: Index of string descriptor describing the configuration */
|
||||||
|
#if (USBD_SELF_POWERED == 1U)
|
||||||
|
0xC0, /* bmAttributes: Bus Powered according to user configuration */
|
||||||
|
#else
|
||||||
|
0x80, /* bmAttributes: Bus Powered according to user configuration */
|
||||||
|
#endif
|
||||||
|
USBD_MAX_POWER, /* MaxPower (mA) */
|
||||||
|
|
||||||
|
/************** Descriptor of CUSTOM HID interface ****************/
|
||||||
|
/* 09 */
|
||||||
|
0x09, /* bLength: Interface Descriptor size */
|
||||||
|
USB_DESC_TYPE_INTERFACE, /* bDescriptorType: Interface descriptor type */
|
||||||
|
0x00, /* bInterfaceNumber: Number of Interface */
|
||||||
|
0x00, /* bAlternateSetting: Alternate setting */
|
||||||
|
0x02, /* bNumEndpoints */
|
||||||
|
0x03, /* bInterfaceClass: CUSTOM_HID */
|
||||||
|
0x00, /* bInterfaceSubClass : 1=BOOT, 0=no boot */
|
||||||
|
0x00, /* nInterfaceProtocol : 0=none, 1=keyboard, 2=mouse */
|
||||||
|
0, /* iInterface: Index of string descriptor */
|
||||||
|
/******************** Descriptor of CUSTOM_HID *************************/
|
||||||
|
/* 18 */
|
||||||
|
0x09, /* bLength: CUSTOM_HID Descriptor size */
|
||||||
|
CUSTOM_HID_DESCRIPTOR_TYPE, /* bDescriptorType: CUSTOM_HID */
|
||||||
|
0x11, /* bCUSTOM_HIDUSTOM_HID: CUSTOM_HID Class Spec release number */
|
||||||
|
0x01,
|
||||||
|
0x00, /* bCountryCode: Hardware target country */
|
||||||
|
0x01, /* bNumDescriptors: Number of CUSTOM_HID class descriptors to follow */
|
||||||
|
0x22, /* bDescriptorType */
|
||||||
|
LOBYTE(USBD_CUSTOM_HID_REPORT_DESC_SIZE), /* wItemLength: Total length of Report descriptor */
|
||||||
|
HIBYTE(USBD_CUSTOM_HID_REPORT_DESC_SIZE),
|
||||||
|
/******************** Descriptor of Custom HID endpoints ********************/
|
||||||
|
/* 27 */
|
||||||
|
0x07, /* bLength: Endpoint Descriptor size */
|
||||||
|
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType */
|
||||||
|
|
||||||
|
CUSTOM_HID_EPIN_ADDR, /* bEndpointAddress: Endpoint Address (IN) */
|
||||||
|
0x03, /* bmAttributes: Interrupt endpoint */
|
||||||
|
LOBYTE(CUSTOM_HID_EPIN_SIZE), /* wMaxPacketSize: 2 Bytes max */
|
||||||
|
HIBYTE(CUSTOM_HID_EPIN_SIZE),
|
||||||
|
CUSTOM_HID_HS_BINTERVAL, /* bInterval: Polling Interval */
|
||||||
|
/* 34 */
|
||||||
|
|
||||||
|
0x07, /* bLength: Endpoint Descriptor size */
|
||||||
|
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: */
|
||||||
|
CUSTOM_HID_EPOUT_ADDR, /* bEndpointAddress: Endpoint Address (OUT) */
|
||||||
|
0x03, /* bmAttributes: Interrupt endpoint */
|
||||||
|
LOBYTE(CUSTOM_HID_EPOUT_SIZE), /* wMaxPacketSize: 2 Bytes max */
|
||||||
|
HIBYTE(CUSTOM_HID_EPOUT_SIZE),
|
||||||
|
CUSTOM_HID_HS_BINTERVAL, /* bInterval: Polling Interval */
|
||||||
|
/* 41 */
|
||||||
|
};
|
||||||
|
|
||||||
|
/* USB CUSTOM_HID device Other Speed Configuration Descriptor */
|
||||||
|
__ALIGN_BEGIN static uint8_t USBD_CUSTOM_HID_OtherSpeedCfgDesc[USB_CUSTOM_HID_CONFIG_DESC_SIZ] __ALIGN_END =
|
||||||
|
{
|
||||||
|
0x09, /* bLength: Configuration Descriptor size */
|
||||||
|
USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType: Configuration */
|
||||||
|
LOBYTE(USB_CUSTOM_HID_CONFIG_DESC_SIZ), /* wTotalLength: Bytes returned */
|
||||||
|
HIBYTE(USB_CUSTOM_HID_CONFIG_DESC_SIZ),
|
||||||
|
0x01, /* bNumInterfaces: 1 interface */
|
||||||
|
0x01, /* bConfigurationValue: Configuration value */
|
||||||
|
0x00, /* iConfiguration: Index of string descriptor describing the configuration */
|
||||||
|
#if (USBD_SELF_POWERED == 1U)
|
||||||
|
0xC0, /* bmAttributes: Bus Powered according to user configuration */
|
||||||
|
#else
|
||||||
|
0x80, /* bmAttributes: Bus Powered according to user configuration */
|
||||||
|
#endif
|
||||||
|
USBD_MAX_POWER, /* MaxPower (mA) */
|
||||||
|
|
||||||
|
/************** Descriptor of CUSTOM HID interface ****************/
|
||||||
|
/* 09 */
|
||||||
|
0x09, /* bLength: Interface Descriptor size */
|
||||||
|
USB_DESC_TYPE_INTERFACE, /* bDescriptorType: Interface descriptor type */
|
||||||
|
0x00, /* bInterfaceNumber: Number of Interface */
|
||||||
|
0x00, /* bAlternateSetting: Alternate setting */
|
||||||
|
0x02, /* bNumEndpoints */
|
||||||
|
0x03, /* bInterfaceClass: CUSTOM_HID */
|
||||||
|
0x00, /* bInterfaceSubClass : 1=BOOT, 0=no boot */
|
||||||
|
0x00, /* nInterfaceProtocol : 0=none, 1=keyboard, 2=mouse */
|
||||||
|
0, /* iInterface: Index of string descriptor */
|
||||||
|
/******************** Descriptor of CUSTOM_HID *************************/
|
||||||
|
/* 18 */
|
||||||
|
0x09, /* bLength: CUSTOM_HID Descriptor size */
|
||||||
|
CUSTOM_HID_DESCRIPTOR_TYPE, /* bDescriptorType: CUSTOM_HID */
|
||||||
|
0x11, /* bCUSTOM_HIDUSTOM_HID: CUSTOM_HID Class Spec release number */
|
||||||
|
0x01,
|
||||||
|
0x00, /* bCountryCode: Hardware target country */
|
||||||
|
0x01, /* bNumDescriptors: Number of CUSTOM_HID class descriptors to follow */
|
||||||
0x22, /* bDescriptorType */
|
0x22, /* bDescriptorType */
|
||||||
LOBYTE(USBD_CUSTOM_HID_REPORT_DESC_SIZE), /* wItemLength: Total length of Report descriptor */
|
LOBYTE(USBD_CUSTOM_HID_REPORT_DESC_SIZE), /* wItemLength: Total length of Report descriptor */
|
||||||
HIBYTE(USBD_CUSTOM_HID_REPORT_DESC_SIZE),
|
HIBYTE(USBD_CUSTOM_HID_REPORT_DESC_SIZE),
|
||||||
|
|||||||
Reference in New Issue
Block a user