stm32f1xx_hal_msp.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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. /* USER CODE END Includes */
  25. extern DMA_HandleTypeDef hdma_usart1_rx;
  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_AFIO_CLK_ENABLE();
  54. __HAL_RCC_PWR_CLK_ENABLE();
  55. /* System interrupt init*/
  56. /** DISABLE: JTAG-DP Disabled and SW-DP Disabled
  57. */
  58. __HAL_AFIO_REMAP_SWJ_DISABLE();
  59. /* USER CODE BEGIN MspInit 1 */
  60. /* USER CODE END MspInit 1 */
  61. }
  62. /**
  63. * @brief TIM_Base MSP Initialization
  64. * This function configures the hardware resources used in this example
  65. * @param htim_base: TIM_Base handle pointer
  66. * @retval None
  67. */
  68. void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* htim_base)
  69. {
  70. if(htim_base->Instance==TIM6)
  71. {
  72. /* USER CODE BEGIN TIM6_MspInit 0 */
  73. /* USER CODE END TIM6_MspInit 0 */
  74. /* Peripheral clock enable */
  75. __HAL_RCC_TIM6_CLK_ENABLE();
  76. /* USER CODE BEGIN TIM6_MspInit 1 */
  77. /* USER CODE END TIM6_MspInit 1 */
  78. }
  79. }
  80. /**
  81. * @brief TIM_Base MSP De-Initialization
  82. * This function freeze the hardware resources used in this example
  83. * @param htim_base: TIM_Base handle pointer
  84. * @retval None
  85. */
  86. void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* htim_base)
  87. {
  88. if(htim_base->Instance==TIM6)
  89. {
  90. /* USER CODE BEGIN TIM6_MspDeInit 0 */
  91. /* USER CODE END TIM6_MspDeInit 0 */
  92. /* Peripheral clock disable */
  93. __HAL_RCC_TIM6_CLK_DISABLE();
  94. /* TIM6 interrupt DeInit */
  95. HAL_NVIC_DisableIRQ(TIM6_IRQn);
  96. /* USER CODE BEGIN TIM6_MspDeInit 1 */
  97. /* USER CODE END TIM6_MspDeInit 1 */
  98. }
  99. }
  100. /**
  101. * @brief UART MSP Initialization
  102. * This function configures the hardware resources used in this example
  103. * @param huart: UART handle pointer
  104. * @retval None
  105. */
  106. void HAL_UART_MspInit(UART_HandleTypeDef* huart)
  107. {
  108. GPIO_InitTypeDef GPIO_InitStruct = {0};
  109. if(huart->Instance==USART1)
  110. {
  111. /* USER CODE BEGIN USART1_MspInit 0 */
  112. /* USER CODE END USART1_MspInit 0 */
  113. /* Peripheral clock enable */
  114. __HAL_RCC_USART1_CLK_ENABLE();
  115. __HAL_RCC_GPIOA_CLK_ENABLE();
  116. /**USART1 GPIO Configuration
  117. PA9 ------> USART1_TX
  118. PA10 ------> USART1_RX
  119. */
  120. GPIO_InitStruct.Pin = GPIO_PIN_9;
  121. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  122. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
  123. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  124. GPIO_InitStruct.Pin = GPIO_PIN_10;
  125. GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  126. GPIO_InitStruct.Pull = GPIO_NOPULL;
  127. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  128. /* USART1 DMA Init */
  129. /* USART1_RX Init */
  130. hdma_usart1_rx.Instance = DMA1_Channel5;
  131. hdma_usart1_rx.Init.Direction = DMA_PERIPH_TO_MEMORY;
  132. hdma_usart1_rx.Init.PeriphInc = DMA_PINC_DISABLE;
  133. hdma_usart1_rx.Init.MemInc = DMA_MINC_ENABLE;
  134. hdma_usart1_rx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
  135. hdma_usart1_rx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
  136. hdma_usart1_rx.Init.Mode = DMA_NORMAL;
  137. hdma_usart1_rx.Init.Priority = DMA_PRIORITY_LOW;
  138. if (HAL_DMA_Init(&hdma_usart1_rx) != HAL_OK)
  139. {
  140. Error_Handler();
  141. }
  142. __HAL_LINKDMA(huart,hdmarx,hdma_usart1_rx);
  143. /* USER CODE BEGIN USART1_MspInit 1 */
  144. /* USER CODE END USART1_MspInit 1 */
  145. }
  146. }
  147. /**
  148. * @brief UART MSP De-Initialization
  149. * This function freeze the hardware resources used in this example
  150. * @param huart: UART handle pointer
  151. * @retval None
  152. */
  153. void HAL_UART_MspDeInit(UART_HandleTypeDef* huart)
  154. {
  155. if(huart->Instance==USART1)
  156. {
  157. /* USER CODE BEGIN USART1_MspDeInit 0 */
  158. /* USER CODE END USART1_MspDeInit 0 */
  159. /* Peripheral clock disable */
  160. __HAL_RCC_USART1_CLK_DISABLE();
  161. /**USART1 GPIO Configuration
  162. PA9 ------> USART1_TX
  163. PA10 ------> USART1_RX
  164. */
  165. HAL_GPIO_DeInit(GPIOA, GPIO_PIN_9|GPIO_PIN_10);
  166. /* USART1 DMA DeInit */
  167. HAL_DMA_DeInit(huart->hdmarx);
  168. /* USART1 interrupt DeInit */
  169. HAL_NVIC_DisableIRQ(USART1_IRQn);
  170. /* USER CODE BEGIN USART1_MspDeInit 1 */
  171. /* USER CODE END USART1_MspDeInit 1 */
  172. }
  173. }
  174. /* USER CODE BEGIN 1 */
  175. /* USER CODE END 1 */
  176. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/