使用开发板为正点原子ministm32

现在我们先使用HID descriptor Tool来生成我们需要的hid的

保存使用选择.H

  1. // D:\usb资料\HID\MSDEV\Projects\test\Desc_HID.h
  2.  
  3. char ReportDescriptor[] = {
  4. 0x06, 0x00, 0xff, // USAGE_PAGE (Vendor Defined Page 1)
  5. 0x09, 0x01, // USAGE (Vendor Usage 1)
  6. 0xa1, 0x01, // COLLECTION (Application)
  7. 0x09, 0x01, // USAGE (Vendor Usage 1)
  8. 0x15, 0x00, // LOGICAL_MINIMUM (0)
  9. 0x26, 0xff, 0x00, // LOGICAL_MAXIMUM (255)
  10. 0x95, 0x40, // REPORT_COUNT (64)
  11. 0x75, 0x08, // REPORT_SIZE (8)
  12. 0x81, 0x02, // INPUT (Data,Var,Abs)
  13. 0x09, 0x01, // USAGE (Vendor Usage 1)
  14. 0x15, 0x00, // LOGICAL_MINIMUM (0)
  15. 0x26, 0xff, 0x00, // LOGICAL_MAXIMUM (255)
  16. 0x95, 0x40, // REPORT_COUNT (64)
  17. 0x75, 0x08, // REPORT_SIZE (8)
  18. 0x91, 0x02, // OUTPUT (Data,Var,Abs)
  19. 0xc0 // END_COLLECTION
  20. };

现在使用使用STM32CubeMX来生成我们的工程

将char ReportDescriptor[34] 修改工程中CUSTOM_HID_ReportDesc_FS[USBD_CUSTOM_HID_REPORT_DESC_SIZE]

  1. /** @defgroup USBD_AUDIO_IF_Private_Variables
  2. * @{
  3. */
  4. __ALIGN_BEGIN static uint8_t CUSTOM_HID_ReportDesc_FS[USBD_CUSTOM_HID_REPORT_DESC_SIZE] __ALIGN_END =
  5. {
  6. /* USER CODE BEGIN 0 */
  7. 0x06, 0x00, 0xff, // USAGE_PAGE (Vendor Defined Page 1)
  8. 0x09, 0x01, // USAGE (Vendor Usage 1)
  9. 0xa1, 0x01, // COLLECTION (Application)
  10. 0x09, 0x01, // USAGE (Vendor Usage 1)
  11. 0x15, 0x00, // LOGICAL_MINIMUM (0)
  12. 0x26, 0xff, 0x00, // LOGICAL_MAXIMUM (255)
  13. 0x95, 0x40, // REPORT_COUNT (64)
  14. 0x75, 0x08, // REPORT_SIZE (8)
  15. 0x81, 0x02, // INPUT (Data,Var,Abs)
  16. 0x09, 0x01, // USAGE (Vendor Usage 1)
  17. 0x15, 0x00, // LOGICAL_MINIMUM (0)
  18. 0x26, 0xff, 0x00, // LOGICAL_MAXIMUM (255)
  19. 0x95, 0x40, // REPORT_COUNT (64)
  20. 0x75, 0x08, // REPORT_SIZE (8)
  21. 0x91, 0x02, // OUTPUT (Data,Var,Abs)
  22. /* USER CODE END 0 */
  23. 0xC0 /* END_COLLECTION */
  24.  
  25. };
  26.  
  27. /* USER CODE BEGIN PRIVATE_VARIABLES */
  28. /* USER CODE END PRIVATE_VARIABLES */
  29. /**
  30. * @}
  31. */

现在编译下载测试

先使用USBlyzer来看看

