搜索
查看: 9621|回复: 19

[已解决] USBD_HID_SendReport只能发送4个字节

[复制链接]

该用户从未签到

22

主题

563

帖子

41

蝴蝶豆

金牌会员

最后登录
2023-9-24
发表于 2018-7-25 08:55:57 | 显示全部楼层 |阅读模式
本帖最后由 jyl518-283289 于 2018-7-26 09:29 编辑

初学USB,请大家支持下!

采用STM32Cube生成STM32F103VBT6的MDK程序,
使用如下库函数
USBD_HID_SendReport(&hUsbDeviceFS,sendbuffer,20);
发送20个字节的数据,在USB抓到的数据可以看到,分成5次发送了???  难道不能一次发送完成 吗??

888

888
请大神帮忙解惑下!!!
看红色部分即可

按键盘“a”键的数据明显是一次发送8个字节
2.jpg
代码如下:
/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "stm32f1xx_hal.h"
#include "cmsis_os.h"
#include "usb_device.h"

osThreadId defaultTaskHandle;
osThreadId RS485_1Handle;

uint8_t uart1_rx_buf[20];
uint8_t uart1_rx_len = 20;
uint8_t uart1_rx_flag = 0;

uint8_t sendbuffer[20]={0x02,0x30,0x31,0x01,0x00,0x31,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x93,0x03};

/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
void StartDefaultTask(void const * argument);
void RS485_1Task(void const * argument);

int main(void)
{
  HAL_Init();
  SystemClock_Config();
  MX_GPIO_Init();
  osThreadDef(defaultTask, StartDefaultTask, osPriorityNormal, 0, 128);
  defaultTaskHandle = osThreadCreate(osThread(defaultTask), NULL);
  osThreadDef(RS485_1, RS485_1Task, osPriorityNormal, 0, 128);
  RS485_1Handle = osThreadCreate(osThread(RS485_1), NULL);
  osKernelStart();
  while (1)
  {
  }
}

void RS485_1Task(void const * argument)
{
  for(;;)
  {
      if(uart1_rx_flag)
      {
         HAL_GPIO_WritePin(DR1_GPIO_Port,DR1_Pin, GPIO_PIN_SET);                //使能485_1发送
         osDelay(100);
         HAL_UART_Transmit_IT(&huart1, uart1_rx_buf, uart1_rx_len);               
         osDelay(100);
         HAL_GPIO_WritePin(DR1_GPIO_Port,DR1_Pin, GPIO_PIN_RESET);                //使能485_1接收                        
         uart1_rx_flag = 0;
         osDelay(100);                        

        USBD_HID_SendReport(&hUsbDeviceFS,sendbuffer,20);    //此处发送20字节数据到PC机
        osDelay(100);        
     }
  }
}







回复

使用道具 举报

该用户从未签到

0

主题

6

帖子

7

蝴蝶豆

初级会员

最后登录
2019-4-30
发表于 2018-7-31 05:35:31 | 显示全部楼层
jyl518-283289 发表于 2018-7-27 14:24
1、USBD_HID_ConfigDesc 里面End point的 wMaxPacketSize 值已由0x04改0x08,此值前期改过不管用,可能是只 ...

HID_EPIN_SIZE 改了没有?不然描述符里虽然说 wMaxPacketSize 是0x8, 但是你的设备因为USB 驱动配置原因自己发不出去 0x8个字节

另外,我说的HID REPORT SIZE 不是 HID_MOUSE_REPORT_DESC_SIZE, 这个可能给你搞糊涂了。HID_MOUSE_REPORT_DESC_SIZE 是 USB HID 描述符本身的大小 (见HID_MOUSE_ReportDesc[HID_MOUSE_REPORT_DESC_SIZE])。 在这个 USB HID 描述符里面会告诉操作系统这个设备的HID REPORT是多少字节,如何去处理,等等细节。你学习下USB HID规范就了解了。HID_MOUSE_ReportDesc这个array里面奥妙很多的。

具体请看 http://notes.iopush.net/stm32-custom-usb-hid-step-by-step-2/http://damogranlabs.com/2016/03/ ... -device-yes-please/

评分

参与人数 1蝴蝶豆 +3 收起 理由
zero99 + 3

