usb_device.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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_hid.h"
  25. /* USER CODE BEGIN Includes */
  26. /* USER CODE END Includes */
  27. /* USER CODE BEGIN PV */
  28. /* Private variables ---------------------------------------------------------*/
  29. /* USER CODE END PV */
  30. /* USER CODE BEGIN PFP */
  31. /* Private function prototypes -----------------------------------------------*/
  32. /* USER CODE END PFP */
  33. extern void Error_Handler(void);
  34. /* USB Device Core handle declaration. */
  35. USBD_HandleTypeDef hUsbDeviceFS;
  36. extern USBD_DescriptorsTypeDef HID_Desc;
  37. /*
  38. * -- Insert your variables declaration here --
  39. */
  40. /* USER CODE BEGIN 0 */
  41. /* USER CODE END 0 */
  42. /*
  43. * -- Insert your external function declaration here --
  44. */
  45. /* USER CODE BEGIN 1 */
  46. /* USER CODE END 1 */
  47. /**
  48. * Init USB device Library, add supported class and start the library
  49. * @retval None
  50. */
  51. void MX_USB_Device_Init(void)
  52. {
  53. /* USER CODE BEGIN USB_Device_Init_PreTreatment */
  54. /* USER CODE END USB_Device_Init_PreTreatment */
  55. /* Init Device Library, add supported class and start the library. */
  56. if (USBD_Init(&hUsbDeviceFS, &HID_Desc, DEVICE_FS) != USBD_OK) {
  57. Error_Handler();
  58. }
  59. if (USBD_RegisterClass(&hUsbDeviceFS, &USBD_HID) != USBD_OK) {
  60. Error_Handler();
  61. }
  62. if (USBD_Start(&hUsbDeviceFS) != USBD_OK) {
  63. Error_Handler();
  64. }
  65. /* USER CODE BEGIN USB_Device_Init_PostTreatment */
  66. /* USER CODE END USB_Device_Init_PostTreatment */
  67. }
  68. /**
  69. * @}
  70. */
  71. /**
  72. * @}
  73. */