stm32f1xx_hal_msp.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. /* USER CODE BEGIN Header */
  2. /**
  3. ******************************************************************************
  4. * @file stm32f1xx_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) 2022 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. void HAL_TIM_MspPostInit(TIM_HandleTypeDef *htim);
  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_AFIO_CLK_ENABLE();
  53. __HAL_RCC_PWR_CLK_ENABLE();
  54. /* System interrupt init*/
  55. /** NOJTAG: JTAG-DP Disabled and SW-DP Enabled
  56. */
  57. __HAL_AFIO_REMAP_SWJ_NOJTAG();
  58. /* USER CODE BEGIN MspInit 1 */
  59. /* USER CODE END MspInit 1 */
  60. }
  61. /**
  62. * @brief ADC MSP Initialization
  63. * This function configures the hardware resources used in this example
  64. * @param hadc: ADC handle pointer
  65. * @retval None
  66. */
  67. void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc)
  68. {
  69. GPIO_InitTypeDef GPIO_InitStruct = {0};
  70. if(hadc->Instance==ADC1)
  71. {
  72. /* USER CODE BEGIN ADC1_MspInit 0 */
  73. /* USER CODE END ADC1_MspInit 0 */
  74. /* Peripheral clock enable */
  75. __HAL_RCC_ADC1_CLK_ENABLE();
  76. __HAL_RCC_GPIOA_CLK_ENABLE();
  77. /**ADC1 GPIO Configuration
  78. PA5 ------> ADC1_IN5
  79. */
  80. GPIO_InitStruct.Pin = GPIO_PIN_5;
  81. GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
  82. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  83. /* USER CODE BEGIN ADC1_MspInit 1 */
  84. /* USER CODE END ADC1_MspInit 1 */
  85. }
  86. }
  87. /**
  88. * @brief ADC MSP De-Initialization
  89. * This function freeze the hardware resources used in this example
  90. * @param hadc: ADC handle pointer
  91. * @retval None
  92. */
  93. void HAL_ADC_MspDeInit(ADC_HandleTypeDef* hadc)
  94. {
  95. if(hadc->Instance==ADC1)
  96. {
  97. /* USER CODE BEGIN ADC1_MspDeInit 0 */
  98. /* USER CODE END ADC1_MspDeInit 0 */
  99. /* Peripheral clock disable */
  100. __HAL_RCC_ADC1_CLK_DISABLE();
  101. /**ADC1 GPIO Configuration
  102. PA5 ------> ADC1_IN5
  103. */
  104. HAL_GPIO_DeInit(GPIOA, GPIO_PIN_5);
  105. /* ADC1 interrupt DeInit */
  106. HAL_NVIC_DisableIRQ(ADC1_2_IRQn);
  107. /* USER CODE BEGIN ADC1_MspDeInit 1 */
  108. /* USER CODE END ADC1_MspDeInit 1 */
  109. }
  110. }
  111. /**
  112. * @brief TIM_Base MSP Initialization
  113. * This function configures the hardware resources used in this example
  114. * @param htim_base: TIM_Base handle pointer
  115. * @retval None
  116. */
  117. void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* htim_base)
  118. {
  119. if(htim_base->Instance==TIM1)
  120. {
  121. /* USER CODE BEGIN TIM1_MspInit 0 */
  122. /* USER CODE END TIM1_MspInit 0 */
  123. /* Peripheral clock enable */
  124. __HAL_RCC_TIM1_CLK_ENABLE();
  125. /* USER CODE BEGIN TIM1_MspInit 1 */
  126. /* USER CODE END TIM1_MspInit 1 */
  127. }
  128. }
  129. void HAL_TIM_MspPostInit(TIM_HandleTypeDef* htim)
  130. {
  131. GPIO_InitTypeDef GPIO_InitStruct = {0};
  132. if(htim->Instance==TIM1)
  133. {
  134. /* USER CODE BEGIN TIM1_MspPostInit 0 */
  135. /* USER CODE END TIM1_MspPostInit 0 */
  136. __HAL_RCC_GPIOA_CLK_ENABLE();
  137. /**TIM1 GPIO Configuration
  138. PA8 ------> TIM1_CH1
  139. */
  140. GPIO_InitStruct.Pin = GPIO_PIN_8;
  141. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  142. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  143. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  144. /* USER CODE BEGIN TIM1_MspPostInit 1 */
  145. /* USER CODE END TIM1_MspPostInit 1 */
  146. }
  147. }
  148. /**
  149. * @brief TIM_Base MSP De-Initialization
  150. * This function freeze the hardware resources used in this example
  151. * @param htim_base: TIM_Base handle pointer
  152. * @retval None
  153. */
  154. void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* htim_base)
  155. {
  156. if(htim_base->Instance==TIM1)
  157. {
  158. /* USER CODE BEGIN TIM1_MspDeInit 0 */
  159. /* USER CODE END TIM1_MspDeInit 0 */
  160. /* Peripheral clock disable */
  161. __HAL_RCC_TIM1_CLK_DISABLE();
  162. /* USER CODE BEGIN TIM1_MspDeInit 1 */
  163. /* USER CODE END TIM1_MspDeInit 1 */
  164. }
  165. }
  166. /**
  167. * @brief UART MSP Initialization
  168. * This function configures the hardware resources used in this example
  169. * @param huart: UART handle pointer
  170. * @retval None
  171. */
  172. void HAL_UART_MspInit(UART_HandleTypeDef* huart)
  173. {
  174. GPIO_InitTypeDef GPIO_InitStruct = {0};
  175. if(huart->Instance==USART2)
  176. {
  177. /* USER CODE BEGIN USART2_MspInit 0 */
  178. /* USER CODE END USART2_MspInit 0 */
  179. /* Peripheral clock enable */
  180. __HAL_RCC_USART2_CLK_ENABLE();
  181. __HAL_RCC_GPIOA_CLK_ENABLE();
  182. /**USART2 GPIO Configuration
  183. PA2 ------> USART2_TX
  184. PA3 ------> USART2_RX
  185. */
  186. GPIO_InitStruct.Pin = GPIO_PIN_2;
  187. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  188. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
  189. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  190. GPIO_InitStruct.Pin = GPIO_PIN_3;
  191. GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  192. GPIO_InitStruct.Pull = GPIO_NOPULL;
  193. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  194. /* USER CODE BEGIN USART2_MspInit 1 */
  195. /* USER CODE END USART2_MspInit 1 */
  196. }
  197. }
  198. /**
  199. * @brief UART MSP De-Initialization
  200. * This function freeze the hardware resources used in this example
  201. * @param huart: UART handle pointer
  202. * @retval None
  203. */
  204. void HAL_UART_MspDeInit(UART_HandleTypeDef* huart)
  205. {
  206. if(huart->Instance==USART2)
  207. {
  208. /* USER CODE BEGIN USART2_MspDeInit 0 */
  209. /* USER CODE END USART2_MspDeInit 0 */
  210. /* Peripheral clock disable */
  211. __HAL_RCC_USART2_CLK_DISABLE();
  212. /**USART2 GPIO Configuration
  213. PA2 ------> USART2_TX
  214. PA3 ------> USART2_RX
  215. */
  216. HAL_GPIO_DeInit(GPIOA, GPIO_PIN_2|GPIO_PIN_3);
  217. /* USART2 interrupt DeInit */
  218. HAL_NVIC_DisableIRQ(USART2_IRQn);
  219. /* USER CODE BEGIN USART2_MspDeInit 1 */
  220. /* USER CODE END USART2_MspDeInit 1 */
  221. }
  222. }
  223. /* USER CODE BEGIN 1 */
  224. /* USER CODE END 1 */