查看全部评分

回复 支持 1 反对 0

使用道具 举报

该用户从未签到

25

主题

486

帖子

63

蝴蝶豆

金牌会员

最后登录
2021-5-12
发表于 2018-7-25 09:18:49 | 显示全部楼层
在配置描述符和报告描述符里把单包最大字节数改成64,如果单包用不到64byte,改成你要发送的数据长度也行。

评分

参与人数 1蝴蝶豆 +3 收起 理由
zero99 + 3

查看全部评分

回复 支持 反对

使用道具 举报

该用户从未签到

22

主题

563

帖子

41

蝴蝶豆

金牌会员

最后登录
2023-9-24
 楼主| 发表于 2018-7-25 10:19:52 | 显示全部楼层
shanji 发表于 2018-7-25 09:18
在配置描述符和报告描述符里把单包最大字节数改成64,如果单包用不到64byte,改成你要发送的数据长度也行。 ...

找了半天,没找到配置描述符,和报告描述符的位置,能否明示下!!
回复 支持 反对

使用道具 举报

该用户从未签到

19

主题

954

帖子

27

蝴蝶豆

论坛元老

最后登录
2019-7-29
发表于 2018-7-25 11:45:07 | 显示全部楼层
如图,在usb_hid.c文件中
1.PNG

评分

参与人数 1蝴蝶豆 +3 收起 理由
zero99 + 3

查看全部评分

回复 支持 反对

使用道具 举报

该用户从未签到

3

主题

1306

帖子

929

蝴蝶豆

版主

最后登录
2021-3-31
发表于 2018-7-25 12:07:17 | 显示全部楼层
shanji 发表于 2018-7-25 09:18
在配置描述符和报告描述符里把单包最大字节数改成64,如果单包用不到64byte,改成你要发送的数据长度也行。 ...

漂亮
回复 支持 反对

使用道具 举报

该用户从未签到

22

主题

563

帖子

41

蝴蝶豆

金牌会员

最后登录
2023-9-24
 楼主| 发表于 2018-7-25 15:55:18 | 显示全部楼层
feiante 发表于 2018-7-25 11:45
如图,在usb_hid.c文件中

试着改了几处,还是没成功。
回复 支持 反对

使用道具 举报

该用户从未签到

22

主题

563

帖子

41

蝴蝶豆

金牌会员

最后登录
2023-9-24
 楼主| 发表于 2018-7-26 09:24:45 | 显示全部楼层
feiante 发表于 2018-7-25 11:45
如图,在usb_hid.c文件中

将配置描述符USB_HID_CONFIG_DESC_SIZ 改为0x08  仍不行
另外报告描述符是改下面这里的数据吗?
88.jpg

回复 支持 反对

使用道具 举报

该用户从未签到

0

主题

6

帖子

7

蝴蝶豆

初级会员

最后登录
2019-4-30
发表于 2018-7-27 04:00:35 | 显示全部楼层
不对。 你要改的是USBD_HID_ConfigDesc 里面End point的 wMaxPacketSize 值。
同时,要让操作系统能够理解你的这个20字节Report,HID Report Descriptor里面的HID REPORT SIZE也需要改成20字节。

评分

参与人数 1蝴蝶豆 +3 收起 理由
zero99 + 3

查看全部评分

回复 支持 反对

使用道具 举报

该用户从未签到

22

主题

563

帖子

41

蝴蝶豆

金牌会员

最后登录
2023-9-24
 楼主| 发表于 2018-7-27 14:11:01 | 显示全部楼层
imgroot 发表于 2018-7-27 04:00
不对。 你要改的是USBD_HID_ConfigDesc 里面End point的 wMaxPacketSize 值。
同时,要让操作系统能够理解 ...

1、USBD_HID_ConfigDesc 里面End point的 wMaxPacketSize 值已由0x04改为0x08
2、HID Report Descriptor里面的HID REPORT SIZE也需要改成20字节。这个更改无从下手,试改几处都不行,如将HID_MOUSE_REPORT_DESC_SIZE值由74改为78


