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