stm32h7xx_hal_msp.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643
  1. /* USER CODE BEGIN Header */
  2. /**
  3. ******************************************************************************
  4. * @file stm32h7xx_hal_msp.c
  5. * @brief This file provides code for the MSP Initialization
  6. * and de-Initialization codes.
  7. ******************************************************************************
  8. * @attention
  9. *
  10. * Copyright (c) 2023 STMicroelectronics.
  11. * All rights reserved.
  12. *
  13. * This software is licensed under terms that can be found in the LICENSE file
  14. * in the root directory of this software component.
  15. * If no LICENSE file comes with this software, it is provided AS-IS.
  16. *
  17. ******************************************************************************
  18. */
  19. /* USER CODE END Header */
  20. /* Includes ------------------------------------------------------------------*/
  21. #include "main.h"
  22. /* USER CODE BEGIN Includes */
  23. #include "drv_common.h"
  24. /* USER CODE END Includes */
  25. /* Private typedef -----------------------------------------------------------*/
  26. /* USER CODE BEGIN TD */
  27. /* USER CODE END TD */
  28. /* Private define ------------------------------------------------------------*/
  29. /* USER CODE BEGIN Define */
  30. /* USER CODE END Define */
  31. /* Private macro -------------------------------------------------------------*/
  32. /* USER CODE BEGIN Macro */
  33. /* USER CODE END Macro */
  34. /* Private variables ---------------------------------------------------------*/
  35. /* USER CODE BEGIN PV */
  36. /* USER CODE END PV */
  37. /* Private function prototypes -----------------------------------------------*/
  38. /* USER CODE BEGIN PFP */
  39. /* USER CODE END PFP */
  40. /* External functions --------------------------------------------------------*/
  41. /* USER CODE BEGIN ExternalFunctions */
  42. /* USER CODE END ExternalFunctions */
  43. /* USER CODE BEGIN 0 */
  44. /* USER CODE END 0 */
  45. /**
  46. * Initializes the Global MSP.
  47. */
  48. void HAL_MspInit(void)
  49. {
  50. /* USER CODE BEGIN MspInit 0 */
  51. /* USER CODE END MspInit 0 */
  52. __HAL_RCC_SYSCFG_CLK_ENABLE();
  53. /* System interrupt init*/
  54. /* USER CODE BEGIN MspInit 1 */
  55. /* USER CODE END MspInit 1 */
  56. }
  57. /**
  58. * @brief DCMI MSP Initialization
  59. * This function configures the hardware resources used in this example
  60. * @param hdcmi: DCMI handle pointer
  61. * @retval None
  62. */
  63. void HAL_DCMI_MspInit(DCMI_HandleTypeDef* hdcmi)
  64. {
  65. GPIO_InitTypeDef GPIO_InitStruct = {0};
  66. if(hdcmi->Instance==DCMI)
  67. {
  68. /* USER CODE BEGIN DCMI_MspInit 0 */
  69. /* USER CODE END DCMI_MspInit 0 */
  70. /* Peripheral clock enable */
  71. __HAL_RCC_DCMI_CLK_ENABLE();
  72. __HAL_RCC_GPIOE_CLK_ENABLE();
  73. __HAL_RCC_GPIOA_CLK_ENABLE();
  74. __HAL_RCC_GPIOC_CLK_ENABLE();
  75. __HAL_RCC_GPIOD_CLK_ENABLE();
  76. __HAL_RCC_GPIOB_CLK_ENABLE();
  77. /**DCMI GPIO Configuration
  78. PE4 ------> DCMI_D4
  79. PE5 ------> DCMI_D6
  80. PE6 ------> DCMI_D7
  81. PA4 ------> DCMI_HSYNC
  82. PA6 ------> DCMI_PIXCLK
  83. PC6 ------> DCMI_D0
  84. PC7 ------> DCMI_D1
  85. PD3 ------> DCMI_D5
  86. PB7 ------> DCMI_VSYNC
  87. PE0 ------> DCMI_D2
  88. PE1 ------> DCMI_D3
  89. */
  90. GPIO_InitStruct.Pin = GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_0
  91. |GPIO_PIN_1;
  92. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  93. GPIO_InitStruct.Pull = GPIO_NOPULL;
  94. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  95. GPIO_InitStruct.Alternate = GPIO_AF13_DCMI;
  96. HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
  97. GPIO_InitStruct.Pin = GPIO_PIN_4|GPIO_PIN_6;
  98. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  99. GPIO_InitStruct.Pull = GPIO_NOPULL;
  100. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  101. GPIO_InitStruct.Alternate = GPIO_AF13_DCMI;
  102. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  103. GPIO_InitStruct.Pin = GPIO_PIN_6|GPIO_PIN_7;
  104. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  105. GPIO_InitStruct.Pull = GPIO_NOPULL;
  106. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  107. GPIO_InitStruct.Alternate = GPIO_AF13_DCMI;
  108. HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
  109. GPIO_InitStruct.Pin = GPIO_PIN_3;
  110. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  111. GPIO_InitStruct.Pull = GPIO_NOPULL;
  112. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  113. GPIO_InitStruct.Alternate = GPIO_AF13_DCMI;
  114. HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
  115. GPIO_InitStruct.Pin = GPIO_PIN_7;
  116. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  117. GPIO_InitStruct.Pull = GPIO_NOPULL;
  118. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  119. GPIO_InitStruct.Alternate = GPIO_AF13_DCMI;
  120. HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  121. /* DCMI interrupt Init */
  122. HAL_NVIC_SetPriority(DCMI_IRQn, 0, 0);
  123. HAL_NVIC_EnableIRQ(DCMI_IRQn);
  124. /* USER CODE BEGIN DCMI_MspInit 1 */
  125. /* USER CODE END DCMI_MspInit 1 */
  126. }
  127. }
  128. /**
  129. * @brief DCMI MSP De-Initialization
  130. * This function freeze the hardware resources used in this example
  131. * @param hdcmi: DCMI handle pointer
  132. * @retval None
  133. */
  134. void HAL_DCMI_MspDeInit(DCMI_HandleTypeDef* hdcmi)
  135. {
  136. if(hdcmi->Instance==DCMI)
  137. {
  138. /* USER CODE BEGIN DCMI_MspDeInit 0 */
  139. /* USER CODE END DCMI_MspDeInit 0 */
  140. /* Peripheral clock disable */
  141. __HAL_RCC_DCMI_CLK_DISABLE();
  142. /**DCMI GPIO Configuration
  143. PE4 ------> DCMI_D4
  144. PE5 ------> DCMI_D6
  145. PE6 ------> DCMI_D7
  146. PA4 ------> DCMI_HSYNC
  147. PA6 ------> DCMI_PIXCLK
  148. PC6 ------> DCMI_D0
  149. PC7 ------> DCMI_D1
  150. PD3 ------> DCMI_D5
  151. PB7 ------> DCMI_VSYNC
  152. PE0 ------> DCMI_D2
  153. PE1 ------> DCMI_D3
  154. */
  155. HAL_GPIO_DeInit(GPIOE, GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_0
  156. |GPIO_PIN_1);
  157. HAL_GPIO_DeInit(GPIOA, GPIO_PIN_4|GPIO_PIN_6);
  158. HAL_GPIO_DeInit(GPIOC, GPIO_PIN_6|GPIO_PIN_7);
  159. HAL_GPIO_DeInit(GPIOD, GPIO_PIN_3);
  160. HAL_GPIO_DeInit(GPIOB, GPIO_PIN_7);
  161. /* DCMI interrupt DeInit */
  162. HAL_NVIC_DisableIRQ(DCMI_IRQn);
  163. /* USER CODE BEGIN DCMI_MspDeInit 1 */
  164. /* USER CODE END DCMI_MspDeInit 1 */
  165. }
  166. }
  167. /**
  168. * @brief QSPI MSP Initialization
  169. * This function configures the hardware resources used in this example
  170. * @param hqspi: QSPI handle pointer
  171. * @retval None
  172. */
  173. void HAL_QSPI_MspInit(QSPI_HandleTypeDef* hqspi)
  174. {
  175. GPIO_InitTypeDef GPIO_InitStruct = {0};
  176. RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
  177. if(hqspi->Instance==QUADSPI)
  178. {
  179. /* USER CODE BEGIN QUADSPI_MspInit 0 */
  180. /* USER CODE END QUADSPI_MspInit 0 */
  181. /** Initializes the peripherals clock
  182. */
  183. PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_QSPI;
  184. PeriphClkInitStruct.QspiClockSelection = RCC_QSPICLKSOURCE_D1HCLK;
  185. if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
  186. {
  187. Error_Handler();
  188. }
  189. /* Peripheral clock enable */
  190. __HAL_RCC_QSPI_CLK_ENABLE();
  191. __HAL_RCC_GPIOE_CLK_ENABLE();
  192. __HAL_RCC_GPIOB_CLK_ENABLE();
  193. __HAL_RCC_GPIOD_CLK_ENABLE();
  194. /**QUADSPI GPIO Configuration
  195. PE2 ------> QUADSPI_BK1_IO2
  196. PB2 ------> QUADSPI_CLK
  197. PD11 ------> QUADSPI_BK1_IO0
  198. PD12 ------> QUADSPI_BK1_IO1
  199. PD13 ------> QUADSPI_BK1_IO3
  200. PB6 ------> QUADSPI_BK1_NCS
  201. */
  202. GPIO_InitStruct.Pin = GPIO_PIN_2;
  203. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  204. GPIO_InitStruct.Pull = GPIO_NOPULL;
  205. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  206. GPIO_InitStruct.Alternate = GPIO_AF9_QUADSPI;
  207. HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
  208. GPIO_InitStruct.Pin = GPIO_PIN_2;
  209. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  210. GPIO_InitStruct.Pull = GPIO_NOPULL;
  211. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  212. GPIO_InitStruct.Alternate = GPIO_AF9_QUADSPI;
  213. HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  214. GPIO_InitStruct.Pin = GPIO_PIN_11|GPIO_PIN_12|GPIO_PIN_13;
  215. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  216. GPIO_InitStruct.Pull = GPIO_NOPULL;
  217. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  218. GPIO_InitStruct.Alternate = GPIO_AF9_QUADSPI;
  219. HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
  220. GPIO_InitStruct.Pin = GPIO_PIN_6;
  221. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  222. GPIO_InitStruct.Pull = GPIO_NOPULL;
  223. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  224. GPIO_InitStruct.Alternate = GPIO_AF10_QUADSPI;
  225. HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  226. /* USER CODE BEGIN QUADSPI_MspInit 1 */
  227. /* USER CODE END QUADSPI_MspInit 1 */
  228. }
  229. }
  230. /**
  231. * @brief QSPI MSP De-Initialization
  232. * This function freeze the hardware resources used in this example
  233. * @param hqspi: QSPI handle pointer
  234. * @retval None
  235. */
  236. void HAL_QSPI_MspDeInit(QSPI_HandleTypeDef* hqspi)
  237. {
  238. if(hqspi->Instance==QUADSPI)
  239. {
  240. /* USER CODE BEGIN QUADSPI_MspDeInit 0 */
  241. /* USER CODE END QUADSPI_MspDeInit 0 */
  242. /* Peripheral clock disable */
  243. __HAL_RCC_QSPI_CLK_DISABLE();
  244. /**QUADSPI GPIO Configuration
  245. PE2 ------> QUADSPI_BK1_IO2
  246. PB2 ------> QUADSPI_CLK
  247. PD11 ------> QUADSPI_BK1_IO0
  248. PD12 ------> QUADSPI_BK1_IO1
  249. PD13 ------> QUADSPI_BK1_IO3
  250. PB6 ------> QUADSPI_BK1_NCS
  251. */
  252. HAL_GPIO_DeInit(GPIOE, GPIO_PIN_2);
  253. HAL_GPIO_DeInit(GPIOB, GPIO_PIN_2|GPIO_PIN_6);
  254. HAL_GPIO_DeInit(GPIOD, GPIO_PIN_11|GPIO_PIN_12|GPIO_PIN_13);
  255. /* USER CODE BEGIN QUADSPI_MspDeInit 1 */
  256. /* USER CODE END QUADSPI_MspDeInit 1 */
  257. }
  258. }
  259. /**
  260. * @brief RTC MSP Initialization
  261. * This function configures the hardware resources used in this example
  262. * @param hrtc: RTC handle pointer
  263. * @retval None
  264. */
  265. void HAL_RTC_MspInit(RTC_HandleTypeDef* hrtc)
  266. {
  267. RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
  268. if(hrtc->Instance==RTC)
  269. {
  270. /* USER CODE BEGIN RTC_MspInit 0 */
  271. /* USER CODE END RTC_MspInit 0 */
  272. /** Initializes the peripherals clock
  273. */
  274. PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_RTC;
  275. PeriphClkInitStruct.RTCClockSelection = RCC_RTCCLKSOURCE_LSE;
  276. if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
  277. {
  278. Error_Handler();
  279. }
  280. /* Peripheral clock enable */
  281. __HAL_RCC_RTC_ENABLE();
  282. /* USER CODE BEGIN RTC_MspInit 1 */
  283. /* USER CODE END RTC_MspInit 1 */
  284. }
  285. }
  286. /**
  287. * @brief RTC MSP De-Initialization
  288. * This function freeze the hardware resources used in this example
  289. * @param hrtc: RTC handle pointer
  290. * @retval None
  291. */
  292. void HAL_RTC_MspDeInit(RTC_HandleTypeDef* hrtc)
  293. {
  294. if(hrtc->Instance==RTC)
  295. {
  296. /* USER CODE BEGIN RTC_MspDeInit 0 */
  297. /* USER CODE END RTC_MspDeInit 0 */
  298. /* Peripheral clock disable */
  299. __HAL_RCC_RTC_DISABLE();
  300. /* USER CODE BEGIN RTC_MspDeInit 1 */
  301. /* USER CODE END RTC_MspDeInit 1 */
  302. }
  303. }
  304. /**
  305. * @brief SD MSP Initialization
  306. * This function configures the hardware resources used in this example
  307. * @param hsd: SD handle pointer
  308. * @retval None
  309. */
  310. void HAL_SD_MspInit(SD_HandleTypeDef* hsd)
  311. {
  312. GPIO_InitTypeDef GPIO_InitStruct = {0};
  313. RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
  314. if(hsd->Instance==SDMMC1)
  315. {
  316. /* USER CODE BEGIN SDMMC1_MspInit 0 */
  317. /* USER CODE END SDMMC1_MspInit 0 */
  318. /** Initializes the peripherals clock
  319. */
  320. PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_SDMMC;
  321. PeriphClkInitStruct.SdmmcClockSelection = RCC_SDMMCCLKSOURCE_PLL;
  322. if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
  323. {
  324. Error_Handler();
  325. }
  326. /* Peripheral clock enable */
  327. __HAL_RCC_SDMMC1_CLK_ENABLE();
  328. __HAL_RCC_GPIOC_CLK_ENABLE();
  329. __HAL_RCC_GPIOD_CLK_ENABLE();
  330. /**SDMMC1 GPIO Configuration
  331. PC8 ------> SDMMC1_D0
  332. PC9 ------> SDMMC1_D1
  333. PC10 ------> SDMMC1_D2
  334. PC11 ------> SDMMC1_D3
  335. PC12 ------> SDMMC1_CK
  336. PD2 ------> SDMMC1_CMD
  337. */
  338. GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_11
  339. |GPIO_PIN_12;
  340. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  341. GPIO_InitStruct.Pull = GPIO_NOPULL;
  342. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  343. GPIO_InitStruct.Alternate = GPIO_AF12_SDIO1;
  344. HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
  345. GPIO_InitStruct.Pin = GPIO_PIN_2;
  346. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  347. GPIO_InitStruct.Pull = GPIO_NOPULL;
  348. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  349. GPIO_InitStruct.Alternate = GPIO_AF12_SDIO1;
  350. HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
  351. /* SDMMC1 interrupt Init */
  352. HAL_NVIC_SetPriority(SDMMC1_IRQn, 0, 0);
  353. HAL_NVIC_EnableIRQ(SDMMC1_IRQn);
  354. /* USER CODE BEGIN SDMMC1_MspInit 1 */
  355. /* USER CODE END SDMMC1_MspInit 1 */
  356. }
  357. }
  358. /**
  359. * @brief SD MSP De-Initialization
  360. * This function freeze the hardware resources used in this example
  361. * @param hsd: SD handle pointer
  362. * @retval None
  363. */
  364. void HAL_SD_MspDeInit(SD_HandleTypeDef* hsd)
  365. {
  366. if(hsd->Instance==SDMMC1)
  367. {
  368. /* USER CODE BEGIN SDMMC1_MspDeInit 0 */
  369. /* USER CODE END SDMMC1_MspDeInit 0 */
  370. /* Peripheral clock disable */
  371. __HAL_RCC_SDMMC1_CLK_DISABLE();
  372. /**SDMMC1 GPIO Configuration
  373. PC8 ------> SDMMC1_D0
  374. PC9 ------> SDMMC1_D1
  375. PC10 ------> SDMMC1_D2
  376. PC11 ------> SDMMC1_D3
  377. PC12 ------> SDMMC1_CK
  378. PD2 ------> SDMMC1_CMD
  379. */
  380. HAL_GPIO_DeInit(GPIOC, GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_11
  381. |GPIO_PIN_12);
  382. HAL_GPIO_DeInit(GPIOD, GPIO_PIN_2);
  383. /* SDMMC1 interrupt DeInit */
  384. HAL_NVIC_DisableIRQ(SDMMC1_IRQn);
  385. /* USER CODE BEGIN SDMMC1_MspDeInit 1 */
  386. /* USER CODE END SDMMC1_MspDeInit 1 */
  387. }
  388. }
  389. /**
  390. * @brief SPI MSP Initialization
  391. * This function configures the hardware resources used in this example
  392. * @param hspi: SPI handle pointer
  393. * @retval None
  394. */
  395. void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi)
  396. {
  397. GPIO_InitTypeDef GPIO_InitStruct = {0};
  398. RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
  399. if(hspi->Instance==SPI4)
  400. {
  401. /* USER CODE BEGIN SPI4_MspInit 0 */
  402. /* USER CODE END SPI4_MspInit 0 */
  403. /** Initializes the peripherals clock
  404. */
  405. PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_SPI4;
  406. PeriphClkInitStruct.Spi45ClockSelection = RCC_SPI45CLKSOURCE_D2PCLK1;
  407. if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
  408. {
  409. Error_Handler();
  410. }
  411. /* Peripheral clock enable */
  412. __HAL_RCC_SPI4_CLK_ENABLE();
  413. __HAL_RCC_GPIOE_CLK_ENABLE();
  414. /**SPI4 GPIO Configuration
  415. PE11 ------> SPI4_NSS
  416. PE12 ------> SPI4_SCK
  417. PE14 ------> SPI4_MOSI
  418. */
  419. // GPIO_InitStruct.Pin = GPIO_PIN_11|GPIO_PIN_12|GPIO_PIN_14;
  420. // GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  421. // GPIO_InitStruct.Pull = GPIO_NOPULL;
  422. // GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  423. // GPIO_InitStruct.Alternate = GPIO_AF5_SPI4;
  424. // HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
  425. /* USER CODE BEGIN SPI4_MspInit 1 */
  426. /**SPI4 GPIO Configuration
  427. PE11 ------> soft CS
  428. PE12 ------> SPI4_SCK
  429. PE14 ------> SPI4_MOSI
  430. */
  431. GPIO_InitStruct.Pin = GPIO_PIN_12|GPIO_PIN_14;
  432. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  433. GPIO_InitStruct.Pull = GPIO_NOPULL;
  434. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  435. GPIO_InitStruct.Alternate = GPIO_AF5_SPI4;
  436. HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
  437. /* USER CODE END SPI4_MspInit 1 */
  438. }
  439. }
  440. /**
  441. * @brief SPI MSP De-Initialization
  442. * This function freeze the hardware resources used in this example
  443. * @param hspi: SPI handle pointer
  444. * @retval None
  445. */
  446. void HAL_SPI_MspDeInit(SPI_HandleTypeDef* hspi)
  447. {
  448. if(hspi->Instance==SPI4)
  449. {
  450. /* USER CODE BEGIN SPI4_MspDeInit 0 */
  451. /* USER CODE END SPI4_MspDeInit 0 */
  452. /* Peripheral clock disable */
  453. __HAL_RCC_SPI4_CLK_DISABLE();
  454. /**SPI4 GPIO Configuration
  455. PE11 ------> SPI4_NSS
  456. PE12 ------> SPI4_SCK
  457. PE14 ------> SPI4_MOSI
  458. */
  459. HAL_GPIO_DeInit(GPIOE, GPIO_PIN_11|GPIO_PIN_12|GPIO_PIN_14);
  460. /* USER CODE BEGIN SPI4_MspDeInit 1 */
  461. /* USER CODE END SPI4_MspDeInit 1 */
  462. }
  463. }
  464. /**
  465. * @brief UART MSP Initialization
  466. * This function configures the hardware resources used in this example
  467. * @param huart: UART handle pointer
  468. * @retval None
  469. */
  470. void HAL_UART_MspInit(UART_HandleTypeDef* huart)
  471. {
  472. GPIO_InitTypeDef GPIO_InitStruct = {0};
  473. RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
  474. if(huart->Instance==USART1)
  475. {
  476. /* USER CODE BEGIN USART1_MspInit 0 */
  477. /* USER CODE END USART1_MspInit 0 */
  478. /** Initializes the peripherals clock
  479. */
  480. PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_USART1;
  481. PeriphClkInitStruct.Usart16ClockSelection = RCC_USART16CLKSOURCE_D2PCLK2;
  482. if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
  483. {
  484. Error_Handler();
  485. }
  486. /* Peripheral clock enable */
  487. __HAL_RCC_USART1_CLK_ENABLE();
  488. __HAL_RCC_GPIOA_CLK_ENABLE();
  489. /**USART1 GPIO Configuration
  490. PA9 ------> USART1_TX
  491. PA10 ------> USART1_RX
  492. */
  493. GPIO_InitStruct.Pin = GPIO_PIN_9|GPIO_PIN_10;
  494. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  495. GPIO_InitStruct.Pull = GPIO_NOPULL;
  496. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  497. GPIO_InitStruct.Alternate = GPIO_AF7_USART1;
  498. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  499. /* USER CODE BEGIN USART1_MspInit 1 */
  500. /* USER CODE END USART1_MspInit 1 */
  501. }
  502. }
  503. /**
  504. * @brief UART MSP De-Initialization
  505. * This function freeze the hardware resources used in this example
  506. * @param huart: UART handle pointer
  507. * @retval None
  508. */
  509. void HAL_UART_MspDeInit(UART_HandleTypeDef* huart)
  510. {
  511. if(huart->Instance==USART1)
  512. {
  513. /* USER CODE BEGIN USART1_MspDeInit 0 */
  514. /* USER CODE END USART1_MspDeInit 0 */
  515. /* Peripheral clock disable */
  516. __HAL_RCC_USART1_CLK_DISABLE();
  517. /**USART1 GPIO Configuration
  518. PA9 ------> USART1_TX
  519. PA10 ------> USART1_RX
  520. */
  521. HAL_GPIO_DeInit(GPIOA, GPIO_PIN_9|GPIO_PIN_10);
  522. /* USER CODE BEGIN USART1_MspDeInit 1 */
  523. /* USER CODE END USART1_MspDeInit 1 */
  524. }
  525. }
  526. /* USER CODE BEGIN 1 */
  527. /* USER CODE END 1 */