3、我把usbd_hid.c的文件内容全部贴在下面,请知道改么改个留个言。谢谢!谢谢!
  1. /**
  2.   ******************************************************************************
  3.   * @file    usbd_hid.c
  4.   * @author  MCD Application Team
  5.   * @version V2.4.2
  6.   * @date    11-December-2015
  7.   * @brief   This file provides the HID core functions.
  8.   *
  9.   * @verbatim
  10.   *      
  11.   *          ===================================================================      
  12.   *                                HID Class  Description
  13.   *          ===================================================================
  14.   *           This module manages the HID class V1.11 following the "Device Class Definition
  15.   *           for Human Interface Devices (HID) Version 1.11 Jun 27, 2001".
  16.   *           This driver implements the following aspects of the specification:
  17.   *             - The Boot Interface Subclass
  18.   *             - The Mouse protocol
  19.   *             - Usage Page : Generic Desktop
  20.   *             - Usage : Joystick
  21.   *             - Collection : Application
  22.   *      
  23.   * @note     In HS mode and when the DMA is used, all variables and data structures
  24.   *           dealing with the DMA during the transaction process should be 32-bit aligned.
  25.   *           
  26.   *      
  27.   *  @endverbatim
  28.   *
  29.   ******************************************************************************
  30.   * @attention
  31.   *
  32.   * <h2><center>&copy; COPYRIGHT 2015 STMicroelectronics</center></h2>
  33.   *
  34.   * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
  35.   * You may not use this file except in compliance with the License.
  36.   * You may obtain a copy of the License at:
  37.   *
  38.   *        http://www.st.com/software_license_agreement_liberty_v2
  39.   *
  40.   * Unless required by applicable law or agreed to in writing, software
  41.   * distributed under the License is distributed on an "AS IS" BASIS,
  42.   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  43.   * See the License for the specific language governing permissions and
  44.   * limitations under the License.
  45.   *
  46.   ******************************************************************************
  47.   */

  48. /* Includes ------------------------------------------------------------------*/
  49. #include "usbd_hid.h"
  50. #include "usbd_desc.h"
  51. #include "usbd_ctlreq.h"


  52. /** @addtogroup STM32_USB_DEVICE_LIBRARY
  53.   * @{
  54.   */


  55. /** @defgroup USBD_HID
  56.   * @brief usbd core module
  57.   * @{
  58.   */

  59. /** @defgroup USBD_HID_Private_TypesDefinitions
  60.   * @{
  61.   */
  62. /**
  63.   * @}
  64.   */


  65. /** @defgroup USBD_HID_Private_Defines
  66.   * @{
  67.   */

  68. /**
  69.   * @}
  70.   */


  71. /** @defgroup USBD_HID_Private_Macros
  72.   * @{
  73.   */
  74. /**
  75.   * @}
  76.   */




  77. /** @defgroup USBD_HID_Private_FunctionPrototypes
  78.   * @{
  79.   */


  80. static uint8_t  USBD_HID_Init (USBD_HandleTypeDef *pdev,
  81.                                uint8_t cfgidx);

  82. static uint8_t  USBD_HID_DeInit (USBD_HandleTypeDef *pdev,
  83.                                  uint8_t cfgidx);

  84. static uint8_t  USBD_HID_Setup (USBD_HandleTypeDef *pdev,
  85.                                 USBD_SetupReqTypedef *req);

  86. static uint8_t  *USBD_HID_GetCfgDesc (uint16_t *length);

  87. static uint8_t  *USBD_HID_GetDeviceQualifierDesc (uint16_t *length);

  88. static uint8_t  USBD_HID_DataIn (USBD_HandleTypeDef *pdev, uint8_t epnum);
  89. /**
  90.   * @}
  91.   */

  92. /** @defgroup USBD_HID_Private_Variables
  93.   * @{
  94.   */

  95. USBD_ClassTypeDef  USBD_HID =
  96. {
  97.   USBD_HID_Init,
  98.   USBD_HID_DeInit,
  99.   USBD_HID_Setup,
  100.   NULL, /*EP0_TxSent*/  
  101.   NULL, /*EP0_RxReady*/
  102.   USBD_HID_DataIn, /*DataIn*/
  103.   NULL, /*DataOut*/
  104.   NULL, /*SOF */
  105.   NULL,
  106.   NULL,      
  107.   USBD_HID_GetCfgDesc,
  108.   USBD_HID_GetCfgDesc,
  109.   USBD_HID_GetCfgDesc,
  110.   USBD_HID_GetDeviceQualifierDesc,
  111. };

  112. /* USB HID device Configuration Descriptor */
  113. __ALIGN_BEGIN static uint8_t USBD_HID_CfgDesc[USB_HID_CONFIG_DESC_SIZ]  __ALIGN_END =
  114. {
  115.   0x09, /* bLength: Configuration Descriptor size */
  116.   USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType: Configuration */
  117.   USB_HID_CONFIG_DESC_SIZ,
  118.   /* wTotalLength: Bytes returned */
  119.   0x00,
  120.   0x01,         /*bNumInterfaces: 1 interface*/
  121.   0x01,         /*bConfigurationValue: Configuration value*/
  122.   0x00,         /*iConfiguration: Index of string descriptor describing
  123.   the configuration*/
  124.   0xE0,         /*bmAttributes: bus powered and Support Remote Wake-up */
  125.   0x32,         /*MaxPower 100 mA: this current is used for detecting Vbus*/
  126.   
  127.   /************** Descriptor of Joystick Mouse interface ****************/
  128.   /* 09 */
  129.   0x09,         /*bLength: Interface Descriptor size*/
  130.   USB_DESC_TYPE_INTERFACE,/*bDescriptorType: Interface descriptor type*/
  131.   0x00,         /*bInterfaceNumber: Number of Interface*/
  132.   0x00,         /*bAlternateSetting: Alternate setting*/
  133.   0x01,         /*bNumEndpoints*/
  134.   0x03,         /*bInterfaceClass: HID*/
  135.   0x01,         /*bInterfaceSubClass : 1=BOOT, 0=no boot*/
  136.   0x02,         /*nInterfaceProtocol : 0=none, 1=keyboard, 2=mouse*/
  137.   0,            /*iInterface: Index of string descriptor*/
  138.   /******************** Descriptor of Joystick Mouse HID ********************/
  139.   /* 18 */
  140.   0x09,         /*bLength: HID Descriptor size*/
  141.   HID_DESCRIPTOR_TYPE, /*bDescriptorType: HID*/
  142.   0x11,         /*bcdHID: HID Class Spec release number*/
  143.   0x01,
  144.   0x00,         /*bCountryCode: Hardware target country*/
  145.   0x01,         /*bNumDescriptors: Number of HID class descriptors to follow*/
  146.   0x22,         /*bDescriptorType*/
  147.   HID_MOUSE_REPORT_DESC_SIZE,/*wItemLength: Total length of Report descriptor*/
  148.   0x00,
  149.   /******************** Descriptor of Mouse endpoint ********************/
  150.   /* 27 */
  151.   0x07,          /*bLength: Endpoint Descriptor size*/
  152.   USB_DESC_TYPE_ENDPOINT, /*bDescriptorType:*/
  153.   
  154.   HID_EPIN_ADDR,     /*bEndpointAddress: Endpoint Address (IN)*/
  155.   0x03,          /*bmAttributes: Interrupt endpoint*/
  156.   HID_EPIN_SIZE, /*wMaxPacketSize: 4 Byte max */
  157.   0x00,
  158.   HID_FS_BINTERVAL,          /*bInterval: Polling Interval (10 ms)*/
  159.   /* 34 */
  160. } ;

  161. /* USB HID device Configuration Descriptor */
  162. __ALIGN_BEGIN static uint8_t USBD_HID_Desc[USB_HID_DESC_SIZ]  __ALIGN_END  =
  163. {
  164.   /* 18 */
  165.   0x09,         /*bLength: HID Descriptor size*/
  166.   HID_DESCRIPTOR_TYPE, /*bDescriptorType: HID*/
  167.   0x11,         /*bcdHID: HID Class Spec release number*/
  168.   0x01,
  169.   0x00,         /*bCountryCode: Hardware target country*/
  170.   0x01,         /*bNumDescriptors: Number of HID class descriptors to follow*/
  171.   0x22,         /*bDescriptorType*/
  172.   HID_MOUSE_REPORT_DESC_SIZE,/*wItemLength: Total length of Report descriptor*/
  173.   0x00,
  174. };

  175. /* USB Standard Device Descriptor */
  176. __ALIGN_BEGIN static uint8_t USBD_HID_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_DESC]  __ALIGN_END =
  177. {
  178.   USB_LEN_DEV_QUALIFIER_DESC,
  179.   USB_DESC_TYPE_DEVICE_QUALIFIER,
  180.   0x00,
  181.   0x02,
  182.   0x00,
  183.   0x00,
  184.   0x00,
  185.   0x40,
  186.   0x01,
  187.   0x00,
  188. };

  189. __ALIGN_BEGIN static uint8_t HID_MOUSE_ReportDesc[HID_MOUSE_REPORT_DESC_SIZE]  __ALIGN_END =
  190. {
  191.   0x05,   0x01,
  192.   0x09,   0x02,
  193.   0xA1,   0x01,
  194.   0x09,   0x01,
  195.   
  196.   0xA1,   0x00,
  197.   0x05,   0x09,
  198.   0x19,   0x01,
  199.   0x29,   0x03,
  200.   
  201.   0x15,   0x00,
  202.   0x25,   0x01,
  203.   0x95,   0x03,
  204.   0x75,   0x01,
  205.   
  206.   0x81,   0x02,
  207.   0x95,   0x01,
  208.   0x75,   0x05,
  209.   0x81,   0x01,
  210.   
  211.   0x05,   0x01,
  212.   0x09,   0x30,
  213.   0x09,   0x31,
  214.   0x09,   0x38,
  215.   
  216.   0x15,   0x81,
  217.   0x25,   0x7F,
  218.   0x75,   0x08,
  219.   0x95,   0x03,
  220.   
  221.   0x81,   0x06,
  222.   0xC0,   0x09,
  223.   0x3c,   0x05,
  224.   0xff,   0x09,
  225.   
  226.   0x01,   0x15,
  227.   0x00,   0x25,
  228.   0x01,   0x75,
  229.   0x01,   0x95,
  230.   
  231.   0x02,   0xb1,
  232.   0x22,   0x75,
  233.   0x06,   0x95,
  234.   0x01,   0xb1,
  235. //  0x06,   0x95,//
  236. //  0x01,   0xb1,//
  237.   
  238.   0x01,   0xc0
  239. };

  240. /**
  241.   * @}
  242.   */

  243. /** @defgroup USBD_HID_Private_Functions
  244.   * @{
  245.   */

  246. /**
  247.   * @brief  USBD_HID_Init
  248.   *         Initialize the HID interface
  249.   * @param  pdev: device instance
  250.   * @param  cfgidx: Configuration index
  251.   * @retval status
  252.   */
  253. static uint8_t  USBD_HID_Init (USBD_HandleTypeDef *pdev,
  254.                                uint8_t cfgidx)
  255. {
  256.   uint8_t ret = 0;
  257.   
  258.   /* Open EP IN */
  259.   USBD_LL_OpenEP(pdev,
  260.                  HID_EPIN_ADDR,
  261.                  USBD_EP_TYPE_INTR,
  262.                  HID_EPIN_SIZE);  
  263.   
  264.   pdev->pClassData = USBD_malloc(sizeof (USBD_HID_HandleTypeDef));
  265.   
  266.   if(pdev->pClassData == NULL)
  267.   {
  268.     ret = 1;
  269.   }
  270.   else
  271.   {
  272.     ((USBD_HID_HandleTypeDef *)pdev->pClassData)->state = HID_IDLE;
  273.   }
  274.   return ret;
  275. }

  276. /**
  277.   * @brief  USBD_HID_Init
  278.   *         DeInitialize the HID layer
  279.   * @param  pdev: device instance
  280.   * @param  cfgidx: Configuration index
  281.   * @retval status
  282.   */
  283. static uint8_t  USBD_HID_DeInit (USBD_HandleTypeDef *pdev,
  284.                                  uint8_t cfgidx)
  285. {
  286.   /* Close HID EPs */
  287.   USBD_LL_CloseEP(pdev,
  288.                   HID_EPIN_ADDR);
  289.   
  290.   /* FRee allocated memory */
  291.   if(pdev->pClassData != NULL)
  292.   {
  293.     USBD_free(pdev->pClassData);
  294.     pdev->pClassData = NULL;
  295.   }
  296.   
  297.   return USBD_OK;
  298. }

  299. /**
  300.   * @brief  USBD_HID_Setup
  301.   *         Handle the HID specific requests
  302.   * @param  pdev: instance
  303.   * @param  req: usb requests
  304.   * @retval status
  305.   */
  306. static uint8_t  USBD_HID_Setup (USBD_HandleTypeDef *pdev,
  307.                                 USBD_SetupReqTypedef *req)
  308. {
  309.   uint16_t len = 0;
  310.   uint8_t  *pbuf = NULL;
  311.   USBD_HID_HandleTypeDef     *hhid = (USBD_HID_HandleTypeDef*) pdev->pClassData;
  312.   
  313.   switch (req->bmRequest & USB_REQ_TYPE_MASK)
  314.   {
  315.   case USB_REQ_TYPE_CLASS :  
  316.     switch (req->bRequest)
  317.     {
  318.       
  319.       
  320.     case HID_REQ_SET_PROTOCOL:
  321.       hhid->Protocol = (uint8_t)(req->wValue);
  322.       break;
  323.       
  324.     case HID_REQ_GET_PROTOCOL:
  325.       USBD_CtlSendData (pdev,
  326.                         (uint8_t *)&hhid->Protocol,
  327.                         1);   
  328.       break;
  329.       
  330.     case HID_REQ_SET_IDLE:
  331.       hhid->IdleState = (uint8_t)(req->wValue >> 8);
  332.       break;
  333.       
  334.     case HID_REQ_GET_IDLE:
  335.       USBD_CtlSendData (pdev,
  336.                         (uint8_t *)&hhid->IdleState,
  337.                         1);        
  338.       break;      
  339.       
  340.     default:
  341.       USBD_CtlError (pdev, req);
  342.       return USBD_FAIL;
  343.     }
  344.     break;
  345.    
  346.   case USB_REQ_TYPE_STANDARD:
  347.     switch (req->bRequest)
  348.     {
  349.     case USB_REQ_GET_DESCRIPTOR:
  350.       if( req->wValue >> 8 == HID_REPORT_DESC)
  351.       {
  352.         len = MIN(HID_MOUSE_REPORT_DESC_SIZE , req->wLength);
  353.         pbuf = HID_MOUSE_ReportDesc;
  354.       }
  355.       else if( req->wValue >> 8 == HID_DESCRIPTOR_TYPE)
  356.       {
  357.         pbuf = USBD_HID_Desc;   
  358.         len = MIN(USB_HID_DESC_SIZ , req->wLength);
  359.       }
  360.       
  361.       USBD_CtlSendData (pdev,
  362.                         pbuf,
  363.                         len);
  364.       
  365.       break;
  366.       
  367.     case USB_REQ_GET_INTERFACE :
  368.       USBD_CtlSendData (pdev,
  369.                         (uint8_t *)&hhid->AltSetting,
  370.                         1);
  371.       break;
  372.       
  373.     case USB_REQ_SET_INTERFACE :
  374.       hhid->AltSetting = (uint8_t)(req->wValue);
  375.       break;
  376.     }
  377.   }
  378.   return USBD_OK;
  379. }

  380. /**
  381.   * @brief  USBD_HID_SendReport
  382.   *         Send HID Report
  383.   * @param  pdev: device instance
  384.   * @param  buff: pointer to report
  385.   * @retval status
  386.   */
  387. uint8_t USBD_HID_SendReport     (USBD_HandleTypeDef  *pdev,
  388.                                  uint8_t *report,
  389.                                  uint16_t len)
  390. {
  391.   USBD_HID_HandleTypeDef     *hhid = (USBD_HID_HandleTypeDef*)pdev->pClassData;
  392.   
  393.   if (pdev->dev_state == USBD_STATE_CONFIGURED )
  394.   {
  395.     if(hhid->state == HID_IDLE)
  396.     {
  397.       hhid->state = HID_BUSY;
  398.       USBD_LL_Transmit (pdev,
  399.                         HID_EPIN_ADDR,                                      
  400.                         report,
  401.                         len);
  402.     }
  403.   }
  404.   return USBD_OK;
  405. }

  406. /**
  407.   * @brief  USBD_HID_GetPollingInterval
  408.   *         return polling interval from endpoint descriptor
  409.   * @param  pdev: device instance
  410.   * @retval polling interval
  411.   */
  412. uint32_t USBD_HID_GetPollingInterval (USBD_HandleTypeDef *pdev)
  413. {
  414.   uint32_t polling_interval = 0;

  415.   /* HIGH-speed endpoints */
  416.   if(pdev->dev_speed == USBD_SPEED_HIGH)
  417.   {
  418.    /* Sets the data transfer polling interval for high speed transfers.
  419.     Values between 1..16 are allowed. Values correspond to interval
  420.     of 2 ^ (bInterval-1). This option (8 ms, corresponds to HID_HS_BINTERVAL */
  421.     polling_interval = (((1 <<(HID_HS_BINTERVAL - 1)))/8);
  422.   }
  423.   else   /* LOW and FULL-speed endpoints */
  424.   {
  425.     /* Sets the data transfer polling interval for low and full
  426.     speed transfers */
  427.     polling_interval =  HID_FS_BINTERVAL;
  428.   }
  429.   
  430.   return ((uint32_t)(polling_interval));
  431. }

  432. /**
  433.   * @brief  USBD_HID_GetCfgDesc
  434.   *         return configuration descriptor
  435.   * @param  speed : current device speed
  436.   * @param  length : pointer data length
  437.   * @retval pointer to descriptor buffer
  438.   */
  439. static uint8_t  *USBD_HID_GetCfgDesc (uint16_t *length)
  440. {
  441.   *length = sizeof (USBD_HID_CfgDesc);
  442.   return USBD_HID_CfgDesc;
  443. }


  444. /**
  445.   * @brief  USBD_HID_DataIn
  446.   *         handle data IN Stage
  447.   * @param  pdev: device instance
  448.   * @param  epnum: endpoint index
  449.   * @retval status
  450.   */
  451. static uint8_t  USBD_HID_DataIn (USBD_HandleTypeDef *pdev,
  452.                               uint8_t epnum)
  453. {
  454.   
  455.   /* Ensure that the FIFO is empty before a new transfer, this condition could
  456.   be caused by  a new transfer before the end of the previous transfer */
  457.   ((USBD_HID_HandleTypeDef *)pdev->pClassData)->state = HID_IDLE;
  458.   return USBD_OK;
  459. }


  460. /**
  461. * @brief  DeviceQualifierDescriptor
  462. *         return Device Qualifier descriptor
  463. * @param  length : pointer data length
  464. * @retval pointer to descriptor buffer
  465. */
  466. static uint8_t  *USBD_HID_GetDeviceQualifierDesc (uint16_t *length)
  467. {
  468.   *length = sizeof (USBD_HID_DeviceQualifierDesc);
  469.   return USBD_HID_DeviceQualifierDesc;
  470. }

  471. /**
  472.   * @}
  473.   */


  474. /**
  475.   * @}
  476.   */


  477. /**
  478.   * @}
  479.   */

  480. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
复制代码
回复 支持 反对

使用道具 举报

该用户从未签到

22

主题

563

帖子

41

蝴蝶豆

金牌会员

最后登录
2023-9-24
 楼主| 发表于 2018-7-27 14:24:44 | 显示全部楼层
1、USBD_HID_ConfigDesc 里面End point的 wMaxPacketSize 值已由0x04改0x08,此值前期改过不管用,可能是只改这一处的原因。

2、Report,HID Report Descriptor里面的HID REPORT SIZE也需要改成20字节。
这条不知怎么下手,试改了几处仍不行,如改过HID_MOUSE_REPORT_DESC_SIZE,值由74改为78,但仍不行 99.jpg
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 注册/登录

本版积分规则

关闭

站长推荐上一条 /3 下一条

Archiver|手机版|小黑屋|论坛-意法半导体STM32/STM8技术社区

GMT+8, 2024-4-26 06:52 , Processed in 1.203739 second(s), 49 queries .

Powered by Discuz! X3.4

Copyright © 2001-2024, Tencent Cloud.

快速回复 返回顶部 返回列表