usb_bsp.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546
  1. /**
  2. ******************************************************************************
  3. * @file usb_bsp.c
  4. * @author MCD Application Team
  5. * @version V2.1.0
  6. * @date 19-March-2012
  7. * @brief This file implements the board support package for the USB host library
  8. ******************************************************************************
  9. * @attention
  10. *
  11. * <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2>
  12. *
  13. * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
  14. * You may not use this file except in compliance with the License.
  15. * You may obtain a copy of the License at:
  16. *
  17. * http://www.st.com/software_license_agreement_liberty_v2
  18. *
  19. * Unless required by applicable law or agreed to in writing, software
  20. * distributed under the License is distributed on an "AS IS" BASIS,
  21. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  22. * See the License for the specific language governing permissions and
  23. * limitations under the License.
  24. *
  25. ******************************************************************************
  26. */
  27. /* Includes ------------------------------------------------------------------*/
  28. #include "usb_bsp.h"
  29. /** @addtogroup USBH_USER
  30. * @{
  31. */
  32. /** @defgroup USB_BSP
  33. * @brief This file is responsible to offer board support package
  34. * @{
  35. */
  36. /** @defgroup USB_BSP_Private_Defines
  37. * @{
  38. */
  39. #define USE_ACCURATE_TIME
  40. #define TIM_MSEC_DELAY 0x01
  41. #define TIM_USEC_DELAY 0x02
  42. #if 0 /* 安富莱STM32-V5 不支持USB HOST接口的供电控制和过流检测 */
  43. #define HOST_OVRCURR_PORT GPIOE
  44. #define HOST_OVRCURR_LINE GPIO_Pin_1
  45. #define HOST_OVRCURR_PORT_SOURCE GPIO_PortSourceGPIOE
  46. #define HOST_OVRCURR_PIN_SOURCE GPIO_PinSource1
  47. #define HOST_OVRCURR_PORT_RCC RCC_APB2Periph_GPIOE
  48. #define HOST_OVRCURR_EXTI_LINE EXTI_Line1
  49. #define HOST_OVRCURR_IRQn EXTI1_IRQn
  50. #ifdef USE_STM3210C_EVAL
  51. #define HOST_POWERSW_PORT_RCC RCC_APB2Periph_GPIOC
  52. #define HOST_POWERSW_PORT GPIOC
  53. #define HOST_POWERSW_VBUS GPIO_Pin_9
  54. #else
  55. #ifdef USE_USB_OTG_FS
  56. #define HOST_POWERSW_PORT_RCC RCC_AHB1Periph_GPIOH
  57. #define HOST_POWERSW_PORT GPIOH
  58. #define HOST_POWERSW_VBUS GPIO_Pin_5
  59. #endif
  60. #endif
  61. #define HOST_SOF_OUTPUT_RCC RCC_APB2Periph_GPIOA
  62. #define HOST_SOF_PORT GPIOA
  63. #define HOST_SOF_SIGNAL GPIO_Pin_8
  64. #endif
  65. /**
  66. * @}
  67. */
  68. /** @defgroup USB_BSP_Private_TypesDefinitions
  69. * @{
  70. */
  71. /**
  72. * @}
  73. */
  74. /** @defgroup USB_BSP_Private_Macros
  75. * @{
  76. */
  77. /**
  78. * @}
  79. */
  80. /** @defgroup USBH_BSP_Private_Variables
  81. * @{
  82. */
  83. ErrorStatus HSEStartUpStatus;
  84. #ifdef USE_ACCURATE_TIME
  85. __IO uint32_t BSP_delay = 0;
  86. #endif
  87. /**
  88. * @}
  89. */
  90. /** @defgroup USBH_BSP_Private_FunctionPrototypes
  91. * @{
  92. */
  93. #ifdef USE_ACCURATE_TIME
  94. static void BSP_SetTime(uint8_t Unit);
  95. static void BSP_Delay(uint32_t nTime, uint8_t Unit);
  96. static void USB_OTG_BSP_TimeInit(void);
  97. #endif
  98. /**
  99. * @}
  100. */
  101. /** @defgroup USB_BSP_Private_Functions
  102. * @{
  103. */
  104. /**
  105. * @brief USB_OTG_BSP_Init
  106. * Initilizes BSP configurations
  107. * @param None
  108. * @retval None
  109. */
  110. void USB_OTG_BSP_Init(USB_OTG_CORE_HANDLE *pdev)
  111. {
  112. // EXTI_InitTypeDef EXTI_InitStructure;
  113. #ifdef USE_STM3210C_EVAL
  114. RCC_OTGFSCLKConfig(RCC_OTGFSCLKSource_PLLVCO_Div3);
  115. RCC_AHBPeriphClockCmd(RCC_AHBPeriph_OTG_FS, ENABLE);
  116. #else // USE_STM322xG_EVAL
  117. GPIO_InitTypeDef GPIO_InitStructure;
  118. #ifdef USE_USB_OTG_FS
  119. RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
  120. /* Configure SOF VBUS ID DM DP Pins */
  121. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_11 | GPIO_Pin_12;
  122. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
  123. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  124. GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  125. GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
  126. GPIO_Init(GPIOA, &GPIO_InitStructure);
  127. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
  128. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
  129. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
  130. GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  131. GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
  132. GPIO_Init(GPIOA, &GPIO_InitStructure);
  133. GPIO_PinAFConfig(GPIOA, GPIO_PinSource8, GPIO_AF_OTG1_FS);
  134. GPIO_PinAFConfig(GPIOA, GPIO_PinSource11, GPIO_AF_OTG1_FS);
  135. GPIO_PinAFConfig(GPIOA, GPIO_PinSource12, GPIO_AF_OTG1_FS);
  136. /* this for ID line debug */
  137. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
  138. GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
  139. GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
  140. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
  141. GPIO_Init(GPIOA, &GPIO_InitStructure);
  142. GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_OTG1_FS);
  143. RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
  144. RCC_AHB2PeriphClockCmd(RCC_AHB2Periph_OTG_FS, ENABLE);
  145. #else // USE_USB_OTG_HS
  146. #ifdef USE_ULPI_PHY // ULPI
  147. RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_GPIOB |
  148. RCC_AHB1Periph_GPIOC | RCC_AHB1Periph_GPIOH |
  149. RCC_AHB1Periph_GPIOI,
  150. ENABLE);
  151. GPIO_PinAFConfig(GPIOA, GPIO_PinSource3, GPIO_AF_OTG2_HS); // D0
  152. GPIO_PinAFConfig(GPIOA, GPIO_PinSource5, GPIO_AF_OTG2_HS); // CLK
  153. GPIO_PinAFConfig(GPIOB, GPIO_PinSource0, GPIO_AF_OTG2_HS); // D1
  154. GPIO_PinAFConfig(GPIOB, GPIO_PinSource1, GPIO_AF_OTG2_HS); // D2
  155. GPIO_PinAFConfig(GPIOB, GPIO_PinSource5, GPIO_AF_OTG2_HS); // D7
  156. GPIO_PinAFConfig(GPIOB, GPIO_PinSource10, GPIO_AF_OTG2_HS); // D3
  157. GPIO_PinAFConfig(GPIOB, GPIO_PinSource11, GPIO_AF_OTG2_HS); // D4
  158. GPIO_PinAFConfig(GPIOB, GPIO_PinSource12, GPIO_AF_OTG2_HS); // D5
  159. GPIO_PinAFConfig(GPIOB, GPIO_PinSource13, GPIO_AF_OTG2_HS); // D6
  160. GPIO_PinAFConfig(GPIOH, GPIO_PinSource4, GPIO_AF_OTG2_HS); // NXT
  161. GPIO_PinAFConfig(GPIOI, GPIO_PinSource11, GPIO_AF_OTG2_HS); // DIR
  162. GPIO_PinAFConfig(GPIOC, GPIO_PinSource0, GPIO_AF_OTG2_HS); // STP
  163. // CLK
  164. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
  165. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
  166. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  167. GPIO_Init(GPIOA, &GPIO_InitStructure);
  168. // D0
  169. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
  170. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
  171. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  172. GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  173. GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
  174. GPIO_Init(GPIOA, &GPIO_InitStructure);
  175. // D1 D2 D3 D4 D5 D6 D7
  176. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 |
  177. GPIO_Pin_5 | GPIO_Pin_10 |
  178. GPIO_Pin_11 | GPIO_Pin_12 |
  179. GPIO_Pin_13;
  180. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
  181. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  182. GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  183. GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
  184. GPIO_Init(GPIOB, &GPIO_InitStructure);
  185. // STP
  186. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
  187. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
  188. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  189. GPIO_Init(GPIOC, &GPIO_InitStructure);
  190. // NXT
  191. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
  192. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
  193. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  194. GPIO_Init(GPIOH, &GPIO_InitStructure);
  195. // DIR
  196. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
  197. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
  198. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  199. GPIO_Init(GPIOI, &GPIO_InitStructure);
  200. RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_OTG_HS |
  201. RCC_AHB1Periph_OTG_HS_ULPI,
  202. ENABLE);
  203. #else
  204. #if 1
  205. /* 安富莱只使用2根线 PB14/OTG_HS_DM 和 PB15/OTG_HS_DP 接U盘 */
  206. RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
  207. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_14 | GPIO_Pin_15;
  208. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
  209. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  210. GPIO_Init(GPIOB, &GPIO_InitStructure);
  211. GPIO_PinAFConfig(GPIOB, GPIO_PinSource14, GPIO_AF_OTG2_FS);
  212. GPIO_PinAFConfig(GPIOB, GPIO_PinSource15, GPIO_AF_OTG2_FS);
  213. RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_OTG_HS, ENABLE);
  214. #else
  215. RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
  216. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12 |
  217. GPIO_Pin_13 |
  218. GPIO_Pin_14 |
  219. GPIO_Pin_15;
  220. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
  221. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  222. GPIO_Init(GPIOB, &GPIO_InitStructure);
  223. GPIO_PinAFConfig(GPIOB, GPIO_PinSource12, GPIO_AF_OTG2_FS);
  224. GPIO_PinAFConfig(GPIOB, GPIO_PinSource13, GPIO_AF_OTG2_FS);
  225. GPIO_PinAFConfig(GPIOB, GPIO_PinSource14, GPIO_AF_OTG2_FS);
  226. GPIO_PinAFConfig(GPIOB, GPIO_PinSource15, GPIO_AF_OTG2_FS);
  227. RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_OTG_HS, ENABLE);
  228. #endif
  229. #endif
  230. #endif // USB_OTG_HS
  231. #endif // USE_STM322xG_EVAL
  232. /* Intialize Timer for delay function */
  233. USB_OTG_BSP_TimeInit();
  234. }
  235. /**
  236. * @brief USB_OTG_BSP_EnableInterrupt
  237. * Configures USB Global interrupt
  238. * @param None
  239. * @retval None
  240. */
  241. void USB_OTG_BSP_EnableInterrupt(USB_OTG_CORE_HANDLE *pdev)
  242. {
  243. NVIC_InitTypeDef NVIC_InitStructure;
  244. #ifdef USE_USB_OTG_HS
  245. NVIC_InitStructure.NVIC_IRQChannel = OTG_HS_IRQn;
  246. #else
  247. NVIC_InitStructure.NVIC_IRQChannel = OTG_FS_IRQn;
  248. #endif
  249. NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 3;
  250. NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
  251. NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  252. NVIC_Init(&NVIC_InitStructure);
  253. }
  254. /**
  255. * @brief BSP_Drive_VBUS
  256. * Drives the Vbus signal through IO
  257. * @param state : VBUS states
  258. * @retval None
  259. */
  260. void USB_OTG_BSP_DriveVBUS(USB_OTG_CORE_HANDLE *pdev, uint8_t state)
  261. {
  262. #if 0 /* 安富莱STM32-F4开发板不支持对外供电的控制 */
  263. /*
  264. On-chip 5 V VBUS generation is not supported. For this reason, a charge pump
  265. or, if 5 V are available on the application board, a basic power switch, must
  266. be added externally to drive the 5 V VBUS line. The external charge pump can
  267. be driven by any GPIO output. When the application decides to power on VBUS
  268. using the chosen GPIO, it must also set the port power bit in the host port
  269. control and status register (PPWR bit in OTG_FS_HPRT).
  270. Bit 12 PPWR: Port power
  271. The application uses this field to control power to this port, and the core
  272. clears this bit on an overcurrent condition.
  273. */
  274. #ifndef USE_USB_OTG_HS
  275. if (0 == state)
  276. {
  277. /* DISABLE is needed on output of the Power Switch */
  278. GPIO_SetBits(HOST_POWERSW_PORT, HOST_POWERSW_VBUS);
  279. }
  280. else
  281. {
  282. /*ENABLE the Power Switch by driving the Enable LOW */
  283. GPIO_ResetBits(HOST_POWERSW_PORT, HOST_POWERSW_VBUS);
  284. }
  285. #endif
  286. #endif
  287. }
  288. /**
  289. * @brief USB_OTG_BSP_ConfigVBUS
  290. * Configures the IO for the Vbus and OverCurrent
  291. * @param None
  292. * @retval None
  293. */
  294. void USB_OTG_BSP_ConfigVBUS(USB_OTG_CORE_HANDLE *pdev)
  295. {
  296. #if 0 /* 安富莱STM32-F4 不支持VBUS */
  297. #ifndef USE_USB_OTG_HS
  298. GPIO_InitTypeDef GPIO_InitStructure;
  299. #ifdef USE_STM3210C_EVAL
  300. RCC_APB2PeriphClockCmd(HOST_POWERSW_PORT_RCC, ENABLE);
  301. /* Configure Power Switch Vbus Pin */
  302. GPIO_InitStructure.GPIO_Pin = HOST_POWERSW_VBUS;
  303. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  304. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  305. GPIO_Init(HOST_POWERSW_PORT, &GPIO_InitStructure);
  306. #else
  307. #ifdef USE_USB_OTG_FS
  308. RCC_AHB1PeriphClockCmd( RCC_AHB1Periph_GPIOH , ENABLE);
  309. GPIO_InitStructure.GPIO_Pin = HOST_POWERSW_VBUS;
  310. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
  311. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
  312. GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  313. GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
  314. GPIO_Init(HOST_POWERSW_PORT,&GPIO_InitStructure);
  315. #endif
  316. #endif
  317. /* By Default, DISABLE is needed on output of the Power Switch */
  318. GPIO_SetBits(HOST_POWERSW_PORT, HOST_POWERSW_VBUS);
  319. USB_OTG_BSP_mDelay(200); /* Delay is need for stabilising the Vbus Low
  320. in Reset Condition, when Vbus=1 and Reset-button is pressed by user */
  321. #endif
  322. #endif
  323. }
  324. /**
  325. * @brief USB_OTG_BSP_TimeInit
  326. * Initializes delay unit using Timer2
  327. * @param None
  328. * @retval None
  329. */
  330. static void USB_OTG_BSP_TimeInit(void)
  331. {
  332. #ifdef USE_ACCURATE_TIME
  333. NVIC_InitTypeDef NVIC_InitStructure;
  334. /* Enable the TIM2 gloabal Interrupt */
  335. NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn;
  336. NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
  337. NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
  338. NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  339. NVIC_Init(&NVIC_InitStructure);
  340. RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
  341. #endif
  342. }
  343. /**
  344. * @brief USB_OTG_BSP_uDelay
  345. * This function provides delay time in micro sec
  346. * @param usec : Value of delay required in micro sec
  347. * @retval None
  348. */
  349. void USB_OTG_BSP_uDelay(const uint32_t usec)
  350. {
  351. #ifdef USE_ACCURATE_TIME
  352. BSP_Delay(usec, TIM_USEC_DELAY);
  353. #else
  354. __IO uint32_t count = 0;
  355. const uint32_t utime = (120 * usec / 7);
  356. do
  357. {
  358. if (++count > utime)
  359. {
  360. return;
  361. }
  362. } while (1);
  363. #endif
  364. }
  365. /**
  366. * @brief USB_OTG_BSP_mDelay
  367. * This function provides delay time in milli sec
  368. * @param msec : Value of delay required in milli sec
  369. * @retval None
  370. */
  371. void USB_OTG_BSP_mDelay(const uint32_t msec)
  372. {
  373. #ifdef USE_ACCURATE_TIME
  374. BSP_Delay(msec, TIM_MSEC_DELAY);
  375. #else
  376. USB_OTG_BSP_uDelay(msec * 1000);
  377. #endif
  378. }
  379. /**
  380. * @brief USB_OTG_BSP_TimerIRQ
  381. * Time base IRQ
  382. * @param None
  383. * @retval None
  384. */
  385. void USB_OTG_BSP_TimerIRQ(void)
  386. {
  387. #ifdef USE_ACCURATE_TIME
  388. if (TIM_GetITStatus(TIM2, TIM_IT_Update) != RESET)
  389. {
  390. TIM_ClearITPendingBit(TIM2, TIM_IT_Update);
  391. if (BSP_delay > 0x00)
  392. {
  393. BSP_delay--;
  394. }
  395. else
  396. {
  397. TIM_Cmd(TIM2, DISABLE);
  398. }
  399. }
  400. #endif
  401. }
  402. #ifdef USE_ACCURATE_TIME
  403. /**
  404. * @brief BSP_Delay
  405. * Delay routine based on TIM2
  406. * @param nTime : Delay Time
  407. * @param unit : Delay Time unit : mili sec / micro sec
  408. * @retval None
  409. */
  410. static void BSP_Delay(uint32_t nTime, uint8_t unit)
  411. {
  412. BSP_delay = nTime;
  413. BSP_SetTime(unit);
  414. while (BSP_delay != 0)
  415. ;
  416. TIM_Cmd(TIM2, DISABLE);
  417. }
  418. /**
  419. * @brief BSP_SetTime
  420. * Configures TIM2 for delay routine based on TIM2
  421. * @param unit : msec /usec
  422. * @retval None
  423. */
  424. static void BSP_SetTime(uint8_t unit)
  425. {
  426. TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
  427. TIM_Cmd(TIM2, DISABLE);
  428. TIM_ITConfig(TIM2, TIM_IT_Update, DISABLE);
  429. if (unit == TIM_USEC_DELAY)
  430. {
  431. TIM_TimeBaseStructure.TIM_Period = 11;
  432. }
  433. else if (unit == TIM_MSEC_DELAY)
  434. {
  435. TIM_TimeBaseStructure.TIM_Period = 11999;
  436. }
  437. TIM_TimeBaseStructure.TIM_Prescaler = 5;
  438. TIM_TimeBaseStructure.TIM_ClockDivision = 0;
  439. TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
  440. TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);
  441. TIM_ClearITPendingBit(TIM2, TIM_IT_Update);
  442. TIM_ARRPreloadConfig(TIM2, ENABLE);
  443. /* TIM IT enable */
  444. TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE);
  445. /* TIM2 enable counter */
  446. TIM_Cmd(TIM2, ENABLE);
  447. }
  448. #endif
  449. /**
  450. * @}
  451. */
  452. /**
  453. * @}
  454. */
  455. /**
  456. * @}
  457. */
  458. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/