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
)
38 void USB_OTG_BSP_DriveVBUS(USB_OTG_CORE_HANDLE
*pdev
,uint8_t state
)
46 * @brief USB_OTG_BSP_Init
47 * Initilizes BSP configurations
52 void USB_OTG_BSP_Init(USB_OTG_CORE_HANDLE
*pdev
)
55 GPIO_InitTypeDef GPIO_InitStructure
;
58 #ifdef USB_OTG_FS_LOW_PWR_MGMT_SUPPORT
59 EXTI_InitTypeDef EXTI_InitStructure
;
60 NVIC_InitTypeDef NVIC_InitStructure
;
64 NVIC_InitTypeDef NVIC_InitStructure
;
66 NVIC_InitStructure
.NVIC_IRQChannel
= OTG_HS_IRQn
;
68 NVIC_InitStructure
.NVIC_IRQChannel
= OTG_FS_IRQn
;
70 NVIC_InitStructure
.NVIC_IRQChannelPreemptionPriority
= NVIC_PRIORITY_BASE(NVIC_PRIO_USB
);
71 NVIC_InitStructure
.NVIC_IRQChannelSubPriority
= NVIC_PRIORITY_SUB(NVIC_PRIO_USB
);
72 NVIC_InitStructure
.NVIC_IRQChannelCmd
= DISABLE
;
73 NVIC_Init(&NVIC_InitStructure
);
75 RCC_AHB1PeriphClockCmd( RCC_AHB1Periph_GPIOA
, ENABLE
);
77 /* Configure SOF VBUS ID DM DP Pins */
78 GPIO_InitStructure
.GPIO_Pin
= GPIO_Pin_11
| GPIO_Pin_12
;
79 GPIO_InitStructure
.GPIO_Speed
= GPIO_Speed_100MHz
;
80 GPIO_InitStructure
.GPIO_Mode
= GPIO_Mode_AF
;
81 GPIO_InitStructure
.GPIO_OType
= GPIO_OType_PP
;
82 GPIO_InitStructure
.GPIO_PuPd
= GPIO_PuPd_NOPULL
;
83 GPIO_Init(GPIOA
, &GPIO_InitStructure
);
85 GPIO_PinAFConfig(GPIOA
,GPIO_PinSource11
,GPIO_AF_OTG1_FS
) ;
86 GPIO_PinAFConfig(GPIOA
,GPIO_PinSource12
,GPIO_AF_OTG1_FS
) ;
88 RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG
, ENABLE
);
89 RCC_AHB2PeriphClockCmd(RCC_AHB2Periph_OTG_FS
, ENABLE
) ;
91 EXTI_ClearITPendingBit(EXTI_Line0
);
94 * @brief USB_OTG_BSP_EnableInterrupt
95 * Enabele USB Global interrupt
99 void USB_OTG_BSP_EnableInterrupt(USB_OTG_CORE_HANDLE
*pdev
)
102 NVIC_InitTypeDef NVIC_InitStructure
;
104 NVIC_PriorityGroupConfig(NVIC_PRIORITY_GROUPING
);
105 #ifdef USE_USB_OTG_HS
106 NVIC_InitStructure
.NVIC_IRQChannel
= OTG_HS_IRQn
;
108 NVIC_InitStructure
.NVIC_IRQChannel
= OTG_FS_IRQn
;
110 NVIC_InitStructure
.NVIC_IRQChannelPreemptionPriority
= NVIC_PRIORITY_BASE(NVIC_PRIO_USB
);
111 NVIC_InitStructure
.NVIC_IRQChannelSubPriority
= NVIC_PRIORITY_SUB(NVIC_PRIO_USB
);
112 NVIC_InitStructure
.NVIC_IRQChannelCmd
= ENABLE
;
113 NVIC_Init(&NVIC_InitStructure
);
114 #ifdef USB_OTG_HS_DEDICATED_EP1_ENABLED
115 NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1
);
116 NVIC_InitStructure
.NVIC_IRQChannel
= OTG_HS_EP1_OUT_IRQn
;
117 NVIC_InitStructure
.NVIC_IRQChannelPreemptionPriority
= 1;
118 NVIC_InitStructure
.NVIC_IRQChannelSubPriority
= 2;
119 NVIC_InitStructure
.NVIC_IRQChannelCmd
= ENABLE
;
120 NVIC_Init(&NVIC_InitStructure
);
122 NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1
);
123 NVIC_InitStructure
.NVIC_IRQChannel
= OTG_HS_EP1_IN_IRQn
;
124 NVIC_InitStructure
.NVIC_IRQChannelPreemptionPriority
= 1;
125 NVIC_InitStructure
.NVIC_IRQChannelSubPriority
= 1;
126 NVIC_InitStructure
.NVIC_IRQChannelCmd
= ENABLE
;
127 NVIC_Init(&NVIC_InitStructure
);
131 * @brief USB_OTG_BSP_uDelay
132 * This function provides delay time in micro sec
133 * @param usec : Value of delay required in micro sec
136 #pragma GCC diagnostic push
137 #pragma GCC diagnostic ignored "-Wunsafe-loop-optimizations"
138 void USB_OTG_BSP_uDelay (const uint32_t usec
)
141 const uint32_t utime
= (120 * usec
/ 7);
144 if ( ++count
> utime
)
151 #pragma GCC diagnostic pop
154 * @brief USB_OTG_BSP_mDelay
155 * This function provides delay time in milli sec
156 * @param msec : Value of delay required in milli sec
159 void USB_OTG_BSP_mDelay (const uint32_t msec
)
161 USB_OTG_BSP_uDelay(msec
* 1000);
175 /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/