stm32h5xx_hal_msp.c 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  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. /**
  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. /* System interrupt init*/
  53. /* USER CODE BEGIN MspInit 1 */
  54. /* USER CODE END MspInit 1 */
  55. }
  56. /**
  57. * @brief UART MSP Initialization
  58. * This function configures the hardware resources used in this example
  59. * @param huart: UART handle pointer
  60. * @retval None
  61. */
  62. void HAL_UART_MspInit(UART_HandleTypeDef* huart)
  63. {
  64. GPIO_InitTypeDef GPIO_InitStruct = {0};
  65. RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
  66. if(huart->Instance==USART1)
  67. {
  68. /* USER CODE BEGIN USART1_MspInit 0 */
  69. /* USER CODE END USART1_MspInit 0 */
  70. /** Initializes the peripherals clock
  71. */
  72. PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_USART1;
  73. PeriphClkInitStruct.Usart1ClockSelection = RCC_USART1CLKSOURCE_PCLK2;
  74. if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
  75. {
  76. Error_Handler();
  77. }
  78. /* Peripheral clock enable */
  79. __HAL_RCC_USART1_CLK_ENABLE();
  80. __HAL_RCC_GPIOB_CLK_ENABLE();
  81. /**USART1 GPIO Configuration
  82. PB14 ------> USART1_TX
  83. PB15 ------> USART1_RX
  84. */
  85. GPIO_InitStruct.Pin = ARD_D1_TX_Pin|ARD_D0_RX_Pin;
  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_AF4_USART1;
  90. HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  91. /* USER CODE BEGIN USART1_MspInit 1 */
  92. /* USER CODE END USART1_MspInit 1 */
  93. }
  94. else if(huart->Instance==USART3)
  95. {
  96. /* USER CODE BEGIN USART3_MspInit 0 */
  97. /* USER CODE END USART3_MspInit 0 */
  98. /** Initializes the peripherals clock
  99. */
  100. PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_USART3;
  101. PeriphClkInitStruct.Usart3ClockSelection = RCC_USART3CLKSOURCE_PCLK1;
  102. if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
  103. {
  104. Error_Handler();
  105. }
  106. /* Peripheral clock enable */
  107. __HAL_RCC_USART3_CLK_ENABLE();
  108. __HAL_RCC_GPIOA_CLK_ENABLE();
  109. /**USART3 GPIO Configuration
  110. PA3 ------> USART3_RX
  111. PA4 ------> USART3_TX
  112. */
  113. GPIO_InitStruct.Pin = T_VCP_RX_Pin|T_VCP_TX_Pin;
  114. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  115. GPIO_InitStruct.Pull = GPIO_NOPULL;
  116. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  117. GPIO_InitStruct.Alternate = GPIO_AF13_USART3;
  118. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  119. /* USER CODE BEGIN USART3_MspInit 1 */
  120. /* USER CODE END USART3_MspInit 1 */
  121. }
  122. }
  123. /**
  124. * @brief UART MSP De-Initialization
  125. * This function freeze the hardware resources used in this example
  126. * @param huart: UART handle pointer
  127. * @retval None
  128. */
  129. void HAL_UART_MspDeInit(UART_HandleTypeDef* huart)
  130. {
  131. if(huart->Instance==USART1)
  132. {
  133. /* USER CODE BEGIN USART1_MspDeInit 0 */
  134. /* USER CODE END USART1_MspDeInit 0 */
  135. /* Peripheral clock disable */
  136. __HAL_RCC_USART1_CLK_DISABLE();
  137. /**USART1 GPIO Configuration
  138. PB14 ------> USART1_TX
  139. PB15 ------> USART1_RX
  140. */
  141. HAL_GPIO_DeInit(GPIOB, ARD_D1_TX_Pin|ARD_D0_RX_Pin);
  142. /* USER CODE BEGIN USART1_MspDeInit 1 */
  143. /* USER CODE END USART1_MspDeInit 1 */
  144. }
  145. else if(huart->Instance==USART3)
  146. {
  147. /* USER CODE BEGIN USART3_MspDeInit 0 */
  148. /* USER CODE END USART3_MspDeInit 0 */
  149. /* Peripheral clock disable */
  150. __HAL_RCC_USART3_CLK_DISABLE();
  151. /**USART3 GPIO Configuration
  152. PA3 ------> USART3_RX
  153. PA4 ------> USART3_TX
  154. */
  155. HAL_GPIO_DeInit(GPIOA, T_VCP_RX_Pin|T_VCP_TX_Pin);
  156. /* USER CODE BEGIN USART3_MspDeInit 1 */
  157. /* USER CODE END USART3_MspDeInit 1 */
  158. }
  159. }
  160. /**
  161. * @brief PCD MSP Initialization
  162. * This function configures the hardware resources used in this example
  163. * @param hpcd: PCD handle pointer
  164. * @retval None
  165. */
  166. void HAL_PCD_MspInit(PCD_HandleTypeDef* hpcd)
  167. {
  168. GPIO_InitTypeDef GPIO_InitStruct = {0};
  169. RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
  170. if(hpcd->Instance==USB_DRD_FS)
  171. {
  172. /* USER CODE BEGIN USB_DRD_FS_MspInit 0 */
  173. /* USER CODE END USB_DRD_FS_MspInit 0 */
  174. /** Initializes the peripherals clock
  175. */
  176. PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_USB;
  177. PeriphClkInitStruct.UsbClockSelection = RCC_USBCLKSOURCE_HSI48;
  178. if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
  179. {
  180. Error_Handler();
  181. }
  182. __HAL_RCC_GPIOA_CLK_ENABLE();
  183. /**USB GPIO Configuration
  184. PA11 ------> USB_DM
  185. PA12 ------> USB_DP
  186. */
  187. GPIO_InitStruct.Pin = USB_FS_DN_Pin|USB_FS_DP_Pin;
  188. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  189. GPIO_InitStruct.Pull = GPIO_NOPULL;
  190. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  191. GPIO_InitStruct.Alternate = GPIO_AF10_USB;
  192. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  193. /* Peripheral clock enable */
  194. __HAL_RCC_USB_CLK_ENABLE();
  195. /* USER CODE BEGIN USB_DRD_FS_MspInit 1 */
  196. /* USER CODE END USB_DRD_FS_MspInit 1 */
  197. }
  198. }
  199. /**
  200. * @brief PCD MSP De-Initialization
  201. * This function freeze the hardware resources used in this example
  202. * @param hpcd: PCD handle pointer
  203. * @retval None
  204. */
  205. void HAL_PCD_MspDeInit(PCD_HandleTypeDef* hpcd)
  206. {
  207. if(hpcd->Instance==USB_DRD_FS)
  208. {
  209. /* USER CODE BEGIN USB_DRD_FS_MspDeInit 0 */
  210. /* USER CODE END USB_DRD_FS_MspDeInit 0 */
  211. /* Peripheral clock disable */
  212. __HAL_RCC_USB_CLK_DISABLE();
  213. /**USB GPIO Configuration
  214. PA11 ------> USB_DM
  215. PA12 ------> USB_DP
  216. */
  217. HAL_GPIO_DeInit(GPIOA, USB_FS_DN_Pin|USB_FS_DP_Pin);
  218. /* USER CODE BEGIN USB_DRD_FS_MspDeInit 1 */
  219. /* USER CODE END USB_DRD_FS_MspDeInit 1 */
  220. }
  221. }
  222. /* USER CODE BEGIN 1 */
  223. /* USER CODE END 1 */