stm32u5xx_hal_msp.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635
  1. /* USER CODE BEGIN Header */
  2. /**
  3. ******************************************************************************
  4. * @file stm32u5xx_hal_msp.c
  5. * @brief This file provides code for the MSP Initialization
  6. * and de-Initialization codes.
  7. ******************************************************************************
  8. * @attention
  9. *
  10. * <h2><center>&copy; Copyright (c) 2023 STMicroelectronics.
  11. * All rights reserved.</center></h2>
  12. *
  13. * This software component is licensed by ST under BSD 3-Clause license,
  14. * the "License"; You may not use this file except in compliance with the
  15. * License. You may obtain a copy of the License at:
  16. * opensource.org/licenses/BSD-3-Clause
  17. *
  18. ******************************************************************************
  19. */
  20. /* USER CODE END Header */
  21. /* Includes ------------------------------------------------------------------*/
  22. #include "main.h"
  23. /* USER CODE BEGIN Includes */
  24. #include <drv_common.h>
  25. /* USER CODE END Includes */
  26. /* Private typedef -----------------------------------------------------------*/
  27. /* USER CODE BEGIN TD */
  28. /* USER CODE END TD */
  29. /* Private define ------------------------------------------------------------*/
  30. /* USER CODE BEGIN Define */
  31. /* USER CODE END Define */
  32. /* Private macro -------------------------------------------------------------*/
  33. /* USER CODE BEGIN Macro */
  34. /* USER CODE END Macro */
  35. /* Private variables ---------------------------------------------------------*/
  36. /* USER CODE BEGIN PV */
  37. /* USER CODE END PV */
  38. /* Private function prototypes -----------------------------------------------*/
  39. /* USER CODE BEGIN PFP */
  40. /* USER CODE END PFP */
  41. /* External functions --------------------------------------------------------*/
  42. /* USER CODE BEGIN ExternalFunctions */
  43. /* USER CODE END ExternalFunctions */
  44. /* USER CODE BEGIN 0 */
  45. /* USER CODE END 0 */
  46. void HAL_TIM_MspPostInit(TIM_HandleTypeDef *htim);
  47. /**
  48. * Initializes the Global MSP.
  49. */
  50. void HAL_MspInit(void)
  51. {
  52. /* USER CODE BEGIN MspInit 0 */
  53. /* USER CODE END MspInit 0 */
  54. __HAL_RCC_PWR_CLK_ENABLE();
  55. HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_3);
  56. /* System interrupt init*/
  57. /* USER CODE BEGIN MspInit 1 */
  58. /* USER CODE END MspInit 1 */
  59. }
  60. /**
  61. * @brief ADC MSP Initialization
  62. * This function configures the hardware resources used in this example
  63. * @param hadc: ADC handle pointer
  64. * @retval None
  65. */
  66. void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc)
  67. {
  68. GPIO_InitTypeDef GPIO_InitStruct = {0};
  69. RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
  70. if(hadc->Instance==ADC1)
  71. {
  72. /* USER CODE BEGIN ADC1_MspInit 0 */
  73. /* USER CODE END ADC1_MspInit 0 */
  74. /** Initializes the peripherals clock
  75. */
  76. PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_ADCDAC;
  77. PeriphClkInit.AdcDacClockSelection = RCC_ADCDACCLKSOURCE_HSI;
  78. if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
  79. {
  80. Error_Handler();
  81. }
  82. /* Peripheral clock enable */
  83. __HAL_RCC_ADC1_CLK_ENABLE();
  84. __HAL_RCC_GPIOC_CLK_ENABLE();
  85. __HAL_RCC_GPIOB_CLK_ENABLE();
  86. /**ADC1 GPIO Configuration
  87. PC0 ------> ADC1_IN1
  88. PC1 ------> ADC1_IN2
  89. PC2 ------> ADC1_IN3
  90. PC3 ------> ADC1_IN4
  91. PB0 ------> ADC1_IN15
  92. */
  93. GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1|VBUS_SENSE_Pin|GPIO_PIN_3;
  94. GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
  95. GPIO_InitStruct.Pull = GPIO_NOPULL;
  96. HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
  97. GPIO_InitStruct.Pin = GPIO_PIN_0;
  98. GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
  99. GPIO_InitStruct.Pull = GPIO_NOPULL;
  100. HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  101. /* USER CODE BEGIN ADC1_MspInit 1 */
  102. /* USER CODE END ADC1_MspInit 1 */
  103. }
  104. }
  105. /**
  106. * @brief ADC MSP De-Initialization
  107. * This function freeze the hardware resources used in this example
  108. * @param hadc: ADC handle pointer
  109. * @retval None
  110. */
  111. void HAL_ADC_MspDeInit(ADC_HandleTypeDef* hadc)
  112. {
  113. if(hadc->Instance==ADC1)
  114. {
  115. /* USER CODE BEGIN ADC1_MspDeInit 0 */
  116. /* USER CODE END ADC1_MspDeInit 0 */
  117. /* Peripheral clock disable */
  118. __HAL_RCC_ADC1_CLK_DISABLE();
  119. /**ADC1 GPIO Configuration
  120. PC0 ------> ADC1_IN1
  121. PC1 ------> ADC1_IN2
  122. PC2 ------> ADC1_IN3
  123. PC3 ------> ADC1_IN4
  124. PB0 ------> ADC1_IN15
  125. */
  126. HAL_GPIO_DeInit(GPIOC, GPIO_PIN_0|GPIO_PIN_1|VBUS_SENSE_Pin|GPIO_PIN_3);
  127. HAL_GPIO_DeInit(GPIOB, GPIO_PIN_0);
  128. /* USER CODE BEGIN ADC1_MspDeInit 1 */
  129. /* USER CODE END ADC1_MspDeInit 1 */
  130. }
  131. }
  132. /**
  133. * @brief UART MSP Initialization
  134. * This function configures the hardware resources used in this example
  135. * @param huart: UART handle pointer
  136. * @retval None
  137. */
  138. void HAL_UART_MspInit(UART_HandleTypeDef* huart)
  139. {
  140. GPIO_InitTypeDef GPIO_InitStruct = {0};
  141. RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
  142. if(huart->Instance==LPUART1)
  143. {
  144. /* USER CODE BEGIN LPUART1_MspInit 0 */
  145. /* USER CODE END LPUART1_MspInit 0 */
  146. /** Initializes the peripherals clock
  147. */
  148. PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_LPUART1;
  149. PeriphClkInit.Lpuart1ClockSelection = RCC_LPUART1CLKSOURCE_PCLK3;
  150. if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
  151. {
  152. Error_Handler();
  153. }
  154. /* Peripheral clock enable */
  155. __HAL_RCC_LPUART1_CLK_ENABLE();
  156. __HAL_RCC_GPIOG_CLK_ENABLE();
  157. /**LPUART1 GPIO Configuration
  158. PG7 ------> LPUART1_TX
  159. PG8 ------> LPUART1_RX
  160. */
  161. GPIO_InitStruct.Pin = GPIO_PIN_7|GPIO_PIN_8;
  162. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  163. GPIO_InitStruct.Pull = GPIO_NOPULL;
  164. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  165. GPIO_InitStruct.Alternate = GPIO_AF8_LPUART1;
  166. HAL_GPIO_Init(GPIOG, &GPIO_InitStruct);
  167. /* USER CODE BEGIN LPUART1_MspInit 1 */
  168. /* USER CODE END LPUART1_MspInit 1 */
  169. }
  170. else if(huart->Instance==USART1)
  171. {
  172. /* USER CODE BEGIN USART1_MspInit 0 */
  173. /* USER CODE END USART1_MspInit 0 */
  174. /** Initializes the peripherals clock
  175. */
  176. PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USART1;
  177. PeriphClkInit.Usart1ClockSelection = RCC_USART1CLKSOURCE_PCLK2;
  178. if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
  179. {
  180. Error_Handler();
  181. }
  182. /* Peripheral clock enable */
  183. __HAL_RCC_USART1_CLK_ENABLE();
  184. __HAL_RCC_GPIOA_CLK_ENABLE();
  185. /**USART1 GPIO Configuration
  186. PA9 ------> USART1_TX
  187. PA10 ------> USART1_RX
  188. */
  189. GPIO_InitStruct.Pin = USART1_TX_Pin|USART1_RX_Pin;
  190. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  191. GPIO_InitStruct.Pull = GPIO_PULLDOWN;
  192. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  193. GPIO_InitStruct.Alternate = GPIO_AF7_USART1;
  194. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  195. /* USER CODE BEGIN USART1_MspInit 1 */
  196. /* USER CODE END USART1_MspInit 1 */
  197. }
  198. else if(huart->Instance==USART2)
  199. {
  200. /* USER CODE BEGIN USART2_MspInit 0 */
  201. /* USER CODE END USART2_MspInit 0 */
  202. /** Initializes the peripherals clock
  203. */
  204. PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USART2;
  205. PeriphClkInit.Usart2ClockSelection = RCC_USART2CLKSOURCE_PCLK1;
  206. if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
  207. {
  208. Error_Handler();
  209. }
  210. /* Peripheral clock enable */
  211. __HAL_RCC_USART2_CLK_ENABLE();
  212. __HAL_RCC_GPIOA_CLK_ENABLE();
  213. /**USART2 GPIO Configuration
  214. PA2 ------> USART2_TX
  215. PA3 ------> USART2_RX
  216. */
  217. GPIO_InitStruct.Pin = GPIO_PIN_2|GPIO_PIN_3;
  218. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  219. GPIO_InitStruct.Pull = GPIO_NOPULL;
  220. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  221. GPIO_InitStruct.Alternate = GPIO_AF7_USART2;
  222. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  223. /* USER CODE BEGIN USART2_MspInit 1 */
  224. /* USER CODE END USART2_MspInit 1 */
  225. }
  226. }
  227. /**
  228. * @brief UART MSP De-Initialization
  229. * This function freeze the hardware resources used in this example
  230. * @param huart: UART handle pointer
  231. * @retval None
  232. */
  233. void HAL_UART_MspDeInit(UART_HandleTypeDef* huart)
  234. {
  235. if(huart->Instance==LPUART1)
  236. {
  237. /* USER CODE BEGIN LPUART1_MspDeInit 0 */
  238. /* USER CODE END LPUART1_MspDeInit 0 */
  239. /* Peripheral clock disable */
  240. __HAL_RCC_LPUART1_CLK_DISABLE();
  241. /**LPUART1 GPIO Configuration
  242. PG7 ------> LPUART1_TX
  243. PG8 ------> LPUART1_RX
  244. */
  245. HAL_GPIO_DeInit(GPIOG, GPIO_PIN_7|GPIO_PIN_8);
  246. /* USER CODE BEGIN LPUART1_MspDeInit 1 */
  247. /* USER CODE END LPUART1_MspDeInit 1 */
  248. }
  249. else if(huart->Instance==USART1)
  250. {
  251. /* USER CODE BEGIN USART1_MspDeInit 0 */
  252. /* USER CODE END USART1_MspDeInit 0 */
  253. /* Peripheral clock disable */
  254. __HAL_RCC_USART1_CLK_DISABLE();
  255. /**USART1 GPIO Configuration
  256. PA9 ------> USART1_TX
  257. PA10 ------> USART1_RX
  258. */
  259. HAL_GPIO_DeInit(GPIOA, USART1_TX_Pin|USART1_RX_Pin);
  260. /* USER CODE BEGIN USART1_MspDeInit 1 */
  261. /* USER CODE END USART1_MspDeInit 1 */
  262. }
  263. else if(huart->Instance==USART2)
  264. {
  265. /* USER CODE BEGIN USART2_MspDeInit 0 */
  266. /* USER CODE END USART2_MspDeInit 0 */
  267. /* Peripheral clock disable */
  268. __HAL_RCC_USART2_CLK_DISABLE();
  269. /**USART2 GPIO Configuration
  270. PA2 ------> USART2_TX
  271. PA3 ------> USART2_RX
  272. */
  273. HAL_GPIO_DeInit(GPIOA, GPIO_PIN_2|GPIO_PIN_3);
  274. /* USER CODE BEGIN USART2_MspDeInit 1 */
  275. /* USER CODE END USART2_MspDeInit 1 */
  276. }
  277. }
  278. /**
  279. * @brief SPI MSP Initialization
  280. * This function configures the hardware resources used in this example
  281. * @param hspi: SPI handle pointer
  282. * @retval None
  283. */
  284. void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi)
  285. {
  286. GPIO_InitTypeDef GPIO_InitStruct = {0};
  287. RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
  288. if(hspi->Instance==SPI1)
  289. {
  290. /* USER CODE BEGIN SPI1_MspInit 0 */
  291. /* USER CODE END SPI1_MspInit 0 */
  292. /** Initializes the peripherals clock
  293. */
  294. PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_SPI1;
  295. PeriphClkInit.Spi1ClockSelection = RCC_SPI1CLKSOURCE_SYSCLK;
  296. if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
  297. {
  298. Error_Handler();
  299. }
  300. /* Peripheral clock enable */
  301. __HAL_RCC_SPI1_CLK_ENABLE();
  302. __HAL_RCC_GPIOA_CLK_ENABLE();
  303. /**SPI1 GPIO Configuration
  304. PA5 ------> SPI1_SCK
  305. PA6 ------> SPI1_MISO
  306. PA7 ------> SPI1_MOSI
  307. */
  308. GPIO_InitStruct.Pin = GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7;
  309. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  310. GPIO_InitStruct.Pull = GPIO_NOPULL;
  311. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  312. GPIO_InitStruct.Alternate = GPIO_AF5_SPI1;
  313. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  314. /* USER CODE BEGIN SPI1_MspInit 1 */
  315. /* USER CODE END SPI1_MspInit 1 */
  316. }
  317. }
  318. /**
  319. * @brief SPI MSP De-Initialization
  320. * This function freeze the hardware resources used in this example
  321. * @param hspi: SPI handle pointer
  322. * @retval None
  323. */
  324. void HAL_SPI_MspDeInit(SPI_HandleTypeDef* hspi)
  325. {
  326. if(hspi->Instance==SPI1)
  327. {
  328. /* USER CODE BEGIN SPI1_MspDeInit 0 */
  329. /* USER CODE END SPI1_MspDeInit 0 */
  330. /* Peripheral clock disable */
  331. __HAL_RCC_SPI1_CLK_DISABLE();
  332. /**SPI1 GPIO Configuration
  333. PA5 ------> SPI1_SCK
  334. PA6 ------> SPI1_MISO
  335. PA7 ------> SPI1_MOSI
  336. */
  337. HAL_GPIO_DeInit(GPIOA, GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7);
  338. /* USER CODE BEGIN SPI1_MspDeInit 1 */
  339. /* USER CODE END SPI1_MspDeInit 1 */
  340. }
  341. }
  342. /**
  343. * @brief TIM_Base MSP Initialization
  344. * This function configures the hardware resources used in this example
  345. * @param htim_base: TIM_Base handle pointer
  346. * @retval None
  347. */
  348. void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* htim_base)
  349. {
  350. if(htim_base->Instance==TIM1)
  351. {
  352. /* USER CODE BEGIN TIM1_MspInit 0 */
  353. /* USER CODE END TIM1_MspInit 0 */
  354. /* Peripheral clock enable */
  355. __HAL_RCC_TIM1_CLK_ENABLE();
  356. /* USER CODE BEGIN TIM1_MspInit 1 */
  357. /* USER CODE END TIM1_MspInit 1 */
  358. }
  359. else if(htim_base->Instance==TIM4)
  360. {
  361. /* USER CODE BEGIN TIM4_MspInit 0 */
  362. /* USER CODE END TIM4_MspInit 0 */
  363. /* Peripheral clock enable */
  364. __HAL_RCC_TIM4_CLK_ENABLE();
  365. /* USER CODE BEGIN TIM4_MspInit 1 */
  366. /* USER CODE END TIM4_MspInit 1 */
  367. }
  368. }
  369. void HAL_TIM_MspPostInit(TIM_HandleTypeDef* htim)
  370. {
  371. GPIO_InitTypeDef GPIO_InitStruct = {0};
  372. if(htim->Instance==TIM1)
  373. {
  374. /* USER CODE BEGIN TIM1_MspPostInit 0 */
  375. /* USER CODE END TIM1_MspPostInit 0 */
  376. __HAL_RCC_GPIOE_CLK_ENABLE();
  377. /**TIM1 GPIO Configuration
  378. PE9 ------> TIM1_CH1
  379. PE11 ------> TIM1_CH2
  380. PE13 ------> TIM1_CH3
  381. */
  382. GPIO_InitStruct.Pin = GPIO_PIN_9|GPIO_PIN_11|GPIO_PIN_13;
  383. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  384. GPIO_InitStruct.Pull = GPIO_NOPULL;
  385. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  386. GPIO_InitStruct.Alternate = GPIO_AF1_TIM1;
  387. HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
  388. /* USER CODE BEGIN TIM1_MspPostInit 1 */
  389. /* USER CODE END TIM1_MspPostInit 1 */
  390. }
  391. else if(htim->Instance==TIM4)
  392. {
  393. /* USER CODE BEGIN TIM4_MspPostInit 0 */
  394. /* USER CODE END TIM4_MspPostInit 0 */
  395. __HAL_RCC_GPIOD_CLK_ENABLE();
  396. /**TIM4 GPIO Configuration
  397. PD15 ------> TIM4_CH4
  398. */
  399. GPIO_InitStruct.Pin = GPIO_PIN_15;
  400. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  401. GPIO_InitStruct.Pull = GPIO_NOPULL;
  402. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  403. GPIO_InitStruct.Alternate = GPIO_AF2_TIM4;
  404. HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
  405. /* USER CODE BEGIN TIM4_MspPostInit 1 */
  406. /* USER CODE END TIM4_MspPostInit 1 */
  407. }
  408. }
  409. /**
  410. * @brief TIM_Base MSP De-Initialization
  411. * This function freeze the hardware resources used in this example
  412. * @param htim_base: TIM_Base handle pointer
  413. * @retval None
  414. */
  415. void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* htim_base)
  416. {
  417. if(htim_base->Instance==TIM1)
  418. {
  419. /* USER CODE BEGIN TIM1_MspDeInit 0 */
  420. /* USER CODE END TIM1_MspDeInit 0 */
  421. /* Peripheral clock disable */
  422. __HAL_RCC_TIM1_CLK_DISABLE();
  423. /* USER CODE BEGIN TIM1_MspDeInit 1 */
  424. /* USER CODE END TIM1_MspDeInit 1 */
  425. }
  426. else if(htim_base->Instance==TIM4)
  427. {
  428. /* USER CODE BEGIN TIM4_MspDeInit 0 */
  429. /* USER CODE END TIM4_MspDeInit 0 */
  430. /* Peripheral clock disable */
  431. __HAL_RCC_TIM4_CLK_DISABLE();
  432. /* USER CODE BEGIN TIM4_MspDeInit 1 */
  433. /* USER CODE END TIM4_MspDeInit 1 */
  434. }
  435. }
  436. /**
  437. * @brief PCD MSP Initialization
  438. * This function configures the hardware resources used in this example
  439. * @param hpcd: PCD handle pointer
  440. * @retval None
  441. */
  442. void HAL_PCD_MspInit(PCD_HandleTypeDef* hpcd)
  443. {
  444. GPIO_InitTypeDef GPIO_InitStruct = {0};
  445. RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
  446. if(hpcd->Instance==USB_OTG_FS)
  447. {
  448. /* USER CODE BEGIN USB_OTG_FS_MspInit 0 */
  449. /* USER CODE END USB_OTG_FS_MspInit 0 */
  450. /** Initializes the peripherals clock
  451. */
  452. PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_CLK48;
  453. PeriphClkInit.Clk48ClockSelection = RCC_CLK48CLKSOURCE_HSI48;
  454. if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
  455. {
  456. Error_Handler();
  457. }
  458. __HAL_RCC_GPIOA_CLK_ENABLE();
  459. /**USB_OTG_FS GPIO Configuration
  460. PA11 ------> USB_OTG_FS_DM
  461. PA12 ------> USB_OTG_FS_DP
  462. */
  463. GPIO_InitStruct.Pin = USB_OTG_FS_DM_Pin|USB_OTG_FS_DP_Pin;
  464. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  465. GPIO_InitStruct.Pull = GPIO_NOPULL;
  466. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  467. GPIO_InitStruct.Alternate = GPIO_AF10_USB;
  468. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  469. /* Peripheral clock enable */
  470. __HAL_RCC_USB_CLK_ENABLE();
  471. /* Enable VDDUSB */
  472. if(__HAL_RCC_PWR_IS_CLK_DISABLED())
  473. {
  474. __HAL_RCC_PWR_CLK_ENABLE();
  475. HAL_PWREx_EnableVddUSB();
  476. __HAL_RCC_PWR_CLK_DISABLE();
  477. }
  478. else
  479. {
  480. HAL_PWREx_EnableVddUSB();
  481. }
  482. /* USB_OTG_FS interrupt Init */
  483. HAL_NVIC_SetPriority(OTG_FS_IRQn, 0, 0);
  484. HAL_NVIC_EnableIRQ(OTG_FS_IRQn);
  485. /* USER CODE BEGIN USB_OTG_FS_MspInit 1 */
  486. /* USER CODE END USB_OTG_FS_MspInit 1 */
  487. }
  488. }
  489. /**
  490. * @brief PCD MSP De-Initialization
  491. * This function freeze the hardware resources used in this example
  492. * @param hpcd: PCD handle pointer
  493. * @retval None
  494. */
  495. void HAL_PCD_MspDeInit(PCD_HandleTypeDef* hpcd)
  496. {
  497. if(hpcd->Instance==USB_OTG_FS)
  498. {
  499. /* USER CODE BEGIN USB_OTG_FS_MspDeInit 0 */
  500. /* USER CODE END USB_OTG_FS_MspDeInit 0 */
  501. /* Peripheral clock disable */
  502. __HAL_RCC_USB_CLK_DISABLE();
  503. /**USB_OTG_FS GPIO Configuration
  504. PA11 ------> USB_OTG_FS_DM
  505. PA12 ------> USB_OTG_FS_DP
  506. */
  507. HAL_GPIO_DeInit(GPIOA, USB_OTG_FS_DM_Pin|USB_OTG_FS_DP_Pin);
  508. /* USB_OTG_FS interrupt DeInit */
  509. HAL_NVIC_DisableIRQ(OTG_FS_IRQn);
  510. /* USER CODE BEGIN USB_OTG_FS_MspDeInit 1 */
  511. /* USER CODE END USB_OTG_FS_MspDeInit 1 */
  512. }
  513. }
  514. /* USER CODE BEGIN 1 */
  515. /* USER CODE END 1 */
  516. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/