stm32f4xx_hal_msp.c 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  1. /* USER CODE BEGIN Header */
  2. /**
  3. ******************************************************************************
  4. * File Name : stm32f4xx_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. /* 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. __HAL_RCC_PWR_CLK_ENABLE();
  54. /* System interrupt init*/
  55. /* USER CODE BEGIN MspInit 1 */
  56. /* USER CODE END MspInit 1 */
  57. }
  58. /**
  59. * @brief RTC MSP Initialization
  60. * This function configures the hardware resources used in this example
  61. * @param hrtc: RTC handle pointer
  62. * @retval None
  63. */
  64. void HAL_RTC_MspInit(RTC_HandleTypeDef* hrtc)
  65. {
  66. if(hrtc->Instance==RTC)
  67. {
  68. /* USER CODE BEGIN RTC_MspInit 0 */
  69. /* USER CODE END RTC_MspInit 0 */
  70. /* Peripheral clock enable */
  71. __HAL_RCC_RTC_ENABLE();
  72. /* USER CODE BEGIN RTC_MspInit 1 */
  73. /* USER CODE END RTC_MspInit 1 */
  74. }
  75. }
  76. /**
  77. * @brief RTC MSP De-Initialization
  78. * This function freeze the hardware resources used in this example
  79. * @param hrtc: RTC handle pointer
  80. * @retval None
  81. */
  82. void HAL_RTC_MspDeInit(RTC_HandleTypeDef* hrtc)
  83. {
  84. if(hrtc->Instance==RTC)
  85. {
  86. /* USER CODE BEGIN RTC_MspDeInit 0 */
  87. /* USER CODE END RTC_MspDeInit 0 */
  88. /* Peripheral clock disable */
  89. __HAL_RCC_RTC_DISABLE();
  90. /* USER CODE BEGIN RTC_MspDeInit 1 */
  91. /* USER CODE END RTC_MspDeInit 1 */
  92. }
  93. }
  94. /**
  95. * @brief SPI MSP Initialization
  96. * This function configures the hardware resources used in this example
  97. * @param hspi: SPI handle pointer
  98. * @retval None
  99. */
  100. void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi)
  101. {
  102. GPIO_InitTypeDef GPIO_InitStruct = {0};
  103. if(hspi->Instance==SPI1)
  104. {
  105. /* USER CODE BEGIN SPI1_MspInit 0 */
  106. /* USER CODE END SPI1_MspInit 0 */
  107. /* Peripheral clock enable */
  108. __HAL_RCC_SPI1_CLK_ENABLE();
  109. __HAL_RCC_GPIOA_CLK_ENABLE();
  110. /**SPI1 GPIO Configuration
  111. PA5 ------> SPI1_SCK
  112. PA6 ------> SPI1_MISO
  113. PA7 ------> SPI1_MOSI
  114. */
  115. GPIO_InitStruct.Pin = GPIO_PIN_5|GPIO_PIN_6|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_AF5_SPI1;
  120. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  121. /* USER CODE BEGIN SPI1_MspInit 1 */
  122. /* USER CODE END SPI1_MspInit 1 */
  123. }
  124. }
  125. /**
  126. * @brief SPI MSP De-Initialization
  127. * This function freeze the hardware resources used in this example
  128. * @param hspi: SPI handle pointer
  129. * @retval None
  130. */
  131. void HAL_SPI_MspDeInit(SPI_HandleTypeDef* hspi)
  132. {
  133. if(hspi->Instance==SPI1)
  134. {
  135. /* USER CODE BEGIN SPI1_MspDeInit 0 */
  136. /* USER CODE END SPI1_MspDeInit 0 */
  137. /* Peripheral clock disable */
  138. __HAL_RCC_SPI1_CLK_DISABLE();
  139. /**SPI1 GPIO Configuration
  140. PA5 ------> SPI1_SCK
  141. PA6 ------> SPI1_MISO
  142. PA7 ------> SPI1_MOSI
  143. */
  144. HAL_GPIO_DeInit(GPIOA, GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7);
  145. /* USER CODE BEGIN SPI1_MspDeInit 1 */
  146. /* USER CODE END SPI1_MspDeInit 1 */
  147. }
  148. }
  149. /**
  150. * @brief TIM_Base MSP Initialization
  151. * This function configures the hardware resources used in this example
  152. * @param htim_base: TIM_Base handle pointer
  153. * @retval None
  154. */
  155. void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* htim_base)
  156. {
  157. if(htim_base->Instance==TIM10)
  158. {
  159. /* USER CODE BEGIN TIM10_MspInit 0 */
  160. /* USER CODE END TIM10_MspInit 0 */
  161. /* Peripheral clock enable */
  162. __HAL_RCC_TIM10_CLK_ENABLE();
  163. /* USER CODE BEGIN TIM10_MspInit 1 */
  164. /* USER CODE END TIM10_MspInit 1 */
  165. }
  166. else if(htim_base->Instance==TIM11)
  167. {
  168. /* USER CODE BEGIN TIM11_MspInit 0 */
  169. /* USER CODE END TIM11_MspInit 0 */
  170. /* Peripheral clock enable */
  171. __HAL_RCC_TIM11_CLK_ENABLE();
  172. /* USER CODE BEGIN TIM11_MspInit 1 */
  173. /* USER CODE END TIM11_MspInit 1 */
  174. }
  175. }
  176. /**
  177. * @brief TIM_Base MSP De-Initialization
  178. * This function freeze the hardware resources used in this example
  179. * @param htim_base: TIM_Base handle pointer
  180. * @retval None
  181. */
  182. void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* htim_base)
  183. {
  184. if(htim_base->Instance==TIM10)
  185. {
  186. /* USER CODE BEGIN TIM10_MspDeInit 0 */
  187. /* USER CODE END TIM10_MspDeInit 0 */
  188. /* Peripheral clock disable */
  189. __HAL_RCC_TIM10_CLK_DISABLE();
  190. /* USER CODE BEGIN TIM10_MspDeInit 1 */
  191. /* USER CODE END TIM10_MspDeInit 1 */
  192. }
  193. else if(htim_base->Instance==TIM11)
  194. {
  195. /* USER CODE BEGIN TIM11_MspDeInit 0 */
  196. /* USER CODE END TIM11_MspDeInit 0 */
  197. /* Peripheral clock disable */
  198. __HAL_RCC_TIM11_CLK_DISABLE();
  199. /* USER CODE BEGIN TIM11_MspDeInit 1 */
  200. /* USER CODE END TIM11_MspDeInit 1 */
  201. }
  202. }
  203. /**
  204. * @brief UART MSP Initialization
  205. * This function configures the hardware resources used in this example
  206. * @param huart: UART handle pointer
  207. * @retval None
  208. */
  209. void HAL_UART_MspInit(UART_HandleTypeDef* huart)
  210. {
  211. GPIO_InitTypeDef GPIO_InitStruct = {0};
  212. if(huart->Instance==USART1)
  213. {
  214. /* USER CODE BEGIN USART1_MspInit 0 */
  215. /* USER CODE END USART1_MspInit 0 */
  216. /* Peripheral clock enable */
  217. __HAL_RCC_USART1_CLK_ENABLE();
  218. __HAL_RCC_GPIOA_CLK_ENABLE();
  219. /**USART1 GPIO Configuration
  220. PA9 ------> USART1_TX
  221. PA10 ------> USART1_RX
  222. */
  223. GPIO_InitStruct.Pin = GPIO_PIN_9|GPIO_PIN_10;
  224. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  225. GPIO_InitStruct.Pull = GPIO_PULLUP;
  226. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  227. GPIO_InitStruct.Alternate = GPIO_AF7_USART1;
  228. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  229. /* USER CODE BEGIN USART1_MspInit 1 */
  230. /* USER CODE END USART1_MspInit 1 */
  231. }
  232. }
  233. /**
  234. * @brief UART MSP De-Initialization
  235. * This function freeze the hardware resources used in this example
  236. * @param huart: UART handle pointer
  237. * @retval None
  238. */
  239. void HAL_UART_MspDeInit(UART_HandleTypeDef* huart)
  240. {
  241. if(huart->Instance==USART1)
  242. {
  243. /* USER CODE BEGIN USART1_MspDeInit 0 */
  244. /* USER CODE END USART1_MspDeInit 0 */
  245. /* Peripheral clock disable */
  246. __HAL_RCC_USART1_CLK_DISABLE();
  247. /**USART1 GPIO Configuration
  248. PA9 ------> USART1_TX
  249. PA10 ------> USART1_RX
  250. */
  251. HAL_GPIO_DeInit(GPIOA, GPIO_PIN_9|GPIO_PIN_10);
  252. /* USER CODE BEGIN USART1_MspDeInit 1 */
  253. /* USER CODE END USART1_MspDeInit 1 */
  254. }
  255. }
  256. /**
  257. * @brief PCD MSP Initialization
  258. * This function configures the hardware resources used in this example
  259. * @param hpcd: PCD handle pointer
  260. * @retval None
  261. */
  262. void HAL_PCD_MspInit(PCD_HandleTypeDef* hpcd)
  263. {
  264. GPIO_InitTypeDef GPIO_InitStruct = {0};
  265. if(hpcd->Instance==USB_OTG_FS)
  266. {
  267. /* USER CODE BEGIN USB_OTG_FS_MspInit 0 */
  268. /* USER CODE END USB_OTG_FS_MspInit 0 */
  269. __HAL_RCC_GPIOA_CLK_ENABLE();
  270. /**USB_OTG_FS GPIO Configuration
  271. PA11 ------> USB_OTG_FS_DM
  272. PA12 ------> USB_OTG_FS_DP
  273. */
  274. GPIO_InitStruct.Pin = GPIO_PIN_11|GPIO_PIN_12;
  275. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  276. GPIO_InitStruct.Pull = GPIO_NOPULL;
  277. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  278. GPIO_InitStruct.Alternate = GPIO_AF10_OTG_FS;
  279. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  280. /* Peripheral clock enable */
  281. __HAL_RCC_USB_OTG_FS_CLK_ENABLE();
  282. /* USER CODE BEGIN USB_OTG_FS_MspInit 1 */
  283. /* USER CODE END USB_OTG_FS_MspInit 1 */
  284. }
  285. }
  286. /**
  287. * @brief PCD MSP De-Initialization
  288. * This function freeze the hardware resources used in this example
  289. * @param hpcd: PCD handle pointer
  290. * @retval None
  291. */
  292. void HAL_PCD_MspDeInit(PCD_HandleTypeDef* hpcd)
  293. {
  294. if(hpcd->Instance==USB_OTG_FS)
  295. {
  296. /* USER CODE BEGIN USB_OTG_FS_MspDeInit 0 */
  297. /* USER CODE END USB_OTG_FS_MspDeInit 0 */
  298. /* Peripheral clock disable */
  299. __HAL_RCC_USB_OTG_FS_CLK_DISABLE();
  300. /**USB_OTG_FS GPIO Configuration
  301. PA11 ------> USB_OTG_FS_DM
  302. PA12 ------> USB_OTG_FS_DP
  303. */
  304. HAL_GPIO_DeInit(GPIOA, GPIO_PIN_11|GPIO_PIN_12);
  305. /* USER CODE BEGIN USB_OTG_FS_MspDeInit 1 */
  306. /* USER CODE END USB_OTG_FS_MspDeInit 1 */
  307. }
  308. }
  309. /* USER CODE BEGIN 1 */
  310. /* USER CODE END 1 */
  311. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/