stm32f4xx_hal_msp.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683
  1. /* USER CODE BEGIN Header */
  2. /**
  3. ******************************************************************************
  4. * File Name : stm32f4xx_hal_msp.c
  5. * Description : This file provides code for the MSP Initialization
  6. * and de-Initialization codes.
  7. ******************************************************************************
  8. ** This notice applies to any and all portions of this file
  9. * that are not between comment pairs USER CODE BEGIN and
  10. * USER CODE END. Other portions of this file, whether
  11. * inserted by the user or by software development tools
  12. * are owned by their respective copyright owners.
  13. *
  14. * COPYRIGHT(c) 2018 STMicroelectronics
  15. *
  16. * Redistribution and use in source and binary forms, with or without modification,
  17. * are permitted provided that the following conditions are met:
  18. * 1. Redistributions of source code must retain the above copyright notice,
  19. * this list of conditions and the following disclaimer.
  20. * 2. Redistributions in binary form must reproduce the above copyright notice,
  21. * this list of conditions and the following disclaimer in the documentation
  22. * and/or other materials provided with the distribution.
  23. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  24. * may be used to endorse or promote products derived from this software
  25. * without specific prior written permission.
  26. *
  27. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  28. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  29. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  30. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  31. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  32. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  33. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  34. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  35. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  36. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  37. *
  38. ******************************************************************************
  39. */
  40. /* USER CODE END Header */
  41. /* Includes ------------------------------------------------------------------*/
  42. #include "main.h"
  43. /* USER CODE BEGIN Includes */
  44. #include <drv_common.h>
  45. /* USER CODE END Includes */
  46. /* Private typedef -----------------------------------------------------------*/
  47. /* USER CODE BEGIN TD */
  48. /* USER CODE END TD */
  49. /* Private define ------------------------------------------------------------*/
  50. /* USER CODE BEGIN Define */
  51. /* USER CODE END Define */
  52. /* Private macro -------------------------------------------------------------*/
  53. /* USER CODE BEGIN Macro */
  54. /* USER CODE END Macro */
  55. /* Private variables ---------------------------------------------------------*/
  56. /* USER CODE BEGIN PV */
  57. /* USER CODE END PV */
  58. /* Private function prototypes -----------------------------------------------*/
  59. /* USER CODE BEGIN PFP */
  60. /* USER CODE END PFP */
  61. /* External functions --------------------------------------------------------*/
  62. /* USER CODE BEGIN ExternalFunctions */
  63. /* USER CODE END ExternalFunctions */
  64. /* USER CODE BEGIN 0 */
  65. /* USER CODE END 0 */
  66. void HAL_TIM_MspPostInit(TIM_HandleTypeDef *htim);
  67. /**
  68. * Initializes the Global MSP.
  69. */
  70. void HAL_MspInit(void)
  71. {
  72. /* USER CODE BEGIN MspInit 0 */
  73. /* USER CODE END MspInit 0 */
  74. __HAL_RCC_SYSCFG_CLK_ENABLE();
  75. __HAL_RCC_PWR_CLK_ENABLE();
  76. /* System interrupt init*/
  77. /* USER CODE BEGIN MspInit 1 */
  78. /* USER CODE END MspInit 1 */
  79. }
  80. /**
  81. * @brief ADC MSP Initialization
  82. * This function configures the hardware resources used in this example
  83. * @param hadc: ADC handle pointer
  84. * @retval None
  85. */
  86. void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc)
  87. {
  88. GPIO_InitTypeDef GPIO_InitStruct = {0};
  89. if(hadc->Instance==ADC1)
  90. {
  91. /* USER CODE BEGIN ADC1_MspInit 0 */
  92. /* USER CODE END ADC1_MspInit 0 */
  93. /* Peripheral clock enable */
  94. __HAL_RCC_ADC1_CLK_ENABLE();
  95. __HAL_RCC_GPIOA_CLK_ENABLE();
  96. /**ADC1 GPIO Configuration
  97. PA5 ------> ADC1_IN5
  98. */
  99. GPIO_InitStruct.Pin = GPIO_PIN_5;
  100. GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
  101. GPIO_InitStruct.Pull = GPIO_NOPULL;
  102. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  103. /* USER CODE BEGIN ADC1_MspInit 1 */
  104. /* USER CODE END ADC1_MspInit 1 */
  105. }
  106. }
  107. /**
  108. * @brief ADC MSP De-Initialization
  109. * This function freeze the hardware resources used in this example
  110. * @param hadc: ADC handle pointer
  111. * @retval None
  112. */
  113. void HAL_ADC_MspDeInit(ADC_HandleTypeDef* hadc)
  114. {
  115. if(hadc->Instance==ADC1)
  116. {
  117. /* USER CODE BEGIN ADC1_MspDeInit 0 */
  118. /* USER CODE END ADC1_MspDeInit 0 */
  119. /* Peripheral clock disable */
  120. __HAL_RCC_ADC1_CLK_DISABLE();
  121. /**ADC1 GPIO Configuration
  122. PA5 ------> ADC1_IN5
  123. */
  124. HAL_GPIO_DeInit(GPIOA, GPIO_PIN_5);
  125. /* USER CODE BEGIN ADC1_MspDeInit 1 */
  126. /* USER CODE END ADC1_MspDeInit 1 */
  127. }
  128. }
  129. /**
  130. * @brief I2C MSP Initialization
  131. * This function configures the hardware resources used in this example
  132. * @param hi2c: I2C handle pointer
  133. * @retval None
  134. */
  135. void HAL_I2C_MspInit(I2C_HandleTypeDef* hi2c)
  136. {
  137. GPIO_InitTypeDef GPIO_InitStruct = {0};
  138. if(hi2c->Instance==I2C1)
  139. {
  140. /* USER CODE BEGIN I2C1_MspInit 0 */
  141. /* USER CODE END I2C1_MspInit 0 */
  142. __HAL_RCC_GPIOB_CLK_ENABLE();
  143. /**I2C1 GPIO Configuration
  144. PB6 ------> I2C1_SCL
  145. PB9 ------> I2C1_SDA
  146. */
  147. GPIO_InitStruct.Pin = GPIO_PIN_6|GPIO_PIN_9;
  148. GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
  149. GPIO_InitStruct.Pull = GPIO_PULLUP;
  150. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  151. GPIO_InitStruct.Alternate = GPIO_AF4_I2C1;
  152. HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  153. /* Peripheral clock enable */
  154. __HAL_RCC_I2C1_CLK_ENABLE();
  155. /* USER CODE BEGIN I2C1_MspInit 1 */
  156. /* USER CODE END I2C1_MspInit 1 */
  157. }
  158. }
  159. /**
  160. * @brief I2C MSP De-Initialization
  161. * This function freeze the hardware resources used in this example
  162. * @param hi2c: I2C handle pointer
  163. * @retval None
  164. */
  165. void HAL_I2C_MspDeInit(I2C_HandleTypeDef* hi2c)
  166. {
  167. if(hi2c->Instance==I2C1)
  168. {
  169. /* USER CODE BEGIN I2C1_MspDeInit 0 */
  170. /* USER CODE END I2C1_MspDeInit 0 */
  171. /* Peripheral clock disable */
  172. __HAL_RCC_I2C1_CLK_DISABLE();
  173. /**I2C1 GPIO Configuration
  174. PB6 ------> I2C1_SCL
  175. PB9 ------> I2C1_SDA
  176. */
  177. HAL_GPIO_DeInit(GPIOB, GPIO_PIN_6|GPIO_PIN_9);
  178. /* USER CODE BEGIN I2C1_MspDeInit 1 */
  179. /* USER CODE END I2C1_MspDeInit 1 */
  180. }
  181. }
  182. /**
  183. * @brief RTC MSP Initialization
  184. * This function configures the hardware resources used in this example
  185. * @param hrtc: RTC handle pointer
  186. * @retval None
  187. */
  188. void HAL_RTC_MspInit(RTC_HandleTypeDef* hrtc)
  189. {
  190. if(hrtc->Instance==RTC)
  191. {
  192. /* USER CODE BEGIN RTC_MspInit 0 */
  193. /* USER CODE END RTC_MspInit 0 */
  194. /* Peripheral clock enable */
  195. __HAL_RCC_RTC_ENABLE();
  196. /* USER CODE BEGIN RTC_MspInit 1 */
  197. /* USER CODE END RTC_MspInit 1 */
  198. }
  199. }
  200. /**
  201. * @brief RTC MSP De-Initialization
  202. * This function freeze the hardware resources used in this example
  203. * @param hrtc: RTC handle pointer
  204. * @retval None
  205. */
  206. void HAL_RTC_MspDeInit(RTC_HandleTypeDef* hrtc)
  207. {
  208. if(hrtc->Instance==RTC)
  209. {
  210. /* USER CODE BEGIN RTC_MspDeInit 0 */
  211. /* USER CODE END RTC_MspDeInit 0 */
  212. /* Peripheral clock disable */
  213. __HAL_RCC_RTC_DISABLE();
  214. /* USER CODE BEGIN RTC_MspDeInit 1 */
  215. /* USER CODE END RTC_MspDeInit 1 */
  216. }
  217. }
  218. /**
  219. * @brief SPI MSP Initialization
  220. * This function configures the hardware resources used in this example
  221. * @param hspi: SPI handle pointer
  222. * @retval None
  223. */
  224. void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi)
  225. {
  226. GPIO_InitTypeDef GPIO_InitStruct = {0};
  227. if(hspi->Instance==SPI2)
  228. {
  229. /* USER CODE BEGIN SPI2_MspInit 0 */
  230. /* USER CODE END SPI2_MspInit 0 */
  231. /* Peripheral clock enable */
  232. __HAL_RCC_SPI2_CLK_ENABLE();
  233. __HAL_RCC_GPIOC_CLK_ENABLE();
  234. __HAL_RCC_GPIOB_CLK_ENABLE();
  235. /**SPI2 GPIO Configuration
  236. PC2 ------> SPI2_MISO
  237. PC3 ------> SPI2_MOSI
  238. PB10 ------> SPI2_SCK
  239. */
  240. GPIO_InitStruct.Pin = GPIO_PIN_2|GPIO_PIN_3;
  241. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  242. GPIO_InitStruct.Pull = GPIO_NOPULL;
  243. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  244. GPIO_InitStruct.Alternate = GPIO_AF5_SPI2;
  245. HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
  246. GPIO_InitStruct.Pin = GPIO_PIN_10;
  247. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  248. GPIO_InitStruct.Pull = GPIO_NOPULL;
  249. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  250. GPIO_InitStruct.Alternate = GPIO_AF5_SPI2;
  251. HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  252. /* USER CODE BEGIN SPI2_MspInit 1 */
  253. /* USER CODE END SPI2_MspInit 1 */
  254. }
  255. }
  256. /**
  257. * @brief SPI MSP De-Initialization
  258. * This function freeze the hardware resources used in this example
  259. * @param hspi: SPI handle pointer
  260. * @retval None
  261. */
  262. void HAL_SPI_MspDeInit(SPI_HandleTypeDef* hspi)
  263. {
  264. if(hspi->Instance==SPI2)
  265. {
  266. /* USER CODE BEGIN SPI2_MspDeInit 0 */
  267. /* USER CODE END SPI2_MspDeInit 0 */
  268. /* Peripheral clock disable */
  269. __HAL_RCC_SPI2_CLK_DISABLE();
  270. /**SPI2 GPIO Configuration
  271. PC2 ------> SPI2_MISO
  272. PC3 ------> SPI2_MOSI
  273. PB10 ------> SPI2_SCK
  274. */
  275. HAL_GPIO_DeInit(GPIOC, GPIO_PIN_2|GPIO_PIN_3);
  276. HAL_GPIO_DeInit(GPIOB, GPIO_PIN_10);
  277. /* USER CODE BEGIN SPI2_MspDeInit 1 */
  278. /* USER CODE END SPI2_MspDeInit 1 */
  279. }
  280. }
  281. /**
  282. * @brief TIM_Base MSP Initialization
  283. * This function configures the hardware resources used in this example
  284. * @param htim_base: TIM_Base handle pointer
  285. * @retval None
  286. */
  287. void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* htim_base)
  288. {
  289. if(htim_base->Instance==TIM2)
  290. {
  291. /* USER CODE BEGIN TIM2_MspInit 0 */
  292. /* USER CODE END TIM2_MspInit 0 */
  293. /* Peripheral clock enable */
  294. __HAL_RCC_TIM2_CLK_ENABLE();
  295. /* USER CODE BEGIN TIM2_MspInit 1 */
  296. /* USER CODE END TIM2_MspInit 1 */
  297. }
  298. else if(htim_base->Instance==TIM11)
  299. {
  300. /* USER CODE BEGIN TIM11_MspInit 0 */
  301. /* USER CODE END TIM11_MspInit 0 */
  302. /* Peripheral clock enable */
  303. __HAL_RCC_TIM11_CLK_ENABLE();
  304. /* USER CODE BEGIN TIM11_MspInit 1 */
  305. /* USER CODE END TIM11_MspInit 1 */
  306. }
  307. else if(htim_base->Instance==TIM13)
  308. {
  309. /* USER CODE BEGIN TIM13_MspInit 0 */
  310. /* USER CODE END TIM13_MspInit 0 */
  311. /* Peripheral clock enable */
  312. __HAL_RCC_TIM13_CLK_ENABLE();
  313. /* USER CODE BEGIN TIM13_MspInit 1 */
  314. /* USER CODE END TIM13_MspInit 1 */
  315. }
  316. else if(htim_base->Instance==TIM14)
  317. {
  318. /* USER CODE BEGIN TIM14_MspInit 0 */
  319. /* USER CODE END TIM14_MspInit 0 */
  320. /* Peripheral clock enable */
  321. __HAL_RCC_TIM14_CLK_ENABLE();
  322. /* USER CODE BEGIN TIM14_MspInit 1 */
  323. /* USER CODE END TIM14_MspInit 1 */
  324. }
  325. }
  326. void HAL_TIM_MspPostInit(TIM_HandleTypeDef* htim)
  327. {
  328. GPIO_InitTypeDef GPIO_InitStruct = {0};
  329. if(htim->Instance==TIM2)
  330. {
  331. /* USER CODE BEGIN TIM2_MspPostInit 0 */
  332. /* USER CODE END TIM2_MspPostInit 0 */
  333. __HAL_RCC_GPIOA_CLK_ENABLE();
  334. /**TIM2 GPIO Configuration
  335. PA3 ------> TIM2_CH4
  336. */
  337. GPIO_InitStruct.Pin = GPIO_PIN_3;
  338. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  339. GPIO_InitStruct.Pull = GPIO_NOPULL;
  340. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  341. GPIO_InitStruct.Alternate = GPIO_AF1_TIM2;
  342. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  343. /* USER CODE BEGIN TIM2_MspPostInit 1 */
  344. /* USER CODE END TIM2_MspPostInit 1 */
  345. }
  346. }
  347. /**
  348. * @brief TIM_Base MSP De-Initialization
  349. * This function freeze the hardware resources used in this example
  350. * @param htim_base: TIM_Base handle pointer
  351. * @retval None
  352. */
  353. void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* htim_base)
  354. {
  355. if(htim_base->Instance==TIM2)
  356. {
  357. /* USER CODE BEGIN TIM2_MspDeInit 0 */
  358. /* USER CODE END TIM2_MspDeInit 0 */
  359. /* Peripheral clock disable */
  360. __HAL_RCC_TIM2_CLK_DISABLE();
  361. /* USER CODE BEGIN TIM2_MspDeInit 1 */
  362. /* USER CODE END TIM2_MspDeInit 1 */
  363. }
  364. else if(htim_base->Instance==TIM11)
  365. {
  366. /* USER CODE BEGIN TIM11_MspDeInit 0 */
  367. /* USER CODE END TIM11_MspDeInit 0 */
  368. /* Peripheral clock disable */
  369. __HAL_RCC_TIM11_CLK_DISABLE();
  370. /* USER CODE BEGIN TIM11_MspDeInit 1 */
  371. /* USER CODE END TIM11_MspDeInit 1 */
  372. }
  373. else if(htim_base->Instance==TIM13)
  374. {
  375. /* USER CODE BEGIN TIM13_MspDeInit 0 */
  376. /* USER CODE END TIM13_MspDeInit 0 */
  377. /* Peripheral clock disable */
  378. __HAL_RCC_TIM13_CLK_DISABLE();
  379. /* USER CODE BEGIN TIM13_MspDeInit 1 */
  380. /* USER CODE END TIM13_MspDeInit 1 */
  381. }
  382. else if(htim_base->Instance==TIM14)
  383. {
  384. /* USER CODE BEGIN TIM14_MspDeInit 0 */
  385. /* USER CODE END TIM14_MspDeInit 0 */
  386. /* Peripheral clock disable */
  387. __HAL_RCC_TIM14_CLK_DISABLE();
  388. /* USER CODE BEGIN TIM14_MspDeInit 1 */
  389. /* USER CODE END TIM14_MspDeInit 1 */
  390. }
  391. }
  392. /**
  393. * @brief UART MSP Initialization
  394. * This function configures the hardware resources used in this example
  395. * @param huart: UART handle pointer
  396. * @retval None
  397. */
  398. void HAL_UART_MspInit(UART_HandleTypeDef* huart)
  399. {
  400. GPIO_InitTypeDef GPIO_InitStruct = {0};
  401. if(huart->Instance==USART2)
  402. {
  403. /* USER CODE BEGIN USART2_MspInit 0 */
  404. /* USER CODE END USART2_MspInit 0 */
  405. /* Peripheral clock enable */
  406. __HAL_RCC_USART2_CLK_ENABLE();
  407. __HAL_RCC_GPIOA_CLK_ENABLE();
  408. __HAL_RCC_GPIOD_CLK_ENABLE();
  409. /**USART2 GPIO Configuration
  410. PA2 ------> USART2_TX
  411. PD6 ------> USART2_RX
  412. */
  413. GPIO_InitStruct.Pin = GPIO_PIN_2;
  414. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  415. GPIO_InitStruct.Pull = GPIO_PULLUP;
  416. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  417. GPIO_InitStruct.Alternate = GPIO_AF7_USART2;
  418. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  419. GPIO_InitStruct.Pin = GPIO_PIN_6;
  420. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  421. GPIO_InitStruct.Pull = GPIO_PULLUP;
  422. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  423. GPIO_InitStruct.Alternate = GPIO_AF7_USART2;
  424. HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
  425. /* USER CODE BEGIN USART2_MspInit 1 */
  426. /* USER CODE END USART2_MspInit 1 */
  427. }
  428. else if(huart->Instance==USART3)
  429. {
  430. /* USER CODE BEGIN USART3_MspInit 0 */
  431. /* USER CODE END USART3_MspInit 0 */
  432. /* Peripheral clock enable */
  433. __HAL_RCC_USART3_CLK_ENABLE();
  434. __HAL_RCC_GPIOD_CLK_ENABLE();
  435. /**USART3 GPIO Configuration
  436. PD8 ------> USART3_TX
  437. PD9 ------> USART3_RX
  438. */
  439. GPIO_InitStruct.Pin = STLK_RX_Pin|STLK_TX_Pin;
  440. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  441. GPIO_InitStruct.Pull = GPIO_PULLUP;
  442. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  443. GPIO_InitStruct.Alternate = GPIO_AF7_USART3;
  444. HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
  445. /* USER CODE BEGIN USART3_MspInit 1 */
  446. /* USER CODE END USART3_MspInit 1 */
  447. }
  448. }
  449. /**
  450. * @brief UART MSP De-Initialization
  451. * This function freeze the hardware resources used in this example
  452. * @param huart: UART handle pointer
  453. * @retval None
  454. */
  455. void HAL_UART_MspDeInit(UART_HandleTypeDef* huart)
  456. {
  457. if(huart->Instance==USART2)
  458. {
  459. /* USER CODE BEGIN USART2_MspDeInit 0 */
  460. /* USER CODE END USART2_MspDeInit 0 */
  461. /* Peripheral clock disable */
  462. __HAL_RCC_USART2_CLK_DISABLE();
  463. /**USART2 GPIO Configuration
  464. PA2 ------> USART2_TX
  465. PD6 ------> USART2_RX
  466. */
  467. HAL_GPIO_DeInit(GPIOA, GPIO_PIN_2);
  468. HAL_GPIO_DeInit(GPIOD, GPIO_PIN_6);
  469. /* USER CODE BEGIN USART2_MspDeInit 1 */
  470. /* USER CODE END USART2_MspDeInit 1 */
  471. }
  472. else if(huart->Instance==USART3)
  473. {
  474. /* USER CODE BEGIN USART3_MspDeInit 0 */
  475. /* USER CODE END USART3_MspDeInit 0 */
  476. /* Peripheral clock disable */
  477. __HAL_RCC_USART3_CLK_DISABLE();
  478. /**USART3 GPIO Configuration
  479. PD8 ------> USART3_TX
  480. PD9 ------> USART3_RX
  481. */
  482. HAL_GPIO_DeInit(GPIOD, STLK_RX_Pin|STLK_TX_Pin);
  483. /* USER CODE BEGIN USART3_MspDeInit 1 */
  484. /* USER CODE END USART3_MspDeInit 1 */
  485. }
  486. }
  487. /**
  488. * @brief PCD MSP Initialization
  489. * This function configures the hardware resources used in this example
  490. * @param hpcd: PCD handle pointer
  491. * @retval None
  492. */
  493. void HAL_PCD_MspInit(PCD_HandleTypeDef* hpcd)
  494. {
  495. GPIO_InitTypeDef GPIO_InitStruct = {0};
  496. if(hpcd->Instance==USB_OTG_FS)
  497. {
  498. /* USER CODE BEGIN USB_OTG_FS_MspInit 0 */
  499. /* USER CODE END USB_OTG_FS_MspInit 0 */
  500. __HAL_RCC_GPIOA_CLK_ENABLE();
  501. /**USB_OTG_FS GPIO Configuration
  502. PA8 ------> USB_OTG_FS_SOF
  503. PA9 ------> USB_OTG_FS_VBUS
  504. PA10 ------> USB_OTG_FS_ID
  505. PA11 ------> USB_OTG_FS_DM
  506. PA12 ------> USB_OTG_FS_DP
  507. */
  508. GPIO_InitStruct.Pin = USB_SOF_Pin|USB_ID_Pin|USB_DM_Pin|USB_DP_Pin;
  509. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  510. GPIO_InitStruct.Pull = GPIO_NOPULL;
  511. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  512. GPIO_InitStruct.Alternate = GPIO_AF10_OTG_FS;
  513. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  514. GPIO_InitStruct.Pin = USB_VBUS_Pin;
  515. GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  516. GPIO_InitStruct.Pull = GPIO_NOPULL;
  517. HAL_GPIO_Init(USB_VBUS_GPIO_Port, &GPIO_InitStruct);
  518. /* Peripheral clock enable */
  519. __HAL_RCC_USB_OTG_FS_CLK_ENABLE();
  520. /* USER CODE BEGIN USB_OTG_FS_MspInit 1 */
  521. /* USER CODE END USB_OTG_FS_MspInit 1 */
  522. }
  523. }
  524. /**
  525. * @brief PCD MSP De-Initialization
  526. * This function freeze the hardware resources used in this example
  527. * @param hpcd: PCD handle pointer
  528. * @retval None
  529. */
  530. void HAL_PCD_MspDeInit(PCD_HandleTypeDef* hpcd)
  531. {
  532. if(hpcd->Instance==USB_OTG_FS)
  533. {
  534. /* USER CODE BEGIN USB_OTG_FS_MspDeInit 0 */
  535. /* USER CODE END USB_OTG_FS_MspDeInit 0 */
  536. /* Peripheral clock disable */
  537. __HAL_RCC_USB_OTG_FS_CLK_DISABLE();
  538. /**USB_OTG_FS GPIO Configuration
  539. PA8 ------> USB_OTG_FS_SOF
  540. PA9 ------> USB_OTG_FS_VBUS
  541. PA10 ------> USB_OTG_FS_ID
  542. PA11 ------> USB_OTG_FS_DM
  543. PA12 ------> USB_OTG_FS_DP
  544. */
  545. HAL_GPIO_DeInit(GPIOA, USB_SOF_Pin|USB_VBUS_Pin|USB_ID_Pin|USB_DM_Pin
  546. |USB_DP_Pin);
  547. /* USER CODE BEGIN USB_OTG_FS_MspDeInit 1 */
  548. /* USER CODE END USB_OTG_FS_MspDeInit 1 */
  549. }
  550. }
  551. /* USER CODE BEGIN 1 */
  552. /* USER CODE END 1 */
  553. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/