2 ******************************************************************************
4 * @author MCD Application Team
6 * @date 19-September-2011
7 * @brief This file is responsible to offer board support package and is
8 * configurable by user.
9 ******************************************************************************
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>© COPYRIGHT 2011 STMicroelectronics</center></h2>
20 ******************************************************************************
23 /* Includes ------------------------------------------------------------------*/
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
) {
37 void USB_OTG_BSP_DriveVBUS(USB_OTG_CORE_HANDLE
*pdev
,uint8_t state
) {
44 * @brief USB_OTG_BSP_Init
45 * Initilizes BSP configurations
50 void USB_OTG_BSP_Init(USB_OTG_CORE_HANDLE
*pdev
)
53 GPIO_InitTypeDef GPIO_InitStructure
;
56 #ifdef USB_OTG_FS_LOW_PWR_MGMT_SUPPORT
57 EXTI_InitTypeDef EXTI_InitStructure
;
58 NVIC_InitTypeDef NVIC_InitStructure
;
62 NVIC_InitTypeDef NVIC_InitStructure
;
64 NVIC_InitStructure
.NVIC_IRQChannel
= OTG_HS_IRQn
;
66 NVIC_InitStructure
.NVIC_IRQChannel
= OTG_FS_IRQn
;
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
);
92 * @brief USB_OTG_BSP_EnableInterrupt
93 * Enabele USB Global interrupt
97 void USB_OTG_BSP_EnableInterrupt(USB_OTG_CORE_HANDLE
*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
;
106 NVIC_InitStructure
.NVIC_IRQChannel
= OTG_FS_IRQn
;
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
);
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
134 #pragma GCC diagnostic push
135 #pragma GCC diagnostic ignored "-Wunsafe-loop-optimizations"
136 void USB_OTG_BSP_uDelay (const uint32_t usec
)
139 const uint32_t utime
= (120 * usec
/ 7);
142 if ( ++count
> utime
)
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
157 void USB_OTG_BSP_mDelay (const uint32_t msec
)
159 USB_OTG_BSP_uDelay(msec
* 1000);
173 /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/