stm32f4xx_hal_msp.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641
  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. HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_0);
  77. /* System interrupt init*/
  78. /* USER CODE BEGIN MspInit 1 */
  79. /* USER CODE END MspInit 1 */
  80. }
  81. /**
  82. * @brief ADC MSP Initialization
  83. * This function configures the hardware resources used in this example
  84. * @param hadc: ADC handle pointer
  85. * @retval None
  86. */
  87. void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc)
  88. {
  89. GPIO_InitTypeDef GPIO_InitStruct = {0};
  90. if(hadc->Instance==ADC1)
  91. {
  92. /* USER CODE BEGIN ADC1_MspInit 0 */
  93. /* USER CODE END ADC1_MspInit 0 */
  94. /* Peripheral clock enable */
  95. __HAL_RCC_ADC1_CLK_ENABLE();
  96. __HAL_RCC_GPIOC_CLK_ENABLE();
  97. __HAL_RCC_GPIOA_CLK_ENABLE();
  98. __HAL_RCC_GPIOB_CLK_ENABLE();
  99. /**ADC1 GPIO Configuration
  100. PC0 ------> ADC1_IN10
  101. PC1 ------> ADC1_IN11
  102. PA0-WKUP ------> ADC1_IN0
  103. PA1 ------> ADC1_IN1
  104. PA4 ------> ADC1_IN4
  105. PB0 ------> ADC1_IN8
  106. */
  107. GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1;
  108. GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
  109. GPIO_InitStruct.Pull = GPIO_NOPULL;
  110. HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
  111. GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_4;
  112. GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
  113. GPIO_InitStruct.Pull = GPIO_NOPULL;
  114. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  115. GPIO_InitStruct.Pin = GPIO_PIN_0;
  116. GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
  117. GPIO_InitStruct.Pull = GPIO_NOPULL;
  118. HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  119. /* USER CODE BEGIN ADC1_MspInit 1 */
  120. /* USER CODE END ADC1_MspInit 1 */
  121. }
  122. }
  123. /**
  124. * @brief ADC MSP De-Initialization
  125. * This function freeze the hardware resources used in this example
  126. * @param hadc: ADC handle pointer
  127. * @retval None
  128. */
  129. void HAL_ADC_MspDeInit(ADC_HandleTypeDef* hadc)
  130. {
  131. if(hadc->Instance==ADC1)
  132. {
  133. /* USER CODE BEGIN ADC1_MspDeInit 0 */
  134. /* USER CODE END ADC1_MspDeInit 0 */
  135. /* Peripheral clock disable */
  136. __HAL_RCC_ADC1_CLK_DISABLE();
  137. /**ADC1 GPIO Configuration
  138. PC0 ------> ADC1_IN10
  139. PC1 ------> ADC1_IN11
  140. PA0-WKUP ------> ADC1_IN0
  141. PA1 ------> ADC1_IN1
  142. PA4 ------> ADC1_IN4
  143. PB0 ------> ADC1_IN8
  144. */
  145. HAL_GPIO_DeInit(GPIOC, GPIO_PIN_0|GPIO_PIN_1);
  146. HAL_GPIO_DeInit(GPIOA, GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_4);
  147. HAL_GPIO_DeInit(GPIOB, GPIO_PIN_0);
  148. /* USER CODE BEGIN ADC1_MspDeInit 1 */
  149. /* USER CODE END ADC1_MspDeInit 1 */
  150. }
  151. }
  152. /**
  153. * @brief RTC MSP Initialization
  154. * This function configures the hardware resources used in this example
  155. * @param hrtc: RTC handle pointer
  156. * @retval None
  157. */
  158. void HAL_RTC_MspInit(RTC_HandleTypeDef* hrtc)
  159. {
  160. RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
  161. if(hrtc->Instance==RTC)
  162. {
  163. /* USER CODE BEGIN RTC_MspInit 0 */
  164. /* USER CODE END RTC_MspInit 0 */
  165. /** Initializes the peripherals clock
  166. */
  167. PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_RTC;
  168. PeriphClkInitStruct.RTCClockSelection = RCC_RTCCLKSOURCE_LSI;
  169. if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
  170. {
  171. Error_Handler();
  172. }
  173. /* Peripheral clock enable */
  174. __HAL_RCC_RTC_ENABLE();
  175. /* USER CODE BEGIN RTC_MspInit 1 */
  176. /* USER CODE END RTC_MspInit 1 */
  177. }
  178. }
  179. /**
  180. * @brief RTC MSP De-Initialization
  181. * This function freeze the hardware resources used in this example
  182. * @param hrtc: RTC handle pointer
  183. * @retval None
  184. */
  185. void HAL_RTC_MspDeInit(RTC_HandleTypeDef* hrtc)
  186. {
  187. if(hrtc->Instance==RTC)
  188. {
  189. /* USER CODE BEGIN RTC_MspDeInit 0 */
  190. /* USER CODE END RTC_MspDeInit 0 */
  191. /* Peripheral clock disable */
  192. __HAL_RCC_RTC_DISABLE();
  193. /* USER CODE BEGIN RTC_MspDeInit 1 */
  194. /* USER CODE END RTC_MspDeInit 1 */
  195. }
  196. }
  197. /**
  198. * @brief SPI MSP Initialization
  199. * This function configures the hardware resources used in this example
  200. * @param hspi: SPI handle pointer
  201. * @retval None
  202. */
  203. void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi)
  204. {
  205. GPIO_InitTypeDef GPIO_InitStruct = {0};
  206. if(hspi->Instance==SPI3)
  207. {
  208. /* USER CODE BEGIN SPI3_MspInit 0 */
  209. /* USER CODE END SPI3_MspInit 0 */
  210. /* Peripheral clock enable */
  211. __HAL_RCC_SPI3_CLK_ENABLE();
  212. __HAL_RCC_GPIOB_CLK_ENABLE();
  213. __HAL_RCC_GPIOC_CLK_ENABLE();
  214. /**SPI3 GPIO Configuration
  215. PB12 ------> SPI3_SCK
  216. PC11 ------> SPI3_MISO
  217. PC12 ------> SPI3_MOSI
  218. */
  219. GPIO_InitStruct.Pin = GPIO_PIN_12;
  220. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  221. GPIO_InitStruct.Pull = GPIO_NOPULL;
  222. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  223. GPIO_InitStruct.Alternate = GPIO_AF7_SPI3;
  224. HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  225. GPIO_InitStruct.Pin = GPIO_PIN_11|GPIO_PIN_12;
  226. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  227. GPIO_InitStruct.Pull = GPIO_NOPULL;
  228. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  229. GPIO_InitStruct.Alternate = GPIO_AF6_SPI3;
  230. HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
  231. /* USER CODE BEGIN SPI3_MspInit 1 */
  232. /* USER CODE END SPI3_MspInit 1 */
  233. }
  234. }
  235. /**
  236. * @brief SPI MSP De-Initialization
  237. * This function freeze the hardware resources used in this example
  238. * @param hspi: SPI handle pointer
  239. * @retval None
  240. */
  241. void HAL_SPI_MspDeInit(SPI_HandleTypeDef* hspi)
  242. {
  243. if(hspi->Instance==SPI3)
  244. {
  245. /* USER CODE BEGIN SPI3_MspDeInit 0 */
  246. /* USER CODE END SPI3_MspDeInit 0 */
  247. /* Peripheral clock disable */
  248. __HAL_RCC_SPI3_CLK_DISABLE();
  249. /**SPI3 GPIO Configuration
  250. PB12 ------> SPI3_SCK
  251. PC11 ------> SPI3_MISO
  252. PC12 ------> SPI3_MOSI
  253. */
  254. HAL_GPIO_DeInit(GPIOB, GPIO_PIN_12);
  255. HAL_GPIO_DeInit(GPIOC, GPIO_PIN_11|GPIO_PIN_12);
  256. /* USER CODE BEGIN SPI3_MspDeInit 1 */
  257. /* USER CODE END SPI3_MspDeInit 1 */
  258. }
  259. }
  260. /**
  261. * @brief TIM_Base MSP Initialization
  262. * This function configures the hardware resources used in this example
  263. * @param htim_base: TIM_Base handle pointer
  264. * @retval None
  265. */
  266. void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* htim_base)
  267. {
  268. if(htim_base->Instance==TIM1)
  269. {
  270. /* USER CODE BEGIN TIM1_MspInit 0 */
  271. /* USER CODE END TIM1_MspInit 0 */
  272. /* Peripheral clock enable */
  273. __HAL_RCC_TIM1_CLK_ENABLE();
  274. /* USER CODE BEGIN TIM1_MspInit 1 */
  275. /* USER CODE END TIM1_MspInit 1 */
  276. }
  277. else if(htim_base->Instance==TIM2)
  278. {
  279. /* USER CODE BEGIN TIM2_MspInit 0 */
  280. /* USER CODE END TIM2_MspInit 0 */
  281. /* Peripheral clock enable */
  282. __HAL_RCC_TIM2_CLK_ENABLE();
  283. /* USER CODE BEGIN TIM2_MspInit 1 */
  284. /* USER CODE END TIM2_MspInit 1 */
  285. }
  286. else if(htim_base->Instance==TIM3)
  287. {
  288. /* USER CODE BEGIN TIM3_MspInit 0 */
  289. /* USER CODE END TIM3_MspInit 0 */
  290. /* Peripheral clock enable */
  291. __HAL_RCC_TIM3_CLK_ENABLE();
  292. /* USER CODE BEGIN TIM3_MspInit 1 */
  293. /* USER CODE END TIM3_MspInit 1 */
  294. }
  295. else if(htim_base->Instance==TIM4)
  296. {
  297. /* USER CODE BEGIN TIM4_MspInit 0 */
  298. /* USER CODE END TIM4_MspInit 0 */
  299. /* Peripheral clock enable */
  300. __HAL_RCC_TIM4_CLK_ENABLE();
  301. /* USER CODE BEGIN TIM4_MspInit 1 */
  302. /* USER CODE END TIM4_MspInit 1 */
  303. }
  304. }
  305. void HAL_TIM_MspPostInit(TIM_HandleTypeDef* htim)
  306. {
  307. GPIO_InitTypeDef GPIO_InitStruct = {0};
  308. if(htim->Instance==TIM1)
  309. {
  310. /* USER CODE BEGIN TIM1_MspPostInit 0 */
  311. /* USER CODE END TIM1_MspPostInit 0 */
  312. __HAL_RCC_GPIOA_CLK_ENABLE();
  313. /**TIM1 GPIO Configuration
  314. PA7 ------> TIM1_CH1N
  315. */
  316. GPIO_InitStruct.Pin = GPIO_PIN_7;
  317. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  318. GPIO_InitStruct.Pull = GPIO_NOPULL;
  319. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  320. GPIO_InitStruct.Alternate = GPIO_AF1_TIM1;
  321. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  322. /* USER CODE BEGIN TIM1_MspPostInit 1 */
  323. /* USER CODE END TIM1_MspPostInit 1 */
  324. }
  325. else if(htim->Instance==TIM2)
  326. {
  327. /* USER CODE BEGIN TIM2_MspPostInit 0 */
  328. /* USER CODE END TIM2_MspPostInit 0 */
  329. __HAL_RCC_GPIOB_CLK_ENABLE();
  330. /**TIM2 GPIO Configuration
  331. PB10 ------> TIM2_CH3
  332. PB3 ------> TIM2_CH2
  333. */
  334. GPIO_InitStruct.Pin = GPIO_PIN_10|GPIO_PIN_3;
  335. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  336. GPIO_InitStruct.Pull = GPIO_NOPULL;
  337. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  338. GPIO_InitStruct.Alternate = GPIO_AF1_TIM2;
  339. HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  340. /* USER CODE BEGIN TIM2_MspPostInit 1 */
  341. /* USER CODE END TIM2_MspPostInit 1 */
  342. }
  343. else if(htim->Instance==TIM3)
  344. {
  345. /* USER CODE BEGIN TIM3_MspPostInit 0 */
  346. /* USER CODE END TIM3_MspPostInit 0 */
  347. __HAL_RCC_GPIOB_CLK_ENABLE();
  348. __HAL_RCC_GPIOC_CLK_ENABLE();
  349. /**TIM3 GPIO Configuration
  350. PB1 ------> TIM3_CH4
  351. PC7 ------> TIM3_CH2
  352. PB4 ------> TIM3_CH1
  353. */
  354. GPIO_InitStruct.Pin = GPIO_PIN_1|GPIO_PIN_4;
  355. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  356. GPIO_InitStruct.Pull = GPIO_NOPULL;
  357. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  358. GPIO_InitStruct.Alternate = GPIO_AF2_TIM3;
  359. HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  360. GPIO_InitStruct.Pin = GPIO_PIN_7;
  361. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  362. GPIO_InitStruct.Pull = GPIO_NOPULL;
  363. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  364. GPIO_InitStruct.Alternate = GPIO_AF2_TIM3;
  365. HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
  366. /* USER CODE BEGIN TIM3_MspPostInit 1 */
  367. /* USER CODE END TIM3_MspPostInit 1 */
  368. }
  369. else if(htim->Instance==TIM4)
  370. {
  371. /* USER CODE BEGIN TIM4_MspPostInit 0 */
  372. /* USER CODE END TIM4_MspPostInit 0 */
  373. __HAL_RCC_GPIOB_CLK_ENABLE();
  374. /**TIM4 GPIO Configuration
  375. PB6 ------> TIM4_CH1
  376. */
  377. GPIO_InitStruct.Pin = GPIO_PIN_6;
  378. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  379. GPIO_InitStruct.Pull = GPIO_NOPULL;
  380. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  381. GPIO_InitStruct.Alternate = GPIO_AF2_TIM4;
  382. HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  383. /* USER CODE BEGIN TIM4_MspPostInit 1 */
  384. /* USER CODE END TIM4_MspPostInit 1 */
  385. }
  386. }
  387. /**
  388. * @brief TIM_Base MSP De-Initialization
  389. * This function freeze the hardware resources used in this example
  390. * @param htim_base: TIM_Base handle pointer
  391. * @retval None
  392. */
  393. void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* htim_base)
  394. {
  395. if(htim_base->Instance==TIM1)
  396. {
  397. /* USER CODE BEGIN TIM1_MspDeInit 0 */
  398. /* USER CODE END TIM1_MspDeInit 0 */
  399. /* Peripheral clock disable */
  400. __HAL_RCC_TIM1_CLK_DISABLE();
  401. /* USER CODE BEGIN TIM1_MspDeInit 1 */
  402. /* USER CODE END TIM1_MspDeInit 1 */
  403. }
  404. else if(htim_base->Instance==TIM2)
  405. {
  406. /* USER CODE BEGIN TIM2_MspDeInit 0 */
  407. /* USER CODE END TIM2_MspDeInit 0 */
  408. /* Peripheral clock disable */
  409. __HAL_RCC_TIM2_CLK_DISABLE();
  410. /* USER CODE BEGIN TIM2_MspDeInit 1 */
  411. /* USER CODE END TIM2_MspDeInit 1 */
  412. }
  413. else if(htim_base->Instance==TIM3)
  414. {
  415. /* USER CODE BEGIN TIM3_MspDeInit 0 */
  416. /* USER CODE END TIM3_MspDeInit 0 */
  417. /* Peripheral clock disable */
  418. __HAL_RCC_TIM3_CLK_DISABLE();
  419. /* USER CODE BEGIN TIM3_MspDeInit 1 */
  420. /* USER CODE END TIM3_MspDeInit 1 */
  421. }
  422. else if(htim_base->Instance==TIM4)
  423. {
  424. /* USER CODE BEGIN TIM4_MspDeInit 0 */
  425. /* USER CODE END TIM4_MspDeInit 0 */
  426. /* Peripheral clock disable */
  427. __HAL_RCC_TIM4_CLK_DISABLE();
  428. /* USER CODE BEGIN TIM4_MspDeInit 1 */
  429. /* USER CODE END TIM4_MspDeInit 1 */
  430. }
  431. }
  432. /**
  433. * @brief UART MSP Initialization
  434. * This function configures the hardware resources used in this example
  435. * @param huart: UART handle pointer
  436. * @retval None
  437. */
  438. void HAL_UART_MspInit(UART_HandleTypeDef* huart)
  439. {
  440. GPIO_InitTypeDef GPIO_InitStruct = {0};
  441. if(huart->Instance==USART2)
  442. {
  443. /* USER CODE BEGIN USART2_MspInit 0 */
  444. /* USER CODE END USART2_MspInit 0 */
  445. /* Peripheral clock enable */
  446. __HAL_RCC_USART2_CLK_ENABLE();
  447. __HAL_RCC_GPIOA_CLK_ENABLE();
  448. /**USART2 GPIO Configuration
  449. PA2 ------> USART2_TX
  450. PA3 ------> USART2_RX
  451. */
  452. GPIO_InitStruct.Pin = GPIO_PIN_2|GPIO_PIN_3;
  453. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  454. GPIO_InitStruct.Pull = GPIO_NOPULL;
  455. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  456. GPIO_InitStruct.Alternate = GPIO_AF7_USART2;
  457. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  458. /* USER CODE BEGIN USART2_MspInit 1 */
  459. /* USER CODE END USART2_MspInit 1 */
  460. }
  461. else if(huart->Instance==USART6)
  462. {
  463. /* USER CODE BEGIN USART6_MspInit 0 */
  464. /* USER CODE END USART6_MspInit 0 */
  465. /* Peripheral clock enable */
  466. __HAL_RCC_USART6_CLK_ENABLE();
  467. __HAL_RCC_GPIOA_CLK_ENABLE();
  468. /**USART6 GPIO Configuration
  469. PA11 ------> USART6_TX
  470. PA12 ------> USART6_RX
  471. */
  472. GPIO_InitStruct.Pin = GPIO_PIN_11|GPIO_PIN_12;
  473. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  474. GPIO_InitStruct.Pull = GPIO_NOPULL;
  475. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  476. GPIO_InitStruct.Alternate = GPIO_AF8_USART6;
  477. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  478. /* USER CODE BEGIN USART6_MspInit 1 */
  479. /* USER CODE END USART6_MspInit 1 */
  480. }
  481. }
  482. /**
  483. * @brief UART MSP De-Initialization
  484. * This function freeze the hardware resources used in this example
  485. * @param huart: UART handle pointer
  486. * @retval None
  487. */
  488. void HAL_UART_MspDeInit(UART_HandleTypeDef* huart)
  489. {
  490. if(huart->Instance==USART2)
  491. {
  492. /* USER CODE BEGIN USART2_MspDeInit 0 */
  493. /* USER CODE END USART2_MspDeInit 0 */
  494. /* Peripheral clock disable */
  495. __HAL_RCC_USART2_CLK_DISABLE();
  496. /**USART2 GPIO Configuration
  497. PA2 ------> USART2_TX
  498. PA3 ------> USART2_RX
  499. */
  500. HAL_GPIO_DeInit(GPIOA, GPIO_PIN_2|GPIO_PIN_3);
  501. /* USER CODE BEGIN USART2_MspDeInit 1 */
  502. /* USER CODE END USART2_MspDeInit 1 */
  503. }
  504. else if(huart->Instance==USART6)
  505. {
  506. /* USER CODE BEGIN USART6_MspDeInit 0 */
  507. /* USER CODE END USART6_MspDeInit 0 */
  508. /* Peripheral clock disable */
  509. __HAL_RCC_USART6_CLK_DISABLE();
  510. /**USART6 GPIO Configuration
  511. PA11 ------> USART6_TX
  512. PA12 ------> USART6_RX
  513. */
  514. HAL_GPIO_DeInit(GPIOA, GPIO_PIN_11|GPIO_PIN_12);
  515. /* USER CODE BEGIN USART6_MspDeInit 1 */
  516. /* USER CODE END USART6_MspDeInit 1 */
  517. }
  518. }
  519. /* USER CODE BEGIN 1 */
  520. /* USER CODE END 1 */