/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
- /**
- ******************************************************************************
- * File Name : USB_OTG.c
- * Description : This file provides code for the configuration
- * of the USB_OTG instances.
- ******************************************************************************
- ** This notice applies to any and all portions of this file
- * that are not between comment pairs USER CODE BEGIN and
- * USER CODE END. Other portions of this file, whether
- * inserted by the user or by software development tools
- * are owned by their respective copyright owners.
- *
- * COPYRIGHT(c) 2018 STMicroelectronics
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * 3. Neither the name of STMicroelectronics nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- ******************************************************************************
- */
- /* Includes ------------------------------------------------------------------*/
- #include "usb_otg.h"
- #include "stm32f4xx_hal.h"
- #include "aos/hal/gpio.h"
- /* USER CODE BEGIN 0 */
- /* USER CODE END 0 */
- PCD_HandleTypeDef hpcd_USB_OTG_FS;
- /* USB_OTG_FS init function */
- void MX_USB_OTG_FS_PCD_Init(void)
- {
- hpcd_USB_OTG_FS.Instance = USB_OTG_FS;
- hpcd_USB_OTG_FS.Init.dev_endpoints = 4;
- hpcd_USB_OTG_FS.Init.speed = PCD_SPEED_FULL;
- hpcd_USB_OTG_FS.Init.dma_enable = DISABLE;
- hpcd_USB_OTG_FS.Init.ep0_mps = DEP0CTL_MPS_64;
- hpcd_USB_OTG_FS.Init.phy_itface = PCD_PHY_EMBEDDED;
- hpcd_USB_OTG_FS.Init.Sof_enable = ENABLE;
- hpcd_USB_OTG_FS.Init.low_power_enable = DISABLE;
- hpcd_USB_OTG_FS.Init.lpm_enable = DISABLE;
- hpcd_USB_OTG_FS.Init.vbus_sensing_enable = ENABLE;
- hpcd_USB_OTG_FS.Init.use_dedicated_ep1 = DISABLE;
- if (HAL_PCD_Init(&hpcd_USB_OTG_FS) != HAL_OK)
- {
- Error_Handler(__FILE__, __LINE__);
- }
- }
- void HAL_PCD_MspInit(PCD_HandleTypeDef* pcdHandle)
- {
- GPIO_InitTypeDef GPIO_InitStruct;
- if(pcdHandle->Instance==USB_OTG_FS)
- {
- /* USER CODE BEGIN USB_OTG_FS_MspInit 0 */
- /* USER CODE END USB_OTG_FS_MspInit 0 */
-
- /**USB_OTG_FS GPIO Configuration
- PA8 ------> USB_OTG_FS_SOF
- PA9 ------> USB_OTG_FS_VBUS
- PA10 ------> USB_OTG_FS_ID
- PA11 ------> USB_OTG_FS_DM
- PA12 ------> USB_OTG_FS_DP
- */
- GPIO_InitStruct.Pin = USB_SOF_Pin|USB_ID_Pin|USB_DM_Pin|USB_DP_Pin;
- GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
- GPIO_InitStruct.Pull = GPIO_NOPULL;
- GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
- GPIO_InitStruct.Alternate = GPIO_AF10_OTG_FS;
- HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
- GPIO_InitStruct.Pin = USB_VBUS_Pin;
- GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
- GPIO_InitStruct.Pull = GPIO_NOPULL;
- HAL_GPIO_Init(USB_VBUS_GPIO_Port, &GPIO_InitStruct);
- /* USB_OTG_FS clock enable */
- __HAL_RCC_USB_OTG_FS_CLK_ENABLE();
- /* USER CODE BEGIN USB_OTG_FS_MspInit 1 */
- /* USER CODE END USB_OTG_FS_MspInit 1 */
- }
- }
- void HAL_PCD_MspDeInit(PCD_HandleTypeDef* pcdHandle)
- {
- if(pcdHandle->Instance==USB_OTG_FS)
- {
- /* USER CODE BEGIN USB_OTG_FS_MspDeInit 0 */
- /* USER CODE END USB_OTG_FS_MspDeInit 0 */
- /* Peripheral clock disable */
- __HAL_RCC_USB_OTG_FS_CLK_DISABLE();
-
- /**USB_OTG_FS GPIO Configuration
- PA8 ------> USB_OTG_FS_SOF
- PA9 ------> USB_OTG_FS_VBUS
- PA10 ------> USB_OTG_FS_ID
- PA11 ------> USB_OTG_FS_DM
- PA12 ------> USB_OTG_FS_DP
- */
- HAL_GPIO_DeInit(GPIOA, USB_SOF_Pin|USB_VBUS_Pin|USB_ID_Pin|USB_DM_Pin
- |USB_DP_Pin);
- /* USER CODE BEGIN USB_OTG_FS_MspDeInit 1 */
- /* USER CODE END USB_OTG_FS_MspDeInit 1 */
- }
- }
- /* USER CODE BEGIN 1 */
- /* USER CODE END 1 */
- /**
- * @}
- */
- /**
- * @}
- */
- /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/