usb_otg.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /**
  2. ******************************************************************************
  3. * File Name : USB_OTG.c
  4. * Description : This file provides code for the configuration
  5. * of the USB_OTG instances.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; Copyright (c) 2020 STMicroelectronics.
  10. * All rights reserved.</center></h2>
  11. *
  12. * This software component is licensed by ST under BSD 3-Clause license,
  13. * the "License"; You may not use this file except in compliance with the
  14. * License. You may obtain a copy of the License at:
  15. * opensource.org/licenses/BSD-3-Clause
  16. *
  17. ******************************************************************************
  18. */
  19. /* Includes ------------------------------------------------------------------*/
  20. #include "usb_otg.h"
  21. /* USER CODE BEGIN 0 */
  22. /* USER CODE END 0 */
  23. PCD_HandleTypeDef hpcd_USB_OTG_FS;
  24. /* USB_OTG_FS init function */
  25. void MX_USB_OTG_FS_PCD_Init(void)
  26. {
  27. hpcd_USB_OTG_FS.Instance = USB_OTG_FS;
  28. hpcd_USB_OTG_FS.Init.dev_endpoints = 4;
  29. hpcd_USB_OTG_FS.Init.speed = PCD_SPEED_FULL;
  30. hpcd_USB_OTG_FS.Init.dma_enable = DISABLE;
  31. hpcd_USB_OTG_FS.Init.phy_itface = PCD_PHY_EMBEDDED;
  32. hpcd_USB_OTG_FS.Init.Sof_enable = DISABLE;
  33. hpcd_USB_OTG_FS.Init.low_power_enable = DISABLE;
  34. hpcd_USB_OTG_FS.Init.lpm_enable = DISABLE;
  35. hpcd_USB_OTG_FS.Init.vbus_sensing_enable = DISABLE;
  36. hpcd_USB_OTG_FS.Init.use_dedicated_ep1 = DISABLE;
  37. if (HAL_PCD_Init(&hpcd_USB_OTG_FS) != HAL_OK)
  38. {
  39. Error_Handler();
  40. }
  41. }
  42. void HAL_PCD_MspInit(PCD_HandleTypeDef* pcdHandle)
  43. {
  44. GPIO_InitTypeDef GPIO_InitStruct = {0};
  45. if(pcdHandle->Instance==USB_OTG_FS)
  46. {
  47. /* USER CODE BEGIN USB_OTG_FS_MspInit 0 */
  48. /* USER CODE END USB_OTG_FS_MspInit 0 */
  49. __HAL_RCC_GPIOA_CLK_ENABLE();
  50. /**USB_OTG_FS GPIO Configuration
  51. PA11 ------> USB_OTG_FS_DM
  52. PA12 ------> USB_OTG_FS_DP
  53. */
  54. GPIO_InitStruct.Pin = GPIO_PIN_11|GPIO_PIN_12;
  55. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  56. GPIO_InitStruct.Pull = GPIO_NOPULL;
  57. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  58. GPIO_InitStruct.Alternate = GPIO_AF10_OTG_FS;
  59. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  60. /* USB_OTG_FS clock enable */
  61. __HAL_RCC_USB_OTG_FS_CLK_ENABLE();
  62. /* USER CODE BEGIN USB_OTG_FS_MspInit 1 */
  63. /* USER CODE END USB_OTG_FS_MspInit 1 */
  64. }
  65. }
  66. void HAL_PCD_MspDeInit(PCD_HandleTypeDef* pcdHandle)
  67. {
  68. if(pcdHandle->Instance==USB_OTG_FS)
  69. {
  70. /* USER CODE BEGIN USB_OTG_FS_MspDeInit 0 */
  71. /* USER CODE END USB_OTG_FS_MspDeInit 0 */
  72. /* Peripheral clock disable */
  73. __HAL_RCC_USB_OTG_FS_CLK_DISABLE();
  74. /**USB_OTG_FS GPIO Configuration
  75. PA11 ------> USB_OTG_FS_DM
  76. PA12 ------> USB_OTG_FS_DP
  77. */
  78. HAL_GPIO_DeInit(GPIOA, GPIO_PIN_11|GPIO_PIN_12);
  79. /* USER CODE BEGIN USB_OTG_FS_MspDeInit 1 */
  80. /* USER CODE END USB_OTG_FS_MspDeInit 1 */
  81. }
  82. }
  83. /* USER CODE BEGIN 1 */
  84. /* USER CODE END 1 */
  85. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/