usb_device.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /* USER CODE BEGIN Header */
  2. /**
  3. ******************************************************************************
  4. * @file : usb_device.c
  5. * @version : v1.0_Cube
  6. * @brief : This file implements the USB Device
  7. ******************************************************************************
  8. * @attention
  9. *
  10. * <h2><center>&copy; Copyright (c) 2021 STMicroelectronics.
  11. * All rights reserved.</center></h2>
  12. *
  13. * This software component is licensed by ST under Ultimate Liberty license
  14. * SLA0044, the "License"; You may not use this file except in compliance with
  15. * the License. You may obtain a copy of the License at:
  16. * www.st.com/SLA0044
  17. *
  18. ******************************************************************************
  19. */
  20. /* USER CODE END Header */
  21. /* Includes ------------------------------------------------------------------*/
  22. #include "usb_device.h"
  23. #include "usbd_core.h"
  24. #include "usbd_desc.h"
  25. #include "usbd_msc.h"
  26. #include "usbd_storage_if.h"
  27. /* USER CODE BEGIN Includes */
  28. /* USER CODE END Includes */
  29. /* USER CODE BEGIN PV */
  30. /* Private variables ---------------------------------------------------------*/
  31. /* USER CODE END PV */
  32. /* USER CODE BEGIN PFP */
  33. /* Private function prototypes -----------------------------------------------*/
  34. /* USER CODE END PFP */
  35. /* USB Device Core handle declaration. */
  36. USBD_HandleTypeDef hUsbDeviceHS;
  37. USBD_HandleTypeDef hUsbDeviceFS;
  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(&hUsbDeviceHS, &HS_Desc, DEVICE_HS) != USBD_OK)
  58. {
  59. Error_Handler();
  60. }
  61. if (USBD_RegisterClass(&hUsbDeviceHS, &USBD_MSC) != USBD_OK)
  62. {
  63. Error_Handler();
  64. }
  65. if (USBD_MSC_RegisterStorage(&hUsbDeviceHS, &USBD_Storage_Interface_fops_HS) != USBD_OK)
  66. {
  67. Error_Handler();
  68. }
  69. if (USBD_Start(&hUsbDeviceHS) != USBD_OK)
  70. {
  71. Error_Handler();
  72. }
  73. /* USER CODE BEGIN USB_DEVICE_Init_PreTreatment */
  74. /* USER CODE END USB_DEVICE_Init_PreTreatment */
  75. /* Init Device Library, add supported class and start the library. */
  76. if (USBD_Init(&hUsbDeviceFS, &FS_Desc, DEVICE_FS) != USBD_OK)
  77. {
  78. Error_Handler();
  79. }
  80. if (USBD_RegisterClass(&hUsbDeviceFS, &USBD_MSC) != USBD_OK)
  81. {
  82. Error_Handler();
  83. }
  84. if (USBD_MSC_RegisterStorage(&hUsbDeviceFS, &USBD_Storage_Interface_fops_FS) != USBD_OK)
  85. {
  86. Error_Handler();
  87. }
  88. if (USBD_Start(&hUsbDeviceFS) != USBD_OK)
  89. {
  90. Error_Handler();
  91. }
  92. /* USER CODE BEGIN USB_DEVICE_Init_PostTreatment */
  93. /* USER CODE END USB_DEVICE_Init_PostTreatment */
  94. }
  95. /**
  96. * @}
  97. */
  98. /**
  99. * @}
  100. */
  101. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/