/platform/board/stm32f429zi-nucleo/drivers/Src/usb_otg.c

https://github.com/alibaba/AliOS-Things · C · 150 lines · 49 code · 26 blank · 75 comment · 4 complexity · 8385ef996fddb2e6fcc9326ef2373de8 MD5 · raw file

  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. ** This notice applies to any and all portions of this file
  8. * that are not between comment pairs USER CODE BEGIN and
  9. * USER CODE END. Other portions of this file, whether
  10. * inserted by the user or by software development tools
  11. * are owned by their respective copyright owners.
  12. *
  13. * COPYRIGHT(c) 2018 STMicroelectronics
  14. *
  15. * Redistribution and use in source and binary forms, with or without modification,
  16. * are permitted provided that the following conditions are met:
  17. * 1. Redistributions of source code must retain the above copyright notice,
  18. * this list of conditions and the following disclaimer.
  19. * 2. Redistributions in binary form must reproduce the above copyright notice,
  20. * this list of conditions and the following disclaimer in the documentation
  21. * and/or other materials provided with the distribution.
  22. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  23. * may be used to endorse or promote products derived from this software
  24. * without specific prior written permission.
  25. *
  26. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  27. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  28. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  29. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  30. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  31. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  32. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  33. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  34. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  35. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  36. *
  37. ******************************************************************************
  38. */
  39. /* Includes ------------------------------------------------------------------*/
  40. #include "usb_otg.h"
  41. #include "stm32f4xx_hal.h"
  42. #include "aos/hal/gpio.h"
  43. /* USER CODE BEGIN 0 */
  44. /* USER CODE END 0 */
  45. PCD_HandleTypeDef hpcd_USB_OTG_FS;
  46. /* USB_OTG_FS init function */
  47. void MX_USB_OTG_FS_PCD_Init(void)
  48. {
  49. hpcd_USB_OTG_FS.Instance = USB_OTG_FS;
  50. hpcd_USB_OTG_FS.Init.dev_endpoints = 4;
  51. hpcd_USB_OTG_FS.Init.speed = PCD_SPEED_FULL;
  52. hpcd_USB_OTG_FS.Init.dma_enable = DISABLE;
  53. hpcd_USB_OTG_FS.Init.ep0_mps = DEP0CTL_MPS_64;
  54. hpcd_USB_OTG_FS.Init.phy_itface = PCD_PHY_EMBEDDED;
  55. hpcd_USB_OTG_FS.Init.Sof_enable = ENABLE;
  56. hpcd_USB_OTG_FS.Init.low_power_enable = DISABLE;
  57. hpcd_USB_OTG_FS.Init.lpm_enable = DISABLE;
  58. hpcd_USB_OTG_FS.Init.vbus_sensing_enable = ENABLE;
  59. hpcd_USB_OTG_FS.Init.use_dedicated_ep1 = DISABLE;
  60. if (HAL_PCD_Init(&hpcd_USB_OTG_FS) != HAL_OK)
  61. {
  62. Error_Handler(__FILE__, __LINE__);
  63. }
  64. }
  65. void HAL_PCD_MspInit(PCD_HandleTypeDef* pcdHandle)
  66. {
  67. GPIO_InitTypeDef GPIO_InitStruct;
  68. if(pcdHandle->Instance==USB_OTG_FS)
  69. {
  70. /* USER CODE BEGIN USB_OTG_FS_MspInit 0 */
  71. /* USER CODE END USB_OTG_FS_MspInit 0 */
  72. /**USB_OTG_FS GPIO Configuration
  73. PA8 ------> USB_OTG_FS_SOF
  74. PA9 ------> USB_OTG_FS_VBUS
  75. PA10 ------> USB_OTG_FS_ID
  76. PA11 ------> USB_OTG_FS_DM
  77. PA12 ------> USB_OTG_FS_DP
  78. */
  79. GPIO_InitStruct.Pin = USB_SOF_Pin|USB_ID_Pin|USB_DM_Pin|USB_DP_Pin;
  80. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  81. GPIO_InitStruct.Pull = GPIO_NOPULL;
  82. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  83. GPIO_InitStruct.Alternate = GPIO_AF10_OTG_FS;
  84. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  85. GPIO_InitStruct.Pin = USB_VBUS_Pin;
  86. GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  87. GPIO_InitStruct.Pull = GPIO_NOPULL;
  88. HAL_GPIO_Init(USB_VBUS_GPIO_Port, &GPIO_InitStruct);
  89. /* USB_OTG_FS clock enable */
  90. __HAL_RCC_USB_OTG_FS_CLK_ENABLE();
  91. /* USER CODE BEGIN USB_OTG_FS_MspInit 1 */
  92. /* USER CODE END USB_OTG_FS_MspInit 1 */
  93. }
  94. }
  95. void HAL_PCD_MspDeInit(PCD_HandleTypeDef* pcdHandle)
  96. {
  97. if(pcdHandle->Instance==USB_OTG_FS)
  98. {
  99. /* USER CODE BEGIN USB_OTG_FS_MspDeInit 0 */
  100. /* USER CODE END USB_OTG_FS_MspDeInit 0 */
  101. /* Peripheral clock disable */
  102. __HAL_RCC_USB_OTG_FS_CLK_DISABLE();
  103. /**USB_OTG_FS GPIO Configuration
  104. PA8 ------> USB_OTG_FS_SOF
  105. PA9 ------> USB_OTG_FS_VBUS
  106. PA10 ------> USB_OTG_FS_ID
  107. PA11 ------> USB_OTG_FS_DM
  108. PA12 ------> USB_OTG_FS_DP
  109. */
  110. HAL_GPIO_DeInit(GPIOA, USB_SOF_Pin|USB_VBUS_Pin|USB_ID_Pin|USB_DM_Pin
  111. |USB_DP_Pin);
  112. /* USER CODE BEGIN USB_OTG_FS_MspDeInit 1 */
  113. /* USER CODE END USB_OTG_FS_MspDeInit 1 */
  114. }
  115. }
  116. /* USER CODE BEGIN 1 */
  117. /* USER CODE END 1 */
  118. /**
  119. * @}
  120. */
  121. /**
  122. * @}
  123. */
  124. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/