stm32h5xx_hal_msp.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547
  1. /* USER CODE BEGIN Header */
  2. /**
  3. ******************************************************************************
  4. * @file stm32h5xx_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. void HAL_TIM_MspPostInit(TIM_HandleTypeDef *htim);
  46. /**
  47. * Initializes the Global MSP.
  48. */
  49. void HAL_MspInit(void)
  50. {
  51. /* USER CODE BEGIN MspInit 0 */
  52. /* USER CODE END MspInit 0 */
  53. /* System interrupt init*/
  54. /* USER CODE BEGIN MspInit 1 */
  55. /* USER CODE END MspInit 1 */
  56. }
  57. /**
  58. * @brief ADC MSP Initialization
  59. * This function configures the hardware resources used in this example
  60. * @param hadc: ADC handle pointer
  61. * @retval None
  62. */
  63. void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc)
  64. {
  65. GPIO_InitTypeDef GPIO_InitStruct = {0};
  66. RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
  67. if(hadc->Instance==ADC1)
  68. {
  69. /* USER CODE BEGIN ADC1_MspInit 0 */
  70. /* USER CODE END ADC1_MspInit 0 */
  71. /** Initializes the peripherals clock
  72. */
  73. PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_ADCDAC;
  74. PeriphClkInitStruct.AdcDacClockSelection = RCC_ADCDACCLKSOURCE_HCLK;
  75. if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
  76. {
  77. Error_Handler();
  78. }
  79. /* Peripheral clock enable */
  80. __HAL_RCC_ADC_CLK_ENABLE();
  81. __HAL_RCC_GPIOC_CLK_ENABLE();
  82. __HAL_RCC_GPIOA_CLK_ENABLE();
  83. __HAL_RCC_GPIOB_CLK_ENABLE();
  84. /**ADC1 GPIO Configuration
  85. PC0 ------> ADC1_INP10
  86. PC1 ------> ADC1_INP11
  87. PA0 ------> ADC1_INP0
  88. PA1 ------> ADC1_INP1
  89. PA2 ------> ADC1_INP14
  90. PB0 ------> ADC1_INP9
  91. */
  92. GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1;
  93. GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
  94. GPIO_InitStruct.Pull = GPIO_NOPULL;
  95. HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
  96. GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2;
  97. GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
  98. GPIO_InitStruct.Pull = GPIO_NOPULL;
  99. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  100. GPIO_InitStruct.Pin = GPIO_PIN_0;
  101. GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
  102. GPIO_InitStruct.Pull = GPIO_NOPULL;
  103. HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  104. /* USER CODE BEGIN ADC1_MspInit 1 */
  105. /* USER CODE END ADC1_MspInit 1 */
  106. }
  107. }
  108. /**
  109. * @brief ADC MSP De-Initialization
  110. * This function freeze the hardware resources used in this example
  111. * @param hadc: ADC handle pointer
  112. * @retval None
  113. */
  114. void HAL_ADC_MspDeInit(ADC_HandleTypeDef* hadc)
  115. {
  116. if(hadc->Instance==ADC1)
  117. {
  118. /* USER CODE BEGIN ADC1_MspDeInit 0 */
  119. /* USER CODE END ADC1_MspDeInit 0 */
  120. /* Peripheral clock disable */
  121. __HAL_RCC_ADC_CLK_DISABLE();
  122. /**ADC1 GPIO Configuration
  123. PC0 ------> ADC1_INP10
  124. PC1 ------> ADC1_INP11
  125. PA0 ------> ADC1_INP0
  126. PA1 ------> ADC1_INP1
  127. PA2 ------> ADC1_INP14
  128. PB0 ------> ADC1_INP9
  129. */
  130. HAL_GPIO_DeInit(GPIOC, GPIO_PIN_0|GPIO_PIN_1);
  131. HAL_GPIO_DeInit(GPIOA, GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2);
  132. HAL_GPIO_DeInit(GPIOB, GPIO_PIN_0);
  133. /* USER CODE BEGIN ADC1_MspDeInit 1 */
  134. /* USER CODE END ADC1_MspDeInit 1 */
  135. }
  136. }
  137. /**
  138. * @brief TIM_Base MSP Initialization
  139. * This function configures the hardware resources used in this example
  140. * @param htim_base: TIM_Base handle pointer
  141. * @retval None
  142. */
  143. void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* htim_base)
  144. {
  145. if(htim_base->Instance==TIM1)
  146. {
  147. /* USER CODE BEGIN TIM1_MspInit 0 */
  148. /* USER CODE END TIM1_MspInit 0 */
  149. /* Peripheral clock enable */
  150. __HAL_RCC_TIM1_CLK_ENABLE();
  151. /* USER CODE BEGIN TIM1_MspInit 1 */
  152. /* USER CODE END TIM1_MspInit 1 */
  153. }
  154. else if(htim_base->Instance==TIM2)
  155. {
  156. /* USER CODE BEGIN TIM2_MspInit 0 */
  157. /* USER CODE END TIM2_MspInit 0 */
  158. /* Peripheral clock enable */
  159. __HAL_RCC_TIM2_CLK_ENABLE();
  160. /* USER CODE BEGIN TIM2_MspInit 1 */
  161. /* USER CODE END TIM2_MspInit 1 */
  162. }
  163. else if(htim_base->Instance==TIM3)
  164. {
  165. /* USER CODE BEGIN TIM3_MspInit 0 */
  166. /* USER CODE END TIM3_MspInit 0 */
  167. /* Peripheral clock enable */
  168. __HAL_RCC_TIM3_CLK_ENABLE();
  169. /* USER CODE BEGIN TIM3_MspInit 1 */
  170. /* USER CODE END TIM3_MspInit 1 */
  171. }
  172. }
  173. void HAL_TIM_MspPostInit(TIM_HandleTypeDef* htim)
  174. {
  175. GPIO_InitTypeDef GPIO_InitStruct = {0};
  176. if(htim->Instance==TIM1)
  177. {
  178. /* USER CODE BEGIN TIM1_MspPostInit 0 */
  179. /* USER CODE END TIM1_MspPostInit 0 */
  180. __HAL_RCC_GPIOB_CLK_ENABLE();
  181. /**TIM1 GPIO Configuration
  182. PB4(NJTRST) ------> TIM1_CH2
  183. */
  184. GPIO_InitStruct.Pin = GPIO_PIN_4;
  185. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  186. GPIO_InitStruct.Pull = GPIO_NOPULL;
  187. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  188. GPIO_InitStruct.Alternate = GPIO_AF14_TIM1;
  189. HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  190. /* USER CODE BEGIN TIM1_MspPostInit 1 */
  191. /* USER CODE END TIM1_MspPostInit 1 */
  192. }
  193. else if(htim->Instance==TIM2)
  194. {
  195. /* USER CODE BEGIN TIM2_MspPostInit 0 */
  196. /* USER CODE END TIM2_MspPostInit 0 */
  197. __HAL_RCC_GPIOB_CLK_ENABLE();
  198. /**TIM2 GPIO Configuration
  199. PB10 ------> TIM2_CH3
  200. */
  201. GPIO_InitStruct.Pin = GPIO_PIN_10;
  202. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  203. GPIO_InitStruct.Pull = GPIO_NOPULL;
  204. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  205. GPIO_InitStruct.Alternate = GPIO_AF1_TIM2;
  206. HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  207. /* USER CODE BEGIN TIM2_MspPostInit 1 */
  208. /* USER CODE END TIM2_MspPostInit 1 */
  209. }
  210. else if(htim->Instance==TIM3)
  211. {
  212. /* USER CODE BEGIN TIM3_MspPostInit 0 */
  213. /* USER CODE END TIM3_MspPostInit 0 */
  214. __HAL_RCC_GPIOA_CLK_ENABLE();
  215. __HAL_RCC_GPIOC_CLK_ENABLE();
  216. /**TIM3 GPIO Configuration
  217. PA7 ------> TIM3_CH2
  218. PC6 ------> TIM3_CH1
  219. PC9 ------> TIM3_CH4
  220. */
  221. GPIO_InitStruct.Pin = GPIO_PIN_7;
  222. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  223. GPIO_InitStruct.Pull = GPIO_NOPULL;
  224. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  225. GPIO_InitStruct.Alternate = GPIO_AF2_TIM3;
  226. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  227. GPIO_InitStruct.Pin = GPIO_PIN_6|GPIO_PIN_9;
  228. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  229. GPIO_InitStruct.Pull = GPIO_NOPULL;
  230. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  231. GPIO_InitStruct.Alternate = GPIO_AF2_TIM3;
  232. HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
  233. /* USER CODE BEGIN TIM3_MspPostInit 1 */
  234. /* USER CODE END TIM3_MspPostInit 1 */
  235. }
  236. }
  237. /**
  238. * @brief TIM_Base MSP De-Initialization
  239. * This function freeze the hardware resources used in this example
  240. * @param htim_base: TIM_Base handle pointer
  241. * @retval None
  242. */
  243. void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* htim_base)
  244. {
  245. if(htim_base->Instance==TIM1)
  246. {
  247. /* USER CODE BEGIN TIM1_MspDeInit 0 */
  248. /* USER CODE END TIM1_MspDeInit 0 */
  249. /* Peripheral clock disable */
  250. __HAL_RCC_TIM1_CLK_DISABLE();
  251. /* USER CODE BEGIN TIM1_MspDeInit 1 */
  252. /* USER CODE END TIM1_MspDeInit 1 */
  253. }
  254. else if(htim_base->Instance==TIM2)
  255. {
  256. /* USER CODE BEGIN TIM2_MspDeInit 0 */
  257. /* USER CODE END TIM2_MspDeInit 0 */
  258. /* Peripheral clock disable */
  259. __HAL_RCC_TIM2_CLK_DISABLE();
  260. /* USER CODE BEGIN TIM2_MspDeInit 1 */
  261. /* USER CODE END TIM2_MspDeInit 1 */
  262. }
  263. else if(htim_base->Instance==TIM3)
  264. {
  265. /* USER CODE BEGIN TIM3_MspDeInit 0 */
  266. /* USER CODE END TIM3_MspDeInit 0 */
  267. /* Peripheral clock disable */
  268. __HAL_RCC_TIM3_CLK_DISABLE();
  269. /* USER CODE BEGIN TIM3_MspDeInit 1 */
  270. /* USER CODE END TIM3_MspDeInit 1 */
  271. }
  272. }
  273. /**
  274. * @brief UART MSP Initialization
  275. * This function configures the hardware resources used in this example
  276. * @param huart: UART handle pointer
  277. * @retval None
  278. */
  279. void HAL_UART_MspInit(UART_HandleTypeDef* huart)
  280. {
  281. GPIO_InitTypeDef GPIO_InitStruct = {0};
  282. RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
  283. if(huart->Instance==USART1)
  284. {
  285. /* USER CODE BEGIN USART1_MspInit 0 */
  286. /* USER CODE END USART1_MspInit 0 */
  287. /** Initializes the peripherals clock
  288. */
  289. PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_USART1;
  290. PeriphClkInitStruct.Usart1ClockSelection = RCC_USART1CLKSOURCE_PCLK2;
  291. if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
  292. {
  293. Error_Handler();
  294. }
  295. /* Peripheral clock enable */
  296. __HAL_RCC_USART1_CLK_ENABLE();
  297. __HAL_RCC_GPIOB_CLK_ENABLE();
  298. /**USART1 GPIO Configuration
  299. PB14 ------> USART1_TX
  300. PB15 ------> USART1_RX
  301. */
  302. GPIO_InitStruct.Pin = ARD_D1_TX_Pin|ARD_D0_RX_Pin;
  303. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  304. GPIO_InitStruct.Pull = GPIO_NOPULL;
  305. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  306. GPIO_InitStruct.Alternate = GPIO_AF4_USART1;
  307. HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  308. /* USER CODE BEGIN USART1_MspInit 1 */
  309. /* USER CODE END USART1_MspInit 1 */
  310. }
  311. else if(huart->Instance==USART3)
  312. {
  313. /* USER CODE BEGIN USART3_MspInit 0 */
  314. /* USER CODE END USART3_MspInit 0 */
  315. /** Initializes the peripherals clock
  316. */
  317. PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_USART3;
  318. PeriphClkInitStruct.Usart3ClockSelection = RCC_USART3CLKSOURCE_PCLK1;
  319. if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
  320. {
  321. Error_Handler();
  322. }
  323. /* Peripheral clock enable */
  324. __HAL_RCC_USART3_CLK_ENABLE();
  325. __HAL_RCC_GPIOA_CLK_ENABLE();
  326. /**USART3 GPIO Configuration
  327. PA3 ------> USART3_RX
  328. PA4 ------> USART3_TX
  329. */
  330. GPIO_InitStruct.Pin = T_VCP_RX_Pin|T_VCP_TX_Pin;
  331. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  332. GPIO_InitStruct.Pull = GPIO_NOPULL;
  333. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  334. GPIO_InitStruct.Alternate = GPIO_AF13_USART3;
  335. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  336. /* USER CODE BEGIN USART3_MspInit 1 */
  337. /* USER CODE END USART3_MspInit 1 */
  338. }
  339. }
  340. /**
  341. * @brief UART MSP De-Initialization
  342. * This function freeze the hardware resources used in this example
  343. * @param huart: UART handle pointer
  344. * @retval None
  345. */
  346. void HAL_UART_MspDeInit(UART_HandleTypeDef* huart)
  347. {
  348. if(huart->Instance==USART1)
  349. {
  350. /* USER CODE BEGIN USART1_MspDeInit 0 */
  351. /* USER CODE END USART1_MspDeInit 0 */
  352. /* Peripheral clock disable */
  353. __HAL_RCC_USART1_CLK_DISABLE();
  354. /**USART1 GPIO Configuration
  355. PB14 ------> USART1_TX
  356. PB15 ------> USART1_RX
  357. */
  358. HAL_GPIO_DeInit(GPIOB, ARD_D1_TX_Pin|ARD_D0_RX_Pin);
  359. /* USER CODE BEGIN USART1_MspDeInit 1 */
  360. /* USER CODE END USART1_MspDeInit 1 */
  361. }
  362. else if(huart->Instance==USART3)
  363. {
  364. /* USER CODE BEGIN USART3_MspDeInit 0 */
  365. /* USER CODE END USART3_MspDeInit 0 */
  366. /* Peripheral clock disable */
  367. __HAL_RCC_USART3_CLK_DISABLE();
  368. /**USART3 GPIO Configuration
  369. PA3 ------> USART3_RX
  370. PA4 ------> USART3_TX
  371. */
  372. HAL_GPIO_DeInit(GPIOA, T_VCP_RX_Pin|T_VCP_TX_Pin);
  373. /* USER CODE BEGIN USART3_MspDeInit 1 */
  374. /* USER CODE END USART3_MspDeInit 1 */
  375. }
  376. }
  377. /**
  378. * @brief PCD MSP Initialization
  379. * This function configures the hardware resources used in this example
  380. * @param hpcd: PCD handle pointer
  381. * @retval None
  382. */
  383. void HAL_PCD_MspInit(PCD_HandleTypeDef* hpcd)
  384. {
  385. GPIO_InitTypeDef GPIO_InitStruct = {0};
  386. RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
  387. if(hpcd->Instance==USB_DRD_FS)
  388. {
  389. /* USER CODE BEGIN USB_DRD_FS_MspInit 0 */
  390. /* USER CODE END USB_DRD_FS_MspInit 0 */
  391. /** Initializes the peripherals clock
  392. */
  393. PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_USB;
  394. PeriphClkInitStruct.UsbClockSelection = RCC_USBCLKSOURCE_HSI48;
  395. if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
  396. {
  397. Error_Handler();
  398. }
  399. __HAL_RCC_GPIOA_CLK_ENABLE();
  400. /**USB GPIO Configuration
  401. PA11 ------> USB_DM
  402. PA12 ------> USB_DP
  403. */
  404. GPIO_InitStruct.Pin = USB_FS_DN_Pin|USB_FS_DP_Pin;
  405. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  406. GPIO_InitStruct.Pull = GPIO_NOPULL;
  407. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  408. GPIO_InitStruct.Alternate = GPIO_AF10_USB;
  409. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  410. /* Peripheral clock enable */
  411. __HAL_RCC_USB_CLK_ENABLE();
  412. /* USER CODE BEGIN USB_DRD_FS_MspInit 1 */
  413. /* USER CODE END USB_DRD_FS_MspInit 1 */
  414. }
  415. }
  416. /**
  417. * @brief PCD MSP De-Initialization
  418. * This function freeze the hardware resources used in this example
  419. * @param hpcd: PCD handle pointer
  420. * @retval None
  421. */
  422. void HAL_PCD_MspDeInit(PCD_HandleTypeDef* hpcd)
  423. {
  424. if(hpcd->Instance==USB_DRD_FS)
  425. {
  426. /* USER CODE BEGIN USB_DRD_FS_MspDeInit 0 */
  427. /* USER CODE END USB_DRD_FS_MspDeInit 0 */
  428. /* Peripheral clock disable */
  429. __HAL_RCC_USB_CLK_DISABLE();
  430. /**USB GPIO Configuration
  431. PA11 ------> USB_DM
  432. PA12 ------> USB_DP
  433. */
  434. HAL_GPIO_DeInit(GPIOA, USB_FS_DN_Pin|USB_FS_DP_Pin);
  435. /* USER CODE BEGIN USB_DRD_FS_MspDeInit 1 */
  436. /* USER CODE END USB_DRD_FS_MspDeInit 1 */
  437. }
  438. }
  439. /* USER CODE BEGIN 1 */
  440. /* USER CODE END 1 */