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 LOCAL_UNUSED_FUNCTION
static void USB_OTG_BSP_ConfigVBUS(USB_OTG_CORE_HANDLE
*pdev
)
38 LOCAL_UNUSED_FUNCTION
static void USB_OTG_BSP_DriveVBUS(USB_OTG_CORE_HANDLE
*pdev
,uint8_t state
)
45 * @brief USB_OTG_BSP_Init
46 * Initilizes BSP configurations
51 void USB_OTG_BSP_Init(USB_OTG_CORE_HANDLE
*pdev
)
54 GPIO_InitTypeDef GPIO_InitStructure
;
57 #ifdef USB_OTG_FS_LOW_PWR_MGMT_SUPPORT
58 EXTI_InitTypeDef EXTI_InitStructure
;
59 NVIC_InitTypeDef NVIC_InitStructure
;
63 NVIC_InitTypeDef NVIC_InitStructure
;
65 NVIC_InitStructure
.NVIC_IRQChannel
= OTG_HS_IRQn
;
67 NVIC_InitStructure
.NVIC_IRQChannel
= OTG_FS_IRQn
;
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
);
93 * @brief USB_OTG_BSP_EnableInterrupt
94 * Enabele USB Global interrupt
98 void USB_OTG_BSP_EnableInterrupt(USB_OTG_CORE_HANDLE
*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
;
107 NVIC_InitStructure
.NVIC_IRQChannel
= OTG_FS_IRQn
;
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
);
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
135 #pragma GCC diagnostic push
136 #pragma GCC diagnostic ignored "-Wunsafe-loop-optimizations"
137 void USB_OTG_BSP_uDelay (const uint32_t usec
)
140 const uint32_t utime
= (120 * usec
/ 7);
143 if ( ++count
> utime
)
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
158 void USB_OTG_BSP_mDelay (const uint32_t msec
)
160 USB_OTG_BSP_uDelay(msec
* 1000);
174 /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/