usb_device.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /* USER CODE BEGIN Header */
  2. /**
  3. ******************************************************************************
  4. * @file : usb_device.c
  5. * @version : v2.0_Cube
  6. * @brief : This file implements the USB Device
  7. ******************************************************************************
  8. * @attention
  9. *
  10. * Copyright (c) 2024 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_cdc.h"
  25. #include "usbd_cdc_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. /* USB Device Core handle declaration. */
  35. USBD_HandleTypeDef hUsbDeviceFS;
  36. /*
  37. * -- Insert your variables declaration here --
  38. */
  39. /* USER CODE BEGIN 0 */
  40. /* USER CODE END 0 */
  41. /*
  42. * -- Insert your external function declaration here --
  43. */
  44. /* USER CODE BEGIN 1 */
  45. /* USER CODE END 1 */
  46. /**
  47. * Init USB device Library, add supported class and start the library
  48. * @retval None
  49. */
  50. void MX_USB_DEVICE_Init(void)
  51. {
  52. /* USER CODE BEGIN USB_DEVICE_Init_PreTreatment */
  53. /* USER CODE END USB_DEVICE_Init_PreTreatment */
  54. /* Init Device Library, add supported class and start the library. */
  55. if (USBD_Init(&hUsbDeviceFS, &FS_Desc, DEVICE_FS) != USBD_OK)
  56. {
  57. Error_Handler();
  58. }
  59. if (USBD_RegisterClass(&hUsbDeviceFS, &USBD_CDC) != USBD_OK)
  60. {
  61. Error_Handler();
  62. }
  63. if (USBD_CDC_RegisterInterface(&hUsbDeviceFS, &USBD_Interface_fops_FS) != USBD_OK)
  64. {
  65. Error_Handler();
  66. }
  67. if (USBD_Start(&hUsbDeviceFS) != USBD_OK)
  68. {
  69. Error_Handler();
  70. }
  71. /* USER CODE BEGIN USB_DEVICE_Init_PostTreatment */
  72. /* USER CODE END USB_DEVICE_Init_PostTreatment */
  73. }
  74. /**
  75. * @}
  76. */
  77. /**
  78. * @}
  79. */