Refactor missing prototypes 2 (#14170)
[betaflight.git] / src / platform / STM32 / vcpf4 / usb_bsp.c
blobaf871b15d320d32d9bcccbb1db95e3a3cbbfe93a
1 /**
2 ******************************************************************************
3 * @file usb_bsp.c
4 * @author MCD Application Team
5 * @version V1.0.0
6 * @date 19-September-2011
7 * @brief This file is responsible to offer board support package and is
8 * configurable by user.
9 ******************************************************************************
10 * @attention
12 * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
13 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
14 * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
15 * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
16 * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
17 * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
19 * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>
20 ******************************************************************************
23 /* Includes ------------------------------------------------------------------*/
25 #include "platform.h"
27 #include "usb_bsp.h"
28 #include "usbd_conf.h"
29 #include "stm32f4xx_conf.h"
30 #include "drivers/nvic.h"
31 #include "drivers/io.h"
33 LOCAL_UNUSED_FUNCTION static void USB_OTG_BSP_ConfigVBUS(USB_OTG_CORE_HANDLE *pdev)
35 (void)pdev;
38 LOCAL_UNUSED_FUNCTION static void USB_OTG_BSP_DriveVBUS(USB_OTG_CORE_HANDLE *pdev,uint8_t state)
40 (void)pdev;
41 (void)state;
44 /**
45 * @brief USB_OTG_BSP_Init
46 * Initilizes BSP configurations
47 * @param None
48 * @retval None
51 void USB_OTG_BSP_Init(USB_OTG_CORE_HANDLE *pdev)
53 (void)pdev;
54 GPIO_InitTypeDef GPIO_InitStructure;
56 #ifndef USE_ULPI_PHY
57 #ifdef USB_OTG_FS_LOW_PWR_MGMT_SUPPORT
58 EXTI_InitTypeDef EXTI_InitStructure;
59 NVIC_InitTypeDef NVIC_InitStructure;
60 #endif
61 #endif
63 NVIC_InitTypeDef NVIC_InitStructure;
64 #ifdef USE_USB_OTG_HS
65 NVIC_InitStructure.NVIC_IRQChannel = OTG_HS_IRQn;
66 #else
67 NVIC_InitStructure.NVIC_IRQChannel = OTG_FS_IRQn;
68 #endif
69 NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = NVIC_PRIORITY_BASE(NVIC_PRIO_USB);
70 NVIC_InitStructure.NVIC_IRQChannelSubPriority = NVIC_PRIORITY_SUB(NVIC_PRIO_USB);
71 NVIC_InitStructure.NVIC_IRQChannelCmd = DISABLE;
72 NVIC_Init(&NVIC_InitStructure);
74 RCC_AHB1PeriphClockCmd( RCC_AHB1Periph_GPIOA , ENABLE);
76 /* Configure SOF VBUS ID DM DP Pins */
77 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11 | GPIO_Pin_12;
78 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
79 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
80 GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
81 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
82 GPIO_Init(GPIOA, &GPIO_InitStructure);
84 GPIO_PinAFConfig(GPIOA,GPIO_PinSource11,GPIO_AF_OTG1_FS) ;
85 GPIO_PinAFConfig(GPIOA,GPIO_PinSource12,GPIO_AF_OTG1_FS) ;
87 RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
88 RCC_AHB2PeriphClockCmd(RCC_AHB2Periph_OTG_FS, ENABLE) ;
90 EXTI_ClearITPendingBit(EXTI_Line0);
92 /**
93 * @brief USB_OTG_BSP_EnableInterrupt
94 * Enabele USB Global interrupt
95 * @param None
96 * @retval None
98 void USB_OTG_BSP_EnableInterrupt(USB_OTG_CORE_HANDLE *pdev)
100 (void)pdev;
101 NVIC_InitTypeDef NVIC_InitStructure;
103 NVIC_PriorityGroupConfig(NVIC_PRIORITY_GROUPING);
104 #ifdef USE_USB_OTG_HS
105 NVIC_InitStructure.NVIC_IRQChannel = OTG_HS_IRQn;
106 #else
107 NVIC_InitStructure.NVIC_IRQChannel = OTG_FS_IRQn;
108 #endif
109 NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = NVIC_PRIORITY_BASE(NVIC_PRIO_USB);
110 NVIC_InitStructure.NVIC_IRQChannelSubPriority = NVIC_PRIORITY_SUB(NVIC_PRIO_USB);
111 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
112 NVIC_Init(&NVIC_InitStructure);
113 #ifdef USB_OTG_HS_DEDICATED_EP1_ENABLED
114 NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
115 NVIC_InitStructure.NVIC_IRQChannel = OTG_HS_EP1_OUT_IRQn;
116 NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
117 NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;
118 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
119 NVIC_Init(&NVIC_InitStructure);
121 NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
122 NVIC_InitStructure.NVIC_IRQChannel = OTG_HS_EP1_IN_IRQn;
123 NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
124 NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
125 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
126 NVIC_Init(&NVIC_InitStructure);
127 #endif
130 * @brief USB_OTG_BSP_uDelay
131 * This function provides delay time in micro sec
132 * @param usec : Value of delay required in micro sec
133 * @retval None
135 #pragma GCC diagnostic push
136 #pragma GCC diagnostic ignored "-Wunsafe-loop-optimizations"
137 void USB_OTG_BSP_uDelay (const uint32_t usec)
139 uint32_t count = 0;
140 const uint32_t utime = (120 * usec / 7);
143 if ( ++count > utime )
145 return ;
148 while (1);
150 #pragma GCC diagnostic pop
153 * @brief USB_OTG_BSP_mDelay
154 * This function provides delay time in milli sec
155 * @param msec : Value of delay required in milli sec
156 * @retval None
158 void USB_OTG_BSP_mDelay (const uint32_t msec)
160 USB_OTG_BSP_uDelay(msec * 1000);
163 * @}
167 * @}
171 * @}
174 /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/