Create release.yml
[betaflight.git] / src / main / vcpf4 / usb_bsp.c
blob640379150b8db2f8b3ee6f612a4296b1e301817a
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 void USB_OTG_BSP_ConfigVBUS(USB_OTG_CORE_HANDLE *pdev) {
34 (void)pdev;
37 void USB_OTG_BSP_DriveVBUS(USB_OTG_CORE_HANDLE *pdev,uint8_t state) {
38 (void)pdev;
39 (void)state;
43 /**
44 * @brief USB_OTG_BSP_Init
45 * Initilizes BSP configurations
46 * @param None
47 * @retval None
50 void USB_OTG_BSP_Init(USB_OTG_CORE_HANDLE *pdev)
52 (void)pdev;
53 GPIO_InitTypeDef GPIO_InitStructure;
55 #ifndef USE_ULPI_PHY
56 #ifdef USB_OTG_FS_LOW_PWR_MGMT_SUPPORT
57 EXTI_InitTypeDef EXTI_InitStructure;
58 NVIC_InitTypeDef NVIC_InitStructure;
59 #endif
60 #endif
62 NVIC_InitTypeDef NVIC_InitStructure;
63 #ifdef USE_USB_OTG_HS
64 NVIC_InitStructure.NVIC_IRQChannel = OTG_HS_IRQn;
65 #else
66 NVIC_InitStructure.NVIC_IRQChannel = OTG_FS_IRQn;
67 #endif
68 NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = NVIC_PRIORITY_BASE(NVIC_PRIO_USB);
69 NVIC_InitStructure.NVIC_IRQChannelSubPriority = NVIC_PRIORITY_SUB(NVIC_PRIO_USB);
70 NVIC_InitStructure.NVIC_IRQChannelCmd = DISABLE;
71 NVIC_Init(&NVIC_InitStructure);
73 RCC_AHB1PeriphClockCmd( RCC_AHB1Periph_GPIOA , ENABLE);
75 /* Configure SOF VBUS ID DM DP Pins */
76 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11 | GPIO_Pin_12;
77 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
78 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
79 GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
80 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
81 GPIO_Init(GPIOA, &GPIO_InitStructure);
83 GPIO_PinAFConfig(GPIOA,GPIO_PinSource11,GPIO_AF_OTG1_FS) ;
84 GPIO_PinAFConfig(GPIOA,GPIO_PinSource12,GPIO_AF_OTG1_FS) ;
86 RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
87 RCC_AHB2PeriphClockCmd(RCC_AHB2Periph_OTG_FS, ENABLE) ;
89 EXTI_ClearITPendingBit(EXTI_Line0);
91 /**
92 * @brief USB_OTG_BSP_EnableInterrupt
93 * Enabele USB Global interrupt
94 * @param None
95 * @retval None
97 void USB_OTG_BSP_EnableInterrupt(USB_OTG_CORE_HANDLE *pdev)
99 (void)pdev;
100 NVIC_InitTypeDef NVIC_InitStructure;
102 NVIC_PriorityGroupConfig(NVIC_PRIORITY_GROUPING);
103 #ifdef USE_USB_OTG_HS
104 NVIC_InitStructure.NVIC_IRQChannel = OTG_HS_IRQn;
105 #else
106 NVIC_InitStructure.NVIC_IRQChannel = OTG_FS_IRQn;
107 #endif
108 NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = NVIC_PRIORITY_BASE(NVIC_PRIO_USB);
109 NVIC_InitStructure.NVIC_IRQChannelSubPriority = NVIC_PRIORITY_SUB(NVIC_PRIO_USB);
110 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
111 NVIC_Init(&NVIC_InitStructure);
112 #ifdef USB_OTG_HS_DEDICATED_EP1_ENABLED
113 NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
114 NVIC_InitStructure.NVIC_IRQChannel = OTG_HS_EP1_OUT_IRQn;
115 NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
116 NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;
117 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
118 NVIC_Init(&NVIC_InitStructure);
120 NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
121 NVIC_InitStructure.NVIC_IRQChannel = OTG_HS_EP1_IN_IRQn;
122 NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
123 NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
124 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
125 NVIC_Init(&NVIC_InitStructure);
126 #endif
129 * @brief USB_OTG_BSP_uDelay
130 * This function provides delay time in micro sec
131 * @param usec : Value of delay required in micro sec
132 * @retval None
134 #pragma GCC diagnostic push
135 #pragma GCC diagnostic ignored "-Wunsafe-loop-optimizations"
136 void USB_OTG_BSP_uDelay (const uint32_t usec)
138 uint32_t count = 0;
139 const uint32_t utime = (120 * usec / 7);
142 if ( ++count > utime )
144 return ;
147 while (1);
149 #pragma GCC diagnostic pop
152 * @brief USB_OTG_BSP_mDelay
153 * This function provides delay time in milli sec
154 * @param msec : Value of delay required in milli sec
155 * @retval None
157 void USB_OTG_BSP_mDelay (const uint32_t msec)
159 USB_OTG_BSP_uDelay(msec * 1000);
162 * @}
166 * @}
170 * @}
173 /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/