stm32l4xx_hal_msp.c 9.5 KB

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