stm32l0xx_hal_msp.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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 TIM_Base MSP Initialization
  60. * This function configures the hardware resources used in this example
  61. * @param htim_base: TIM_Base handle pointer
  62. * @retval None
  63. */
  64. void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* htim_base)
  65. {
  66. if(htim_base->Instance==TIM22)
  67. {
  68. /* USER CODE BEGIN TIM22_MspInit 0 */
  69. /* USER CODE END TIM22_MspInit 0 */
  70. /* Peripheral clock enable */
  71. __HAL_RCC_TIM22_CLK_ENABLE();
  72. /* TIM22 interrupt Init */
  73. HAL_NVIC_SetPriority(TIM22_IRQn, 0, 0);
  74. HAL_NVIC_EnableIRQ(TIM22_IRQn);
  75. /* USER CODE BEGIN TIM22_MspInit 1 */
  76. /* USER CODE END TIM22_MspInit 1 */
  77. }
  78. }
  79. /**
  80. * @brief TIM_Base MSP De-Initialization
  81. * This function freeze the hardware resources used in this example
  82. * @param htim_base: TIM_Base handle pointer
  83. * @retval None
  84. */
  85. void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* htim_base)
  86. {
  87. if(htim_base->Instance==TIM22)
  88. {
  89. /* USER CODE BEGIN TIM22_MspDeInit 0 */
  90. /* USER CODE END TIM22_MspDeInit 0 */
  91. /* Peripheral clock disable */
  92. __HAL_RCC_TIM22_CLK_DISABLE();
  93. /* TIM22 interrupt DeInit */
  94. HAL_NVIC_DisableIRQ(TIM22_IRQn);
  95. /* USER CODE BEGIN TIM22_MspDeInit 1 */
  96. /* USER CODE END TIM22_MspDeInit 1 */
  97. }
  98. }
  99. /**
  100. * @brief UART MSP Initialization
  101. * This function configures the hardware resources used in this example
  102. * @param huart: UART handle pointer
  103. * @retval None
  104. */
  105. void HAL_UART_MspInit(UART_HandleTypeDef* huart)
  106. {
  107. GPIO_InitTypeDef GPIO_InitStruct = {0};
  108. if(huart->Instance==USART2)
  109. {
  110. /* USER CODE BEGIN USART2_MspInit 0 */
  111. /* USER CODE END USART2_MspInit 0 */
  112. /* Peripheral clock enable */
  113. __HAL_RCC_USART2_CLK_ENABLE();
  114. __HAL_RCC_GPIOA_CLK_ENABLE();
  115. /**USART2 GPIO Configuration
  116. PA2 ------> USART2_TX
  117. PA15 ------> USART2_RX
  118. */
  119. GPIO_InitStruct.Pin = VCP_TX_Pin|VCP_RX_Pin;
  120. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  121. GPIO_InitStruct.Pull = GPIO_NOPULL;
  122. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  123. GPIO_InitStruct.Alternate = GPIO_AF4_USART2;
  124. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  125. /* USART2 DMA Init */
  126. /* USART2_TX Init */
  127. hdma_usart2_tx.Instance = DMA1_Channel4;
  128. hdma_usart2_tx.Init.Request = DMA_REQUEST_4;
  129. hdma_usart2_tx.Init.Direction = DMA_MEMORY_TO_PERIPH;
  130. hdma_usart2_tx.Init.PeriphInc = DMA_PINC_DISABLE;
  131. hdma_usart2_tx.Init.MemInc = DMA_MINC_ENABLE;
  132. hdma_usart2_tx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
  133. hdma_usart2_tx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
  134. hdma_usart2_tx.Init.Mode = DMA_NORMAL;
  135. hdma_usart2_tx.Init.Priority = DMA_PRIORITY_LOW;
  136. if (HAL_DMA_Init(&hdma_usart2_tx) != HAL_OK)
  137. {
  138. Error_Handler();
  139. }
  140. __HAL_LINKDMA(huart,hdmatx,hdma_usart2_tx);
  141. /* USART2 interrupt Init */
  142. HAL_NVIC_SetPriority(USART2_IRQn, 0, 0);
  143. HAL_NVIC_EnableIRQ(USART2_IRQn);
  144. /* USER CODE BEGIN USART2_MspInit 1 */
  145. /* USER CODE END USART2_MspInit 1 */
  146. }
  147. }
  148. /**
  149. * @brief UART MSP De-Initialization
  150. * This function freeze the hardware resources used in this example
  151. * @param huart: UART handle pointer
  152. * @retval None
  153. */
  154. void HAL_UART_MspDeInit(UART_HandleTypeDef* huart)
  155. {
  156. if(huart->Instance==USART2)
  157. {
  158. /* USER CODE BEGIN USART2_MspDeInit 0 */
  159. /* USER CODE END USART2_MspDeInit 0 */
  160. /* Peripheral clock disable */
  161. __HAL_RCC_USART2_CLK_DISABLE();
  162. /**USART2 GPIO Configuration
  163. PA2 ------> USART2_TX
  164. PA15 ------> USART2_RX
  165. */
  166. HAL_GPIO_DeInit(GPIOA, VCP_TX_Pin|VCP_RX_Pin);
  167. /* USART2 DMA DeInit */
  168. HAL_DMA_DeInit(huart->hdmatx);
  169. /* USART2 interrupt DeInit */
  170. HAL_NVIC_DisableIRQ(USART2_IRQn);
  171. /* USER CODE BEGIN USART2_MspDeInit 1 */
  172. /* USER CODE END USART2_MspDeInit 1 */
  173. }
  174. }
  175. /* USER CODE BEGIN 1 */
  176. /* USER CODE END 1 */