stm32h7xx_hal_msp.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483
  1. /* USER CODE BEGIN Header */
  2. /**
  3. ******************************************************************************
  4. * File Name : stm32h7xx_hal_msp.c
  5. * Description : This file provides code for the MSP Initialization
  6. * and de-Initialization codes.
  7. ******************************************************************************
  8. * @attention
  9. *
  10. * <h2><center>&copy; Copyright (c) 2020 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_SYSCFG_CLK_ENABLE();
  55. /* System interrupt init*/
  56. /* USER CODE BEGIN MspInit 1 */
  57. /* USER CODE END MspInit 1 */
  58. }
  59. /**
  60. * @brief QSPI MSP Initialization
  61. * This function configures the hardware resources used in this example
  62. * @param hqspi: QSPI handle pointer
  63. * @retval None
  64. */
  65. void HAL_QSPI_MspInit(QSPI_HandleTypeDef* hqspi)
  66. {
  67. GPIO_InitTypeDef GPIO_InitStruct = {0};
  68. if(hqspi->Instance==QUADSPI)
  69. {
  70. /* USER CODE BEGIN QUADSPI_MspInit 0 */
  71. /* USER CODE END QUADSPI_MspInit 0 */
  72. /* Peripheral clock enable */
  73. __HAL_RCC_QSPI_CLK_ENABLE();
  74. __HAL_RCC_GPIOE_CLK_ENABLE();
  75. __HAL_RCC_GPIOB_CLK_ENABLE();
  76. __HAL_RCC_GPIOD_CLK_ENABLE();
  77. /**QUADSPI GPIO Configuration
  78. PE2 ------> QUADSPI_BK1_IO2
  79. PB2 ------> QUADSPI_CLK
  80. PD11 ------> QUADSPI_BK1_IO0
  81. PD12 ------> QUADSPI_BK1_IO1
  82. PD13 ------> QUADSPI_BK1_IO3
  83. PB6 ------> QUADSPI_BK1_NCS
  84. */
  85. GPIO_InitStruct.Pin = GPIO_PIN_2;
  86. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  87. GPIO_InitStruct.Pull = GPIO_NOPULL;
  88. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  89. GPIO_InitStruct.Alternate = GPIO_AF9_QUADSPI;
  90. HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
  91. GPIO_InitStruct.Pin = GPIO_PIN_2;
  92. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  93. GPIO_InitStruct.Pull = GPIO_NOPULL;
  94. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  95. GPIO_InitStruct.Alternate = GPIO_AF9_QUADSPI;
  96. HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  97. GPIO_InitStruct.Pin = GPIO_PIN_11|GPIO_PIN_12|GPIO_PIN_13;
  98. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  99. GPIO_InitStruct.Pull = GPIO_NOPULL;
  100. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  101. GPIO_InitStruct.Alternate = GPIO_AF9_QUADSPI;
  102. HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
  103. GPIO_InitStruct.Pin = GPIO_PIN_6;
  104. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  105. GPIO_InitStruct.Pull = GPIO_NOPULL;
  106. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  107. GPIO_InitStruct.Alternate = GPIO_AF10_QUADSPI;
  108. HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  109. /* USER CODE BEGIN QUADSPI_MspInit 1 */
  110. /* USER CODE END QUADSPI_MspInit 1 */
  111. }
  112. }
  113. /**
  114. * @brief QSPI MSP De-Initialization
  115. * This function freeze the hardware resources used in this example
  116. * @param hqspi: QSPI handle pointer
  117. * @retval None
  118. */
  119. void HAL_QSPI_MspDeInit(QSPI_HandleTypeDef* hqspi)
  120. {
  121. if(hqspi->Instance==QUADSPI)
  122. {
  123. /* USER CODE BEGIN QUADSPI_MspDeInit 0 */
  124. /* USER CODE END QUADSPI_MspDeInit 0 */
  125. /* Peripheral clock disable */
  126. __HAL_RCC_QSPI_CLK_DISABLE();
  127. /**QUADSPI GPIO Configuration
  128. PE2 ------> QUADSPI_BK1_IO2
  129. PB2 ------> QUADSPI_CLK
  130. PD11 ------> QUADSPI_BK1_IO0
  131. PD12 ------> QUADSPI_BK1_IO1
  132. PD13 ------> QUADSPI_BK1_IO3
  133. PB6 ------> QUADSPI_BK1_NCS
  134. */
  135. HAL_GPIO_DeInit(GPIOE, GPIO_PIN_2);
  136. HAL_GPIO_DeInit(GPIOB, GPIO_PIN_2|GPIO_PIN_6);
  137. HAL_GPIO_DeInit(GPIOD, GPIO_PIN_11|GPIO_PIN_12|GPIO_PIN_13);
  138. /* USER CODE BEGIN QUADSPI_MspDeInit 1 */
  139. /* USER CODE END QUADSPI_MspDeInit 1 */
  140. }
  141. }
  142. /**
  143. * @brief RTC MSP Initialization
  144. * This function configures the hardware resources used in this example
  145. * @param hrtc: RTC handle pointer
  146. * @retval None
  147. */
  148. void HAL_RTC_MspInit(RTC_HandleTypeDef* hrtc)
  149. {
  150. if(hrtc->Instance==RTC)
  151. {
  152. /* USER CODE BEGIN RTC_MspInit 0 */
  153. /* USER CODE END RTC_MspInit 0 */
  154. /* Peripheral clock enable */
  155. __HAL_RCC_RTC_ENABLE();
  156. /* USER CODE BEGIN RTC_MspInit 1 */
  157. /* USER CODE END RTC_MspInit 1 */
  158. }
  159. }
  160. /**
  161. * @brief RTC MSP De-Initialization
  162. * This function freeze the hardware resources used in this example
  163. * @param hrtc: RTC handle pointer
  164. * @retval None
  165. */
  166. void HAL_RTC_MspDeInit(RTC_HandleTypeDef* hrtc)
  167. {
  168. if(hrtc->Instance==RTC)
  169. {
  170. /* USER CODE BEGIN RTC_MspDeInit 0 */
  171. /* USER CODE END RTC_MspDeInit 0 */
  172. /* Peripheral clock disable */
  173. __HAL_RCC_RTC_DISABLE();
  174. /* USER CODE BEGIN RTC_MspDeInit 1 */
  175. /* USER CODE END RTC_MspDeInit 1 */
  176. }
  177. }
  178. /**
  179. * @brief SPI MSP Initialization
  180. * This function configures the hardware resources used in this example
  181. * @param hspi: SPI handle pointer
  182. * @retval None
  183. */
  184. void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi)
  185. {
  186. GPIO_InitTypeDef GPIO_InitStruct = {0};
  187. if(hspi->Instance==SPI1)
  188. {
  189. /* USER CODE BEGIN SPI1_MspInit 0 */
  190. /* USER CODE END SPI1_MspInit 0 */
  191. /* Peripheral clock enable */
  192. __HAL_RCC_SPI1_CLK_ENABLE();
  193. __HAL_RCC_GPIOD_CLK_ENABLE();
  194. __HAL_RCC_GPIOB_CLK_ENABLE();
  195. /**SPI1 GPIO Configuration
  196. PD7 ------> SPI1_MOSI
  197. PB3 (JTDO/TRACESWO) ------> SPI1_SCK
  198. PB4 (NJTRST) ------> SPI1_MISO
  199. */
  200. GPIO_InitStruct.Pin = GPIO_PIN_7;
  201. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  202. GPIO_InitStruct.Pull = GPIO_NOPULL;
  203. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  204. GPIO_InitStruct.Alternate = GPIO_AF5_SPI1;
  205. HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
  206. GPIO_InitStruct.Pin = GPIO_PIN_3|GPIO_PIN_4;
  207. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  208. GPIO_InitStruct.Pull = GPIO_NOPULL;
  209. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  210. GPIO_InitStruct.Alternate = GPIO_AF5_SPI1;
  211. HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  212. /* USER CODE BEGIN SPI1_MspInit 1 */
  213. /* USER CODE END SPI1_MspInit 1 */
  214. }
  215. else if(hspi->Instance==SPI4)
  216. {
  217. /* USER CODE BEGIN SPI4_MspInit 0 */
  218. /* USER CODE END SPI4_MspInit 0 */
  219. /* Peripheral clock enable */
  220. __HAL_RCC_SPI4_CLK_ENABLE();
  221. __HAL_RCC_GPIOE_CLK_ENABLE();
  222. /**SPI4 GPIO Configuration
  223. PE12 ------> SPI4_SCK
  224. PE14 ------> SPI4_MOSI
  225. */
  226. GPIO_InitStruct.Pin = GPIO_PIN_12|GPIO_PIN_14;
  227. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  228. GPIO_InitStruct.Pull = GPIO_NOPULL;
  229. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  230. GPIO_InitStruct.Alternate = GPIO_AF5_SPI4;
  231. HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
  232. /* USER CODE BEGIN SPI4_MspInit 1 */
  233. /* USER CODE END SPI4_MspInit 1 */
  234. }
  235. }
  236. /**
  237. * @brief SPI MSP De-Initialization
  238. * This function freeze the hardware resources used in this example
  239. * @param hspi: SPI handle pointer
  240. * @retval None
  241. */
  242. void HAL_SPI_MspDeInit(SPI_HandleTypeDef* hspi)
  243. {
  244. if(hspi->Instance==SPI1)
  245. {
  246. /* USER CODE BEGIN SPI1_MspDeInit 0 */
  247. /* USER CODE END SPI1_MspDeInit 0 */
  248. /* Peripheral clock disable */
  249. __HAL_RCC_SPI1_CLK_DISABLE();
  250. /**SPI1 GPIO Configuration
  251. PD7 ------> SPI1_MOSI
  252. PB3 (JTDO/TRACESWO) ------> SPI1_SCK
  253. PB4 (NJTRST) ------> SPI1_MISO
  254. */
  255. HAL_GPIO_DeInit(GPIOD, GPIO_PIN_7);
  256. HAL_GPIO_DeInit(GPIOB, GPIO_PIN_3|GPIO_PIN_4);
  257. /* USER CODE BEGIN SPI1_MspDeInit 1 */
  258. /* USER CODE END SPI1_MspDeInit 1 */
  259. }
  260. else if(hspi->Instance==SPI4)
  261. {
  262. /* USER CODE BEGIN SPI4_MspDeInit 0 */
  263. /* USER CODE END SPI4_MspDeInit 0 */
  264. /* Peripheral clock disable */
  265. __HAL_RCC_SPI4_CLK_DISABLE();
  266. /**SPI4 GPIO Configuration
  267. PE12 ------> SPI4_SCK
  268. PE14 ------> SPI4_MOSI
  269. */
  270. HAL_GPIO_DeInit(GPIOE, GPIO_PIN_12|GPIO_PIN_14);
  271. /* USER CODE BEGIN SPI4_MspDeInit 1 */
  272. /* USER CODE END SPI4_MspDeInit 1 */
  273. }
  274. }
  275. /**
  276. * @brief TIM_Base MSP Initialization
  277. * This function configures the hardware resources used in this example
  278. * @param htim_base: TIM_Base handle pointer
  279. * @retval None
  280. */
  281. void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* htim_base)
  282. {
  283. if(htim_base->Instance==TIM1)
  284. {
  285. /* USER CODE BEGIN TIM1_MspInit 0 */
  286. /* USER CODE END TIM1_MspInit 0 */
  287. /* Peripheral clock enable */
  288. __HAL_RCC_TIM1_CLK_ENABLE();
  289. /* USER CODE BEGIN TIM1_MspInit 1 */
  290. /* USER CODE END TIM1_MspInit 1 */
  291. }
  292. }
  293. void HAL_TIM_MspPostInit(TIM_HandleTypeDef* htim)
  294. {
  295. GPIO_InitTypeDef GPIO_InitStruct = {0};
  296. if(htim->Instance==TIM1)
  297. {
  298. /* USER CODE BEGIN TIM1_MspPostInit 0 */
  299. /* USER CODE END TIM1_MspPostInit 0 */
  300. __HAL_RCC_GPIOE_CLK_ENABLE();
  301. /**TIM1 GPIO Configuration
  302. PE10 ------> TIM1_CH2N
  303. */
  304. GPIO_InitStruct.Pin = LCD_LED_Pin;
  305. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  306. GPIO_InitStruct.Pull = GPIO_NOPULL;
  307. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  308. GPIO_InitStruct.Alternate = GPIO_AF1_TIM1;
  309. HAL_GPIO_Init(LCD_LED_GPIO_Port, &GPIO_InitStruct);
  310. /* USER CODE BEGIN TIM1_MspPostInit 1 */
  311. /* USER CODE END TIM1_MspPostInit 1 */
  312. }
  313. }
  314. /**
  315. * @brief TIM_Base MSP De-Initialization
  316. * This function freeze the hardware resources used in this example
  317. * @param htim_base: TIM_Base handle pointer
  318. * @retval None
  319. */
  320. void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* htim_base)
  321. {
  322. if(htim_base->Instance==TIM1)
  323. {
  324. /* USER CODE BEGIN TIM1_MspDeInit 0 */
  325. /* USER CODE END TIM1_MspDeInit 0 */
  326. /* Peripheral clock disable */
  327. __HAL_RCC_TIM1_CLK_DISABLE();
  328. /* USER CODE BEGIN TIM1_MspDeInit 1 */
  329. /* USER CODE END TIM1_MspDeInit 1 */
  330. }
  331. }
  332. /**
  333. * @brief UART MSP Initialization
  334. * This function configures the hardware resources used in this example
  335. * @param huart: UART handle pointer
  336. * @retval None
  337. */
  338. void HAL_UART_MspInit(UART_HandleTypeDef* huart)
  339. {
  340. GPIO_InitTypeDef GPIO_InitStruct = {0};
  341. if(huart->Instance==USART1)
  342. {
  343. /* USER CODE BEGIN USART1_MspInit 0 */
  344. /* USER CODE END USART1_MspInit 0 */
  345. /* Peripheral clock enable */
  346. __HAL_RCC_USART1_CLK_ENABLE();
  347. __HAL_RCC_GPIOB_CLK_ENABLE();
  348. /**USART1 GPIO Configuration
  349. PB14 ------> USART1_TX
  350. PB15 ------> USART1_RX
  351. */
  352. GPIO_InitStruct.Pin = GPIO_PIN_14|GPIO_PIN_15;
  353. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  354. GPIO_InitStruct.Pull = GPIO_NOPULL;
  355. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  356. GPIO_InitStruct.Alternate = GPIO_AF4_USART1;
  357. HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  358. /* USER CODE BEGIN USART1_MspInit 1 */
  359. /* USER CODE END USART1_MspInit 1 */
  360. }
  361. }
  362. /**
  363. * @brief UART MSP De-Initialization
  364. * This function freeze the hardware resources used in this example
  365. * @param huart: UART handle pointer
  366. * @retval None
  367. */
  368. void HAL_UART_MspDeInit(UART_HandleTypeDef* huart)
  369. {
  370. if(huart->Instance==USART1)
  371. {
  372. /* USER CODE BEGIN USART1_MspDeInit 0 */
  373. /* USER CODE END USART1_MspDeInit 0 */
  374. /* Peripheral clock disable */
  375. __HAL_RCC_USART1_CLK_DISABLE();
  376. /**USART1 GPIO Configuration
  377. PB14 ------> USART1_TX
  378. PB15 ------> USART1_RX
  379. */
  380. HAL_GPIO_DeInit(GPIOB, GPIO_PIN_14|GPIO_PIN_15);
  381. /* USER CODE BEGIN USART1_MspDeInit 1 */
  382. /* USER CODE END USART1_MspDeInit 1 */
  383. }
  384. }
  385. /* USER CODE BEGIN 1 */
  386. /* USER CODE END 1 */
  387. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/