现在继续修改我们代码增加发送PC数据

  1. /**
  2. ******************************************************************************
  3. * File Name : main.c
  4. * Description : Main program body
  5. ******************************************************************************
  6. * This notice applies to any and all portions of this file
  7. * that are not between comment pairs USER CODE BEGIN and
  8. * USER CODE END. Other portions of this file, whether
  9. * inserted by the user or by software development tools
  10. * are owned by their respective copyright owners.
  11. *
  12. * Copyright (c) 2017 STMicroelectronics International N.V.
  13. * All rights reserved.
  14. *
  15. * Redistribution and use in source and binary forms, with or without
  16. * modification, are permitted, provided that the following conditions are met:
  17. *
  18. * 1. Redistribution of source code must retain the above copyright notice,
  19. * this list of conditions and the following disclaimer.
  20. * 2. Redistributions in binary form must reproduce the above copyright notice,
  21. * this list of conditions and the following disclaimer in the documentation
  22. * and/or other materials provided with the distribution.
  23. * 3. Neither the name of STMicroelectronics nor the names of other
  24. * contributors to this software may be used to endorse or promote products
  25. * derived from this software without specific written permission.
  26. * 4. This software, including modifications and/or derivative works of this
  27. * software, must execute solely and exclusively on microcontroller or
  28. * microprocessor devices manufactured by or for STMicroelectronics.
  29. * 5. Redistribution and use of this software other than as permitted under
  30. * this license is void and will automatically terminate your rights under
  31. * this license.
  32. *
  33. * THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS"
  34. * AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT
  35. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  36. * PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY
  37. * RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT
  38. * SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  39. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  40. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  41. * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  42. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  43. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  44. * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  45. *
  46. ******************************************************************************
  47. */
  48. /* Includes ------------------------------------------------------------------*/
  49. #include "main.h"
  50. #include "stm32f1xx_hal.h"
  51. #include "usb_device.h"
  52.  
  53. /* USER CODE BEGIN Includes */
  54. #include "usbd_customhid.h"
  55. /* USER CODE END Includes */
  56.  
  57. /* Private variables ---------------------------------------------------------*/
  58.  
  59. /* USER CODE BEGIN PV */
  60. /* Private variables ---------------------------------------------------------*/
  61. extern USBD_HandleTypeDef hUsbDeviceFS;
  62. /* USER CODE END PV */
  63.  
  64. /* Private function prototypes -----------------------------------------------*/
  65. void SystemClock_Config(void);
  66. static void MX_GPIO_Init(void);
  67.  
  68. /* USER CODE BEGIN PFP */
  69. /* Private function prototypes -----------------------------------------------*/
  70.  
  71. /* USER CODE END PFP */
  72.  
  73. /* USER CODE BEGIN 0 */
  74.  
  75. /* USER CODE END 0 */
  76.  
  77. int main(void)
  78. {
  79.  
  80. /* USER CODE BEGIN 1 */
  81. uint8_t send_buf[64] = {0};
  82. uint8_t i;
  83. /* USER CODE END 1 */
  84.  
  85. /* MCU Configuration----------------------------------------------------------*/
  86.  
  87. /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  88. HAL_Init();
  89.  
  90. /* USER CODE BEGIN Init */
  91.  
  92. /* USER CODE END Init */
  93.  
  94. /* Configure the system clock */
  95. SystemClock_Config();
  96.  
  97. /* USER CODE BEGIN SysInit */
  98.  
  99. /* USER CODE END SysInit */
  100.  
  101. /* Initialize all configured peripherals */
  102. MX_GPIO_Init();
  103. MX_USB_DEVICE_Init();
  104.  
  105. /* USER CODE BEGIN 2 */
  106.  
  107. for(i=0;i<64;i++)
  108. {
  109. send_buf[i] = i;
  110. }
  111. /* USER CODE END 2 */
  112.  
  113. /* Infinite loop */
  114. /* USER CODE BEGIN WHILE */
  115. while ()
  116. {
  117. /* USER CODE END WHILE */
  118.  
  119. /* USER CODE BEGIN 3 */
  120. USBD_CUSTOM_HID_SendReport(&hUsbDeviceFS, send_buf, 64);
  121. send_buf[0]++;
  122. HAL_Delay(2000);
  123. }
  124. /* USER CODE END 3 */
  125.  
  126. }
  127.  
  128. /** System Clock Configuration
  129. */
  130. void SystemClock_Config(void)
  131. {
  132.  
  133. RCC_OscInitTypeDef RCC_OscInitStruct;
  134. RCC_ClkInitTypeDef RCC_ClkInitStruct;
  135. RCC_PeriphCLKInitTypeDef PeriphClkInit;
  136.  
  137. /**Initializes the CPU, AHB and APB busses clocks
  138. */
  139. RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
  140. RCC_OscInitStruct.HSEState = RCC_HSE_ON;
  141. RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
  142. RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  143. RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  144. RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  145. RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9;
  146. if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  147. {
  148. _Error_Handler(__FILE__, __LINE__);
  149. }
  150.  
  151. /**Initializes the CPU, AHB and APB busses clocks
  152. */
  153. RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
  154. |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  155. RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  156. RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  157. RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
  158. RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
  159.  
  160. if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
  161. {
  162. _Error_Handler(__FILE__, __LINE__);
  163. }
  164.  
  165. PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USB;
  166. PeriphClkInit.UsbClockSelection = RCC_USBCLKSOURCE_PLL_DIV1_5;
  167. if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
  168. {
  169. _Error_Handler(__FILE__, __LINE__);
  170. }
  171.  
  172. /**Configure the Systick interrupt time
  173. */
  174. HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/);
  175.  
  176. /**Configure the Systick
  177. */
  178. HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
  179.  
  180. /* SysTick_IRQn interrupt configuration */
  181. HAL_NVIC_SetPriority(SysTick_IRQn, , );
  182. }
  183.  
  184. /** Configure pins as
  185. * Analog
  186. * Input
  187. * Output
  188. * EVENT_OUT
  189. * EXTI
  190. */
  191. static void MX_GPIO_Init(void)
  192. {
  193.  
  194. /* GPIO Ports Clock Enable */
  195. __HAL_RCC_GPIOC_CLK_ENABLE();
  196. __HAL_RCC_GPIOD_CLK_ENABLE();
  197. __HAL_RCC_GPIOA_CLK_ENABLE();
  198.  
  199. }
  200.  
  201. /* USER CODE BEGIN 4 */
  202.  
  203. /* USER CODE END 4 */
  204.  
  205. /**
  206. * @brief This function is executed in case of error occurrence.
  207. * @param None
  208. * @retval None
  209. */
  210. void _Error_Handler(char * file, int line)
  211. {
  212. /* USER CODE BEGIN Error_Handler_Debug */
  213. /* User can add his own implementation to report the HAL error return state */
  214. while()
  215. {
  216. }
  217. /* USER CODE END Error_Handler_Debug */
  218. }
  219.  
  220. #ifdef USE_FULL_ASSERT
  221.  
  222. /**
  223. * @brief Reports the name of the source file and the source line number
  224. * where the assert_param error has occurred.
  225. * @param file: pointer to the source file name
  226. * @param line: assert_param error line source number
  227. * @retval None
  228. */
  229. void assert_failed(uint8_t* file, uint32_t line)
  230. {
  231. /* USER CODE BEGIN 6 */
  232. /* User can add his own implementation to report the file name and line number,
  233. ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  234. /* USER CODE END 6 */
  235.  
  236. }
  237.  
  238. #endif
  239.  
  240. /**
  241. * @}
  242. */
  243.  
  244. /**
  245. * @}
  246. */
  247.  
  248. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

