stm32f1xx_hal_msp.c 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  1. /* USER CODE BEGIN Header */
  2. /**
  3. ******************************************************************************
  4. * File Name : stm32f1xx_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) 2019 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. void HAL_TIM_MspPostInit(TIM_HandleTypeDef *htim);
  47. /**
  48. * Initializes the Global MSP.
  49. */
  50. void HAL_MspInit(void)
  51. {
  52. /* USER CODE BEGIN MspInit 0 */
  53. /* USER CODE END MspInit 0 */
  54. __HAL_RCC_AFIO_CLK_ENABLE();
  55. __HAL_RCC_PWR_CLK_ENABLE();
  56. /* System interrupt init*/
  57. /** NOJTAG: JTAG-DP Disabled and SW-DP Enabled
  58. */
  59. __HAL_AFIO_REMAP_SWJ_NOJTAG();
  60. /* USER CODE BEGIN MspInit 1 */
  61. /* USER CODE END MspInit 1 */
  62. }
  63. /**
  64. * @brief TIM_Encoder MSP Initialization
  65. * This function configures the hardware resources used in this example
  66. * @param htim_encoder: TIM_Encoder handle pointer
  67. * @retval None
  68. */
  69. void HAL_TIM_Encoder_MspInit(TIM_HandleTypeDef* htim_encoder)
  70. {
  71. GPIO_InitTypeDef GPIO_InitStruct = {0};
  72. if(htim_encoder->Instance==TIM1)
  73. {
  74. /* USER CODE BEGIN TIM1_MspInit 0 */
  75. /* USER CODE END TIM1_MspInit 0 */
  76. /* Peripheral clock enable */
  77. __HAL_RCC_TIM1_CLK_ENABLE();
  78. __HAL_RCC_GPIOA_CLK_ENABLE();
  79. /**TIM1 GPIO Configuration
  80. PA8 ------> TIM1_CH1
  81. PA9 ------> TIM1_CH2
  82. */
  83. GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_9;
  84. GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  85. GPIO_InitStruct.Pull = GPIO_NOPULL;
  86. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  87. /* USER CODE BEGIN TIM1_MspInit 1 */
  88. /* USER CODE END TIM1_MspInit 1 */
  89. }
  90. }
  91. /**
  92. * @brief TIM_Base MSP Initialization
  93. * This function configures the hardware resources used in this example
  94. * @param htim_base: TIM_Base handle pointer
  95. * @retval None
  96. */
  97. void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* htim_base)
  98. {
  99. if(htim_base->Instance==TIM3)
  100. {
  101. /* USER CODE BEGIN TIM3_MspInit 0 */
  102. /* USER CODE END TIM3_MspInit 0 */
  103. /* Peripheral clock enable */
  104. __HAL_RCC_TIM3_CLK_ENABLE();
  105. /* USER CODE BEGIN TIM3_MspInit 1 */
  106. /* USER CODE END TIM3_MspInit 1 */
  107. }
  108. else if(htim_base->Instance==TIM4)
  109. {
  110. /* USER CODE BEGIN TIM4_MspInit 0 */
  111. /* USER CODE END TIM4_MspInit 0 */
  112. /* Peripheral clock enable */
  113. __HAL_RCC_TIM4_CLK_ENABLE();
  114. /* USER CODE BEGIN TIM4_MspInit 1 */
  115. /* USER CODE END TIM4_MspInit 1 */
  116. }
  117. }
  118. void HAL_TIM_MspPostInit(TIM_HandleTypeDef* htim)
  119. {
  120. GPIO_InitTypeDef GPIO_InitStruct = {0};
  121. if(htim->Instance==TIM3)
  122. {
  123. /* USER CODE BEGIN TIM3_MspPostInit 0 */
  124. /* USER CODE END TIM3_MspPostInit 0 */
  125. __HAL_RCC_GPIOA_CLK_ENABLE();
  126. /**TIM3 GPIO Configuration
  127. PA6 ------> TIM3_CH1
  128. */
  129. GPIO_InitStruct.Pin = GPIO_PIN_6;
  130. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  131. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  132. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  133. /* USER CODE BEGIN TIM3_MspPostInit 1 */
  134. /* USER CODE END TIM3_MspPostInit 1 */
  135. }
  136. else if(htim->Instance==TIM4)
  137. {
  138. /* USER CODE BEGIN TIM4_MspPostInit 0 */
  139. /* USER CODE END TIM4_MspPostInit 0 */
  140. __HAL_RCC_GPIOB_CLK_ENABLE();
  141. /**TIM4 GPIO Configuration
  142. PB8 ------> TIM4_CH3
  143. PB9 ------> TIM4_CH4
  144. */
  145. GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_9;
  146. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  147. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  148. HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  149. /* USER CODE BEGIN TIM4_MspPostInit 1 */
  150. /* USER CODE END TIM4_MspPostInit 1 */
  151. }
  152. }
  153. /**
  154. * @brief TIM_Encoder MSP De-Initialization
  155. * This function freeze the hardware resources used in this example
  156. * @param htim_encoder: TIM_Encoder handle pointer
  157. * @retval None
  158. */
  159. void HAL_TIM_Encoder_MspDeInit(TIM_HandleTypeDef* htim_encoder)
  160. {
  161. if(htim_encoder->Instance==TIM1)
  162. {
  163. /* USER CODE BEGIN TIM1_MspDeInit 0 */
  164. /* USER CODE END TIM1_MspDeInit 0 */
  165. /* Peripheral clock disable */
  166. __HAL_RCC_TIM1_CLK_DISABLE();
  167. /**TIM1 GPIO Configuration
  168. PA8 ------> TIM1_CH1
  169. PA9 ------> TIM1_CH2
  170. */
  171. HAL_GPIO_DeInit(GPIOA, GPIO_PIN_8|GPIO_PIN_9);
  172. /* USER CODE BEGIN TIM1_MspDeInit 1 */
  173. /* USER CODE END TIM1_MspDeInit 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==TIM3)
  185. {
  186. /* USER CODE BEGIN TIM3_MspDeInit 0 */
  187. /* USER CODE END TIM3_MspDeInit 0 */
  188. /* Peripheral clock disable */
  189. __HAL_RCC_TIM3_CLK_DISABLE();
  190. /* USER CODE BEGIN TIM3_MspDeInit 1 */
  191. /* USER CODE END TIM3_MspDeInit 1 */
  192. }
  193. else if(htim_base->Instance==TIM4)
  194. {
  195. /* USER CODE BEGIN TIM4_MspDeInit 0 */
  196. /* USER CODE END TIM4_MspDeInit 0 */
  197. /* Peripheral clock disable */
  198. __HAL_RCC_TIM4_CLK_DISABLE();
  199. /* USER CODE BEGIN TIM4_MspDeInit 1 */
  200. /* USER CODE END TIM4_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==USART2)
  213. {
  214. /* USER CODE BEGIN USART2_MspInit 0 */
  215. /* USER CODE END USART2_MspInit 0 */
  216. /* Peripheral clock enable */
  217. __HAL_RCC_USART2_CLK_ENABLE();
  218. __HAL_RCC_GPIOA_CLK_ENABLE();
  219. /**USART2 GPIO Configuration
  220. PA2 ------> USART2_TX
  221. PA3 ------> USART2_RX
  222. */
  223. GPIO_InitStruct.Pin = GPIO_PIN_2;
  224. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  225. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
  226. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  227. GPIO_InitStruct.Pin = GPIO_PIN_3;
  228. GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  229. GPIO_InitStruct.Pull = GPIO_PULLUP;
  230. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  231. /* USER CODE BEGIN USART2_MspInit 1 */
  232. /* USER CODE END USART2_MspInit 1 */
  233. }
  234. else if(huart->Instance==USART3)
  235. {
  236. /* USER CODE BEGIN USART3_MspInit 0 */
  237. /* USER CODE END USART3_MspInit 0 */
  238. /* Peripheral clock enable */
  239. __HAL_RCC_USART3_CLK_ENABLE();
  240. __HAL_RCC_GPIOB_CLK_ENABLE();
  241. /**USART3 GPIO Configuration
  242. PB10 ------> USART3_TX
  243. PB11 ------> USART3_RX
  244. */
  245. GPIO_InitStruct.Pin = GPIO_PIN_10;
  246. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  247. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
  248. HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  249. GPIO_InitStruct.Pin = GPIO_PIN_11;
  250. GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  251. GPIO_InitStruct.Pull = GPIO_NOPULL;
  252. HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  253. /* USER CODE BEGIN USART3_MspInit 1 */
  254. /* USER CODE END USART3_MspInit 1 */
  255. }
  256. }
  257. /**
  258. * @brief UART MSP De-Initialization
  259. * This function freeze the hardware resources used in this example
  260. * @param huart: UART handle pointer
  261. * @retval None
  262. */
  263. void HAL_UART_MspDeInit(UART_HandleTypeDef* huart)
  264. {
  265. if(huart->Instance==USART2)
  266. {
  267. /* USER CODE BEGIN USART2_MspDeInit 0 */
  268. /* USER CODE END USART2_MspDeInit 0 */
  269. /* Peripheral clock disable */
  270. __HAL_RCC_USART2_CLK_DISABLE();
  271. /**USART2 GPIO Configuration
  272. PA2 ------> USART2_TX
  273. PA3 ------> USART2_RX
  274. */
  275. HAL_GPIO_DeInit(GPIOA, GPIO_PIN_2|GPIO_PIN_3);
  276. /* USER CODE BEGIN USART2_MspDeInit 1 */
  277. /* USER CODE END USART2_MspDeInit 1 */
  278. }
  279. else if(huart->Instance==USART3)
  280. {
  281. /* USER CODE BEGIN USART3_MspDeInit 0 */
  282. /* USER CODE END USART3_MspDeInit 0 */
  283. /* Peripheral clock disable */
  284. __HAL_RCC_USART3_CLK_DISABLE();
  285. /**USART3 GPIO Configuration
  286. PB10 ------> USART3_TX
  287. PB11 ------> USART3_RX
  288. */
  289. HAL_GPIO_DeInit(GPIOB, GPIO_PIN_10|GPIO_PIN_11);
  290. /* USER CODE BEGIN USART3_MspDeInit 1 */
  291. /* USER CODE END USART3_MspDeInit 1 */
  292. }
  293. }
  294. /* USER CODE BEGIN 1 */
  295. /* USER CODE END 1 */