1
0

stm32wlxx_hal_msp.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. /* USER CODE BEGIN Header */
  2. /**
  3. ******************************************************************************
  4. * @file stm32wlxx_hal_msp.c
  5. * @brief This file provides code for the MSP Initialization
  6. * and de-Initialization codes.
  7. ******************************************************************************
  8. * @attention
  9. *
  10. * <h2><center>&copy; Copyright (c) 2022 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. /**
  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. /* System interrupt init*/
  54. /* USER CODE BEGIN MspInit 1 */
  55. /* USER CODE END MspInit 1 */
  56. }
  57. /**
  58. * @brief UART MSP Initialization
  59. * This function configures the hardware resources used in this example
  60. * @param huart: UART handle pointer
  61. * @retval None
  62. */
  63. void HAL_UART_MspInit(UART_HandleTypeDef* huart)
  64. {
  65. GPIO_InitTypeDef GPIO_InitStruct = {0};
  66. RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
  67. if(huart->Instance==LPUART1)
  68. {
  69. /* USER CODE BEGIN LPUART1_MspInit 0 */
  70. /* USER CODE END LPUART1_MspInit 0 */
  71. /** Initializes the peripherals clocks
  72. */
  73. PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_LPUART1;
  74. PeriphClkInitStruct.Lpuart1ClockSelection = RCC_LPUART1CLKSOURCE_PCLK1;
  75. if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
  76. {
  77. Error_Handler();
  78. }
  79. /* Peripheral clock enable */
  80. __HAL_RCC_LPUART1_CLK_ENABLE();
  81. __HAL_RCC_GPIOA_CLK_ENABLE();
  82. /**LPUART1 GPIO Configuration
  83. PA3 ------> LPUART1_RX
  84. PA2 ------> LPUART1_TX
  85. */
  86. GPIO_InitStruct.Pin = GPIO_PIN_3|GPIO_PIN_2;
  87. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  88. GPIO_InitStruct.Pull = GPIO_PULLUP;
  89. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  90. GPIO_InitStruct.Alternate = GPIO_AF8_LPUART1;
  91. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  92. /* USER CODE BEGIN LPUART1_MspInit 1 */
  93. /* USER CODE END LPUART1_MspInit 1 */
  94. }
  95. else if(huart->Instance==USART1)
  96. {
  97. /* USER CODE BEGIN USART1_MspInit 0 */
  98. /* USER CODE END USART1_MspInit 0 */
  99. /** Initializes the peripherals clocks
  100. */
  101. PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_USART1;
  102. PeriphClkInitStruct.Usart1ClockSelection = RCC_USART1CLKSOURCE_SYSCLK;
  103. if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
  104. {
  105. Error_Handler();
  106. }
  107. /* Peripheral clock enable */
  108. __HAL_RCC_USART1_CLK_ENABLE();
  109. __HAL_RCC_GPIOB_CLK_ENABLE();
  110. /**USART1 GPIO Configuration
  111. PB7 ------> USART1_RX
  112. PB6 ------> USART1_TX
  113. */
  114. GPIO_InitStruct.Pin = GPIO_PIN_7|GPIO_PIN_6;
  115. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  116. GPIO_InitStruct.Pull = GPIO_PULLUP;
  117. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  118. GPIO_InitStruct.Alternate = GPIO_AF7_USART1;
  119. HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  120. /* USER CODE BEGIN USART1_MspInit 1 */
  121. /* USER CODE END USART1_MspInit 1 */
  122. }
  123. }
  124. /**
  125. * @brief UART MSP De-Initialization
  126. * This function freeze the hardware resources used in this example
  127. * @param huart: UART handle pointer
  128. * @retval None
  129. */
  130. void HAL_UART_MspDeInit(UART_HandleTypeDef* huart)
  131. {
  132. if(huart->Instance==LPUART1)
  133. {
  134. /* USER CODE BEGIN LPUART1_MspDeInit 0 */
  135. /* USER CODE END LPUART1_MspDeInit 0 */
  136. /* Peripheral clock disable */
  137. __HAL_RCC_LPUART1_CLK_DISABLE();
  138. /**LPUART1 GPIO Configuration
  139. PA3 ------> LPUART1_RX
  140. PA2 ------> LPUART1_TX
  141. */
  142. HAL_GPIO_DeInit(GPIOA, GPIO_PIN_3|GPIO_PIN_2);
  143. /* USER CODE BEGIN LPUART1_MspDeInit 1 */
  144. /* USER CODE END LPUART1_MspDeInit 1 */
  145. }
  146. else if(huart->Instance==USART1)
  147. {
  148. /* USER CODE BEGIN USART1_MspDeInit 0 */
  149. /* USER CODE END USART1_MspDeInit 0 */
  150. /* Peripheral clock disable */
  151. __HAL_RCC_USART1_CLK_DISABLE();
  152. /**USART1 GPIO Configuration
  153. PB7 ------> USART1_RX
  154. PB6 ------> USART1_TX
  155. */
  156. HAL_GPIO_DeInit(GPIOB, GPIO_PIN_7|GPIO_PIN_6);
  157. /* USER CODE BEGIN USART1_MspDeInit 1 */
  158. /* USER CODE END USART1_MspDeInit 1 */
  159. }
  160. }
  161. /* USER CODE BEGIN 1 */
  162. /* USER CODE END 1 */
  163. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/