可以看到下面的数据在变化

bus hound的设置如下

现在使用bus hound发送数据到MCU

现在修改一下工程代码

注释掉main.C中的

//    USBD_CUSTOM_HID_SendReport(&hUsbDeviceFS, &send_buf[0],64);
//    send_buf[0]++;
//    HAL_Delay(2000);

  1. /**
  2. ******************************************************************************
  3. * File Name : main.c
  4. * Description : Main program body
  5. ******************************************************************************
  6. * This notice applies to any and all portions of this file
  7. * that are not between comment pairs USER CODE BEGIN and
  8. * USER CODE END. Other portions of this file, whether
  9. * inserted by the user or by software development tools
  10. * are owned by their respective copyright owners.
  11. *
  12. * Copyright (c) 2017 STMicroelectronics International N.V.
  13. * All rights reserved.
  14. *
  15. * Redistribution and use in source and binary forms, with or without
  16. * modification, are permitted, provided that the following conditions are met:
  17. *
  18. * 1. Redistribution of source code must retain the above copyright notice,
  19. * this list of conditions and the following disclaimer.
  20. * 2. Redistributions in binary form must reproduce the above copyright notice,
  21. * this list of conditions and the following disclaimer in the documentation
  22. * and/or other materials provided with the distribution.
  23. * 3. Neither the name of STMicroelectronics nor the names of other
  24. * contributors to this software may be used to endorse or promote products
  25. * derived from this software without specific written permission.
  26. * 4. This software, including modifications and/or derivative works of this
  27. * software, must execute solely and exclusively on microcontroller or
  28. * microprocessor devices manufactured by or for STMicroelectronics.
  29. * 5. Redistribution and use of this software other than as permitted under
  30. * this license is void and will automatically terminate your rights under
  31. * this license.
  32. *
  33. * THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS"
  34. * AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT
  35. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  36. * PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY
  37. * RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT
  38. * SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  39. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  40. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  41. * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  42. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  43. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  44. * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  45. *
  46. ******************************************************************************
  47. */
  48. /* Includes ------------------------------------------------------------------*/
  49. #include "main.h"
  50. #include "stm32f1xx_hal.h"
  51. #include "usb_device.h"
  52.  
  53. /* USER CODE BEGIN Includes */
  54. #include "usbd_customhid.h"
  55. /* USER CODE END Includes */
  56.  
  57. /* Private variables ---------------------------------------------------------*/
  58.  
  59. /* USER CODE BEGIN PV */
  60. /* Private variables ---------------------------------------------------------*/
  61. extern USBD_HandleTypeDef hUsbDeviceFS;
  62. /* USER CODE END PV */
  63.  
  64. /* Private function prototypes -----------------------------------------------*/
  65. void SystemClock_Config(void);
  66. static void MX_GPIO_Init(void);
  67.  
  68. /* USER CODE BEGIN PFP */
  69. /* Private function prototypes -----------------------------------------------*/
  70.  
  71. /* USER CODE END PFP */
  72.  
  73. /* USER CODE BEGIN 0 */
  74.  
  75. /* USER CODE END 0 */
  76.  
  77. int main(void)
  78. {
  79.  
  80. /* USER CODE BEGIN 1 */
  81. uint8_t send_buf[] = {0XFF};
  82. uint8_t i;
  83. /* USER CODE END 1 */
  84.  
  85. /* MCU Configuration----------------------------------------------------------*/
  86.  
  87. /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  88. HAL_Init();
  89.  
  90. /* USER CODE BEGIN Init */
  91.  
  92. /* USER CODE END Init */
  93.  
  94. /* Configure the system clock */
  95. SystemClock_Config();
  96.  
  97. /* USER CODE BEGIN SysInit */
  98.  
  99. /* USER CODE END SysInit */
  100.  
  101. /* Initialize all configured peripherals */
  102. MX_GPIO_Init();
  103. MX_USB_DEVICE_Init();
  104.  
  105. /* USER CODE BEGIN 2 */
  106.  
  107. for(i=;i<;i++)
  108. {
  109. send_buf[i] = i;
  110. }
  111. /* USER CODE END 2 */
  112.  
  113. /* Infinite loop */
  114. /* USER CODE BEGIN WHILE */
  115. while ()
  116. {
  117. /* USER CODE END WHILE */
  118.  
  119. /* USER CODE BEGIN 3 */
  120.  
  121. // USBD_CUSTOM_HID_SendReport(&hUsbDeviceFS, &send_buf[0],64);
  122. // send_buf[0]++;
  123. // HAL_Delay(2000);
  124. }
  125. /* USER CODE END 3 */
  126.  
  127. }
  128.  
  129. /** System Clock Configuration
  130. */
  131. void SystemClock_Config(void)
  132. {
  133.  
  134. RCC_OscInitTypeDef RCC_OscInitStruct;
  135. RCC_ClkInitTypeDef RCC_ClkInitStruct;
  136. RCC_PeriphCLKInitTypeDef PeriphClkInit;
  137.  
  138. /**Initializes the CPU, AHB and APB busses clocks
  139. */
  140. RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
  141. RCC_OscInitStruct.HSEState = RCC_HSE_ON;
  142. RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
  143. RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  144. RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  145. RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  146. RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9;
  147. if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  148. {
  149. _Error_Handler(__FILE__, __LINE__);
  150. }
  151.  
  152. /**Initializes the CPU, AHB and APB busses clocks
  153. */
  154. RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
  155. |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  156. RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  157. RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  158. RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
  159. RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
  160.  
  161. if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
  162. {
  163. _Error_Handler(__FILE__, __LINE__);
  164. }
  165.  
  166. PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USB;
  167. PeriphClkInit.UsbClockSelection = RCC_USBCLKSOURCE_PLL_DIV1_5;
  168. if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
  169. {
  170. _Error_Handler(__FILE__, __LINE__);
  171. }
  172.  
  173. /**Configure the Systick interrupt time
  174. */
  175. HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/);
  176.  
  177. /**Configure the Systick
  178. */
  179. HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
  180.  
  181. /* SysTick_IRQn interrupt configuration */
  182. HAL_NVIC_SetPriority(SysTick_IRQn, , );
  183. }
  184.  
  185. /** Configure pins as
  186. * Analog
  187. * Input
  188. * Output
  189. * EVENT_OUT
  190. * EXTI
  191. */
  192. static void MX_GPIO_Init(void)
  193. {
  194.  
  195. /* GPIO Ports Clock Enable */
  196. __HAL_RCC_GPIOC_CLK_ENABLE();
  197. __HAL_RCC_GPIOD_CLK_ENABLE();
  198. __HAL_RCC_GPIOA_CLK_ENABLE();
  199.  
  200. }
  201.  
  202. /* USER CODE BEGIN 4 */
  203.  
  204. /* USER CODE END 4 */
  205.  
  206. /**
  207. * @brief This function is executed in case of error occurrence.
  208. * @param None
  209. * @retval None
  210. */
  211. void _Error_Handler(char * file, int line)
  212. {
  213. /* USER CODE BEGIN Error_Handler_Debug */
  214. /* User can add his own implementation to report the HAL error return state */
  215. while()
  216. {
  217. }
  218. /* USER CODE END Error_Handler_Debug */
  219. }
  220.  
  221. #ifdef USE_FULL_ASSERT
  222.  
  223. /**
  224. * @brief Reports the name of the source file and the source line number
  225. * where the assert_param error has occurred.
  226. * @param file: pointer to the source file name
  227. * @param line: assert_param error line source number
  228. * @retval None
  229. */
  230. void assert_failed(uint8_t* file, uint32_t line)
  231. {
  232. /* USER CODE BEGIN 6 */
  233. /* User can add his own implementation to report the file name and line number,
  234. ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  235. /* USER CODE END 6 */
  236.  
  237. }
  238.  
  239. #endif
  240.  
  241. /**
  242. * @}
  243. */
  244.  
  245. /**
  246. * @}
  247. */
  248.  
  249. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

修改在usbd_custom_hid_if.c

  1. /**
  2. * @brief CUSTOM_HID_OutEvent_FS
  3. * Manage the CUSTOM HID class events
  4. * @param event_idx: event index
  5. * @param state: event state
  6. * @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
  7. */
  8. static int8_t CUSTOM_HID_OutEvent_FS (uint8_t event_idx, uint8_t state)
  9. {
  10. /* USER CODE BEGIN 6 */
  11. USBD_CUSTOM_HID_HandleTypeDef *hhid = hUsbDeviceFS.pClassData;
  12.  
  13. USBD_CUSTOM_HID_SendReport(&hUsbDeviceFS, hhid->Report_buf,);
  14. return ();
  15. /* USER CODE END 6 */
  16. }

好了测试一下

 存在一个问题当PC发送不是64位时怎么处理??未解决

后面找到一些资料: 所有的 HID 数据都必须使用定义过的报表格式来定义报表中数据的大小与内容。设备可
以支持一个或多个报表。在固件中的报表描述符用来描述了此报表,以及如何使用报表数据的
信息。

利用STM32CubeMX生成HID双向通讯工程的更多相关文章

  1. 利用STM32CubeMX来生成USB_HID_Mouse工程【添加ADC】(1)

    现在原来的基础上添加ADC的功能. 现在(利用STM32CubeMX来生成USB_HID_Mouse工程)基础上新增硬件 JoyStick Shield 游戏摇杆扩展板 与STM32F103C8的连接 ...

  2. 利用STM32CubeMX来生成USB_HID_Mouse工程

    硬件开发板:STM32F103C8 软件平台 好了现在开始利用STM32CubeMX来生成我们的工程 1.新建工程 选择MCU的型号 选择选择时钟 开启usb的模块 选择USB的类 配置时钟树(主要是 ...

  3. 使用STM32CubeMX生成USB_HOST_HID工程[添加对CAPS_LOCK指示灯的控制][SetReport]

    在之前(使用STM32CubeMX生成USB_HOST_HID工程)的基础上进行修改 在结合之前在pc上的测试 USB之HID类Set_Report Request[调试手记1] 测试代码如下: /* ...

  4. 使用STM32CubeMX生成RTC工程[闹钟中断2]

    在上次使用STM32CubeMX生成RTC工程[闹钟中断]基础上实现周期间隔的闹钟 一些场合需要周期性的闹钟 现在为了方便设置每十秒来一次. 备注: 当然可以直接修改HAL库static HAL_St ...

  5. 重温WCF之数单向通讯、双向通讯、回调操作(五)

    一.单向通讯单向操作不等同于异步操作,单向操作只是在发出调用的瞬间阻塞客户端,但如果发出多个单向调用,WCF会将请求调用放入到服务器端的队列中,并在某个时间进行执行.队列的存储个数有限,一旦发出的调用 ...

  6. silverlight与wcf双向通讯 例子

    本文将建立一个silverlight与wcf双向通讯的简单实例,以下是详细步骤: 新建Silverlight应用程序,名称WCFtest.解决方案中添加WCF服务应用程序,名称WcfServiceTe ...

  7. Java进阶(五十二)利用LOG4J生成服务日志

    Java进阶(五十二)利用LOG4J生成服务日志 前言 由于论文写作需求,需要进行流程挖掘.前提是需要有真实的事件日志数据.真实的事件日志数据可以用来发现.监控和提升业务流程. 为了获得真实的事件日志 ...

  8. C++的MFC 与 HTML 双向通讯

    C++中嵌入ie浏览器总结(1) - ie边框 及上下文菜单 最近项目中用html 来做界面,也就折腾了一下在wxwidget中嵌入浏览器的若干细节工作,mfc也基本是类似的,由于wxwidget中已 ...

  9. 利用Zynq Soc创建一个嵌入式工程

    英文题目:Using the Zynq SoC Processing System,参考自ADI的ug1165文档. 利用Zynq Soc创建一个嵌入式工程,该工程总体上包括五个步骤: 步骤一.新建空 ...

随机推荐

  1. 解决MSDE安装回滚的问题

    rem 解决MSDE安装回滚的问题.bat rem 设置为手动rem sc config "LanmanServer" start= DEMAND rem 设置为自动sc conf ...

  2. 【java】之深入理解JVM

    JVM规范定义的标准结构如下: 以上结构是JVM标准规范中定义的,但各厂家在实现时不一定会完全遵守, 1.JVM负责加载class文件并执行,因此,首先要掌握的是JDK如何将Java代码编译成clas ...

  3. java设计模式-工厂系列

    一.简单工厂 1.背景: 任意定制交通工具的类型和生产过程 代码: Moveable.java package com.cy.dp.factory; public interface Moveable ...

  4. DP 01背包 七夕模拟赛

    问题 D: 七夕模拟赛 时间限制: 1 Sec  内存限制: 128 MB提交: 60  解决: 23[提交][状态][讨论版] 题目描述 " 找啊找啊找GF,找到一个好GF,吃顿饭啊拉拉手 ...

  5. 廖雪峰Java5Java集合-5Queue-1使用Queue

    Queue特性和基本方法 Queue实现一个先进先出(FIFO, First In First Out)的队列.如收银台排队支付. Java中LinkedList实现了Queue接口,可以直接把Lin ...

  6. 廖雪峰Java4反射与泛型-1反射-4调用构造方法

    1.Class.newInstance()只能调用public的无参数构造方法 public class Main { public static void main(String[] args) t ...

  7. HDFS的工作流程

    HDFS的工作机制 概述 HDFS集群分为两大角色:NameNode.DataNode NameNode负责管理整个文件系统的元数据 DataNode 负责管理用户的文件数据块 文件会按照固定的大小( ...

  8. Jmeter(三十)Jmeter Question 之 循环+事务的妙用

    先提一个小问题,也是当时在对Jmeter还是懵懂之时,亲身碰到过的一个问题. 真实的业务场景---“登录一次,提交订单N次”,当然该处是两个接口. 提现接口是需要判断用户是否在线,换句话说,服务器需要 ...

  9. [UE4]让机器人开枪射击

  10. Java基础知识_毕向东_Java基础视频教程笔记(14-18集合框架)

    14天-01-集合框架集合类出现:面向对象语言对事物的体现都是以对象的形式,所以为了方便对多个对象的操作,就对对象进行存储,集合就是存储对象最常用的一种方式.数组与集合类同是容器,有何不同? 数组长度 ...