usb_device.c 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /* USER CODE BEGIN Header */
  2. /**
  3. ******************************************************************************
  4. * @file : usb_device.c
  5. * @version : v3.0_Cube
  6. * @brief : This file implements the USB Device
  7. ******************************************************************************
  8. * @attention
  9. *
  10. * Copyright (c) 2025 STMicroelectronics.
  11. * All rights reserved.
  12. *
  13. * This software is licensed under terms that can be found in the LICENSE file
  14. * in the root directory of this software component.
  15. * If no LICENSE file comes with this software, it is provided AS-IS.
  16. *
  17. ******************************************************************************
  18. */
  19. /* USER CODE END Header */
  20. /* Includes ------------------------------------------------------------------*/
  21. #include "usb_device.h"
  22. #include "usbd_core.h"
  23. #include "usbd_desc.h"
  24. #include "usbd_customhid.h"
  25. #include "usbd_custom_hid_if.h"
  26. /* USER CODE BEGIN Includes */
  27. /* USER CODE END Includes */
  28. /* USER CODE BEGIN PV */
  29. /* Private variables ---------------------------------------------------------*/
  30. /* USER CODE END PV */
  31. /* USER CODE BEGIN PFP */
  32. /* Private function prototypes -----------------------------------------------*/
  33. /* USER CODE END PFP */
  34. extern void Error_Handler(void);
  35. /* USB Device Core handle declaration. */
  36. USBD_HandleTypeDef hUsbDeviceFS;
  37. extern USBD_DescriptorsTypeDef CUSTOM_HID_Desc;
  38. /*
  39. * -- Insert your variables declaration here --
  40. */
  41. /* USER CODE BEGIN 0 */
  42. /* USER CODE END 0 */
  43. /*
  44. * -- Insert your external function declaration here --
  45. */
  46. /* USER CODE BEGIN 1 */
  47. /* USER CODE END 1 */
  48. /**
  49. * Init USB device Library, add supported class and start the library
  50. * @retval None
  51. */
  52. void MX_USB_Device_Init(void)
  53. {
  54. /* USER CODE BEGIN USB_Device_Init_PreTreatment */
  55. /* USER CODE END USB_Device_Init_PreTreatment */
  56. /* Init Device Library, add supported class and start the library. */
  57. if (USBD_Init(&hUsbDeviceFS, &CUSTOM_HID_Desc, DEVICE_FS) != USBD_OK) {
  58. Error_Handler();
  59. }
  60. if (USBD_RegisterClass(&hUsbDeviceFS, &USBD_CUSTOM_HID) != USBD_OK) {
  61. Error_Handler();
  62. }
  63. if (USBD_CUSTOM_HID_RegisterInterface(&hUsbDeviceFS, &USBD_CustomHID_fops_FS) != USBD_OK) {
  64. Error_Handler();
  65. }
  66. if (USBD_Start(&hUsbDeviceFS) != USBD_OK) {
  67. Error_Handler();
  68. }
  69. /* USER CODE BEGIN USB_Device_Init_PostTreatment */
  70. /* USER CODE END USB_Device_Init_PostTreatment */
  71. }
  72. /**
  73. * @}
  74. */
  75. /**
  76. * @}
  77. */