stm32f7xx_hal_msp.c 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. /* USER CODE BEGIN Header */
  2. /**
  3. ******************************************************************************
  4. * @file stm32f7xx_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. /* USER CODE END Includes */
  24. /* Private typedef -----------------------------------------------------------*/
  25. /* USER CODE BEGIN TD */
  26. /* USER CODE END TD */
  27. /* Private define ------------------------------------------------------------*/
  28. /* USER CODE BEGIN Define */
  29. /* USER CODE END Define */
  30. /* Private macro -------------------------------------------------------------*/
  31. /* USER CODE BEGIN Macro */
  32. /* USER CODE END Macro */
  33. /* Private variables ---------------------------------------------------------*/
  34. /* USER CODE BEGIN PV */
  35. /* USER CODE END PV */
  36. /* Private function prototypes -----------------------------------------------*/
  37. /* USER CODE BEGIN PFP */
  38. /* USER CODE END PFP */
  39. /* External functions --------------------------------------------------------*/
  40. /* USER CODE BEGIN ExternalFunctions */
  41. /* USER CODE END ExternalFunctions */
  42. /* USER CODE BEGIN 0 */
  43. /* USER CODE END 0 */
  44. /**
  45. * Initializes the Global MSP.
  46. */
  47. void HAL_MspInit(void)
  48. {
  49. /* USER CODE BEGIN MspInit 0 */
  50. /* USER CODE END MspInit 0 */
  51. __HAL_RCC_PWR_CLK_ENABLE();
  52. __HAL_RCC_SYSCFG_CLK_ENABLE();
  53. /* System interrupt init*/
  54. /* PendSV_IRQn interrupt configuration */
  55. HAL_NVIC_SetPriority(PendSV_IRQn, 15, 0);
  56. /* USER CODE BEGIN MspInit 1 */
  57. /* USER CODE END MspInit 1 */
  58. }
  59. /**
  60. * @brief RTC MSP Initialization
  61. * This function configures the hardware resources used in this example
  62. * @param hrtc: RTC handle pointer
  63. * @retval None
  64. */
  65. void HAL_RTC_MspInit(RTC_HandleTypeDef* hrtc)
  66. {
  67. RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
  68. if(hrtc->Instance==RTC)
  69. {
  70. /* USER CODE BEGIN RTC_MspInit 0 */
  71. /* USER CODE END RTC_MspInit 0 */
  72. /** Initializes the peripherals clock
  73. */
  74. PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_RTC;
  75. PeriphClkInitStruct.RTCClockSelection = RCC_RTCCLKSOURCE_LSE;
  76. if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
  77. {
  78. Error_Handler();
  79. }
  80. /* Peripheral clock enable */
  81. __HAL_RCC_RTC_ENABLE();
  82. /* USER CODE BEGIN RTC_MspInit 1 */
  83. /* USER CODE END RTC_MspInit 1 */
  84. }
  85. }
  86. /**
  87. * @brief RTC MSP De-Initialization
  88. * This function freeze the hardware resources used in this example
  89. * @param hrtc: RTC handle pointer
  90. * @retval None
  91. */
  92. void HAL_RTC_MspDeInit(RTC_HandleTypeDef* hrtc)
  93. {
  94. if(hrtc->Instance==RTC)
  95. {
  96. /* USER CODE BEGIN RTC_MspDeInit 0 */
  97. /* USER CODE END RTC_MspDeInit 0 */
  98. /* Peripheral clock disable */
  99. __HAL_RCC_RTC_DISABLE();
  100. /* USER CODE BEGIN RTC_MspDeInit 1 */
  101. /* USER CODE END RTC_MspDeInit 1 */
  102. }
  103. }
  104. /**
  105. * @brief UART MSP Initialization
  106. * This function configures the hardware resources used in this example
  107. * @param huart: UART handle pointer
  108. * @retval None
  109. */
  110. void HAL_UART_MspInit(UART_HandleTypeDef* huart)
  111. {
  112. GPIO_InitTypeDef GPIO_InitStruct = {0};
  113. RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
  114. if(huart->Instance==USART2)
  115. {
  116. /* USER CODE BEGIN USART2_MspInit 0 */
  117. /* USER CODE END USART2_MspInit 0 */
  118. /** Initializes the peripherals clock
  119. */
  120. PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_USART2;
  121. PeriphClkInitStruct.Usart2ClockSelection = RCC_USART2CLKSOURCE_PCLK1;
  122. if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
  123. {
  124. Error_Handler();
  125. }
  126. /* Peripheral clock enable */
  127. __HAL_RCC_USART2_CLK_ENABLE();
  128. __HAL_RCC_GPIOA_CLK_ENABLE();
  129. /**USART2 GPIO Configuration
  130. PA2 ------> USART2_TX
  131. PA3 ------> USART2_RX
  132. */
  133. GPIO_InitStruct.Pin = GPIO_PIN_2|GPIO_PIN_3;
  134. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  135. GPIO_InitStruct.Pull = GPIO_NOPULL;
  136. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  137. GPIO_InitStruct.Alternate = GPIO_AF7_USART2;
  138. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  139. /* USER CODE BEGIN USART2_MspInit 1 */
  140. /* USER CODE END USART2_MspInit 1 */
  141. }
  142. }
  143. /**
  144. * @brief UART MSP De-Initialization
  145. * This function freeze the hardware resources used in this example
  146. * @param huart: UART handle pointer
  147. * @retval None
  148. */
  149. void HAL_UART_MspDeInit(UART_HandleTypeDef* huart)
  150. {
  151. if(huart->Instance==USART2)
  152. {
  153. /* USER CODE BEGIN USART2_MspDeInit 0 */
  154. /* USER CODE END USART2_MspDeInit 0 */
  155. /* Peripheral clock disable */
  156. __HAL_RCC_USART2_CLK_DISABLE();
  157. /**USART2 GPIO Configuration
  158. PA2 ------> USART2_TX
  159. PA3 ------> USART2_RX
  160. */
  161. HAL_GPIO_DeInit(GPIOA, GPIO_PIN_2|GPIO_PIN_3);
  162. /* USER CODE BEGIN USART2_MspDeInit 1 */
  163. /* USER CODE END USART2_MspDeInit 1 */
  164. }
  165. }
  166. /**
  167. * @brief PCD MSP Initialization
  168. * This function configures the hardware resources used in this example
  169. * @param hpcd: PCD handle pointer
  170. * @retval None
  171. */
  172. void HAL_PCD_MspInit(PCD_HandleTypeDef* hpcd)
  173. {
  174. GPIO_InitTypeDef GPIO_InitStruct = {0};
  175. RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
  176. if(hpcd->Instance==USB_OTG_HS)
  177. {
  178. /* USER CODE BEGIN USB_OTG_HS_MspInit 0 */
  179. /* USER CODE END USB_OTG_HS_MspInit 0 */
  180. /** Initializes the peripherals clock
  181. */
  182. PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_CLK48;
  183. PeriphClkInitStruct.Clk48ClockSelection = RCC_CLK48SOURCE_PLL;
  184. if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
  185. {
  186. Error_Handler();
  187. }
  188. __HAL_RCC_GPIOB_CLK_ENABLE();
  189. /**USB_OTG_HS GPIO Configuration
  190. PB14 ------> USB_OTG_HS_DM
  191. PB15 ------> USB_OTG_HS_DP
  192. */
  193. GPIO_InitStruct.Pin = GPIO_PIN_14|GPIO_PIN_15;
  194. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  195. GPIO_InitStruct.Pull = GPIO_NOPULL;
  196. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  197. GPIO_InitStruct.Alternate = GPIO_AF12_OTG_HS_FS;
  198. HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  199. /* Peripheral clock enable */
  200. __HAL_RCC_OTGPHYC_CLK_ENABLE();
  201. __HAL_RCC_USB_OTG_HS_CLK_ENABLE();
  202. __HAL_RCC_USB_OTG_HS_ULPI_CLK_ENABLE();
  203. /* USB_OTG_HS interrupt Init */
  204. HAL_NVIC_SetPriority(OTG_HS_IRQn, 5, 0);
  205. HAL_NVIC_EnableIRQ(OTG_HS_IRQn);
  206. /* USER CODE BEGIN USB_OTG_HS_MspInit 1 */
  207. /* USER CODE END USB_OTG_HS_MspInit 1 */
  208. }
  209. }
  210. /**
  211. * @brief PCD MSP De-Initialization
  212. * This function freeze the hardware resources used in this example
  213. * @param hpcd: PCD handle pointer
  214. * @retval None
  215. */
  216. void HAL_PCD_MspDeInit(PCD_HandleTypeDef* hpcd)
  217. {
  218. if(hpcd->Instance==USB_OTG_HS)
  219. {
  220. /* USER CODE BEGIN USB_OTG_HS_MspDeInit 0 */
  221. /* USER CODE END USB_OTG_HS_MspDeInit 0 */
  222. /* Peripheral clock disable */
  223. __HAL_RCC_OTGPHYC_CLK_DISABLE();
  224. __HAL_RCC_USB_OTG_HS_CLK_DISABLE();
  225. __HAL_RCC_USB_OTG_HS_ULPI_CLK_DISABLE();
  226. /**USB_OTG_HS GPIO Configuration
  227. PB14 ------> USB_OTG_HS_DM
  228. PB15 ------> USB_OTG_HS_DP
  229. */
  230. HAL_GPIO_DeInit(GPIOB, GPIO_PIN_14|GPIO_PIN_15);
  231. /* USB_OTG_HS interrupt DeInit */
  232. HAL_NVIC_DisableIRQ(OTG_HS_IRQn);
  233. /* USER CODE BEGIN USB_OTG_HS_MspDeInit 1 */
  234. /* USER CODE END USB_OTG_HS_MspDeInit 1 */
  235. }
  236. }
  237. /* USER CODE BEGIN 1 */
  238. /* USER CODE END 1 */