stm32l0xx_hal_msp.c 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. /* USER CODE BEGIN Header */
  2. /**
  3. ******************************************************************************
  4. * @file stm32l0xx_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) 2023 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. extern DMA_HandleTypeDef hdma_usart2_tx;
  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 TIM_Base MSP Initialization
  96. * This function configures the hardware resources used in this example
  97. * @param htim_base: TIM_Base handle pointer
  98. * @retval None
  99. */
  100. void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* htim_base)
  101. {
  102. if(htim_base->Instance==TIM21)
  103. {
  104. /* USER CODE BEGIN TIM21_MspInit 0 */
  105. /* USER CODE END TIM21_MspInit 0 */
  106. /* Peripheral clock enable */
  107. __HAL_RCC_TIM21_CLK_ENABLE();
  108. /* TIM21 interrupt Init */
  109. HAL_NVIC_SetPriority(TIM21_IRQn, 0, 0);
  110. HAL_NVIC_EnableIRQ(TIM21_IRQn);
  111. /* USER CODE BEGIN TIM21_MspInit 1 */
  112. /* USER CODE END TIM21_MspInit 1 */
  113. }
  114. else if(htim_base->Instance==TIM22)
  115. {
  116. /* USER CODE BEGIN TIM22_MspInit 0 */
  117. /* USER CODE END TIM22_MspInit 0 */
  118. /* Peripheral clock enable */
  119. __HAL_RCC_TIM22_CLK_ENABLE();
  120. /* TIM22 interrupt Init */
  121. HAL_NVIC_SetPriority(TIM22_IRQn, 0, 0);
  122. HAL_NVIC_EnableIRQ(TIM22_IRQn);
  123. /* USER CODE BEGIN TIM22_MspInit 1 */
  124. /* USER CODE END TIM22_MspInit 1 */
  125. }
  126. }
  127. /**
  128. * @brief TIM_Base MSP De-Initialization
  129. * This function freeze the hardware resources used in this example
  130. * @param htim_base: TIM_Base handle pointer
  131. * @retval None
  132. */
  133. void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* htim_base)
  134. {
  135. if(htim_base->Instance==TIM21)
  136. {
  137. /* USER CODE BEGIN TIM21_MspDeInit 0 */
  138. /* USER CODE END TIM21_MspDeInit 0 */
  139. /* Peripheral clock disable */
  140. __HAL_RCC_TIM21_CLK_DISABLE();
  141. /* TIM21 interrupt DeInit */
  142. HAL_NVIC_DisableIRQ(TIM21_IRQn);
  143. /* USER CODE BEGIN TIM21_MspDeInit 1 */
  144. /* USER CODE END TIM21_MspDeInit 1 */
  145. }
  146. else if(htim_base->Instance==TIM22)
  147. {
  148. /* USER CODE BEGIN TIM22_MspDeInit 0 */
  149. /* USER CODE END TIM22_MspDeInit 0 */
  150. /* Peripheral clock disable */
  151. __HAL_RCC_TIM22_CLK_DISABLE();
  152. /* TIM22 interrupt DeInit */
  153. HAL_NVIC_DisableIRQ(TIM22_IRQn);
  154. /* USER CODE BEGIN TIM22_MspDeInit 1 */
  155. /* USER CODE END TIM22_MspDeInit 1 */
  156. }
  157. }
  158. /**
  159. * @brief UART MSP Initialization
  160. * This function configures the hardware resources used in this example
  161. * @param huart: UART handle pointer
  162. * @retval None
  163. */
  164. void HAL_UART_MspInit(UART_HandleTypeDef* huart)
  165. {
  166. GPIO_InitTypeDef GPIO_InitStruct = {0};
  167. if(huart->Instance==USART2)
  168. {
  169. /* USER CODE BEGIN USART2_MspInit 0 */
  170. /* USER CODE END USART2_MspInit 0 */
  171. /* Peripheral clock enable */
  172. __HAL_RCC_USART2_CLK_ENABLE();
  173. __HAL_RCC_GPIOA_CLK_ENABLE();
  174. /**USART2 GPIO Configuration
  175. PA2 ------> USART2_TX
  176. PA15 ------> USART2_RX
  177. */
  178. GPIO_InitStruct.Pin = VCP_TX_Pin|VCP_RX_Pin;
  179. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  180. GPIO_InitStruct.Pull = GPIO_NOPULL;
  181. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  182. GPIO_InitStruct.Alternate = GPIO_AF4_USART2;
  183. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  184. /* USART2 DMA Init */
  185. /* USART2_TX Init */
  186. hdma_usart2_tx.Instance = DMA1_Channel4;
  187. hdma_usart2_tx.Init.Request = DMA_REQUEST_4;
  188. hdma_usart2_tx.Init.Direction = DMA_MEMORY_TO_PERIPH;
  189. hdma_usart2_tx.Init.PeriphInc = DMA_PINC_DISABLE;
  190. hdma_usart2_tx.Init.MemInc = DMA_MINC_ENABLE;
  191. hdma_usart2_tx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
  192. hdma_usart2_tx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
  193. hdma_usart2_tx.Init.Mode = DMA_NORMAL;
  194. hdma_usart2_tx.Init.Priority = DMA_PRIORITY_LOW;
  195. if (HAL_DMA_Init(&hdma_usart2_tx) != HAL_OK)
  196. {
  197. Error_Handler();
  198. }
  199. __HAL_LINKDMA(huart,hdmatx,hdma_usart2_tx);
  200. /* USART2 interrupt Init */
  201. HAL_NVIC_SetPriority(USART2_IRQn, 0, 0);
  202. HAL_NVIC_EnableIRQ(USART2_IRQn);
  203. /* USER CODE BEGIN USART2_MspInit 1 */
  204. /* USER CODE END USART2_MspInit 1 */
  205. }
  206. }
  207. /**
  208. * @brief UART MSP De-Initialization
  209. * This function freeze the hardware resources used in this example
  210. * @param huart: UART handle pointer
  211. * @retval None
  212. */
  213. void HAL_UART_MspDeInit(UART_HandleTypeDef* huart)
  214. {
  215. if(huart->Instance==USART2)
  216. {
  217. /* USER CODE BEGIN USART2_MspDeInit 0 */
  218. /* USER CODE END USART2_MspDeInit 0 */
  219. /* Peripheral clock disable */
  220. __HAL_RCC_USART2_CLK_DISABLE();
  221. /**USART2 GPIO Configuration
  222. PA2 ------> USART2_TX
  223. PA15 ------> USART2_RX
  224. */
  225. HAL_GPIO_DeInit(GPIOA, VCP_TX_Pin|VCP_RX_Pin);
  226. /* USART2 DMA DeInit */
  227. HAL_DMA_DeInit(huart->hdmatx);
  228. /* USART2 interrupt DeInit */
  229. HAL_NVIC_DisableIRQ(USART2_IRQn);
  230. /* USER CODE BEGIN USART2_MspDeInit 1 */
  231. /* USER CODE END USART2_MspDeInit 1 */
  232. }
  233. }
  234. /* USER CODE BEGIN 1 */
  235. /* USER CODE END 1 */