stm32f1xx_hal_msp.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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. ** This notice applies to any and all portions of this file
  9. * that are not between comment pairs USER CODE BEGIN and
  10. * USER CODE END. Other portions of this file, whether
  11. * inserted by the user or by software development tools
  12. * are owned by their respective copyright owners.
  13. *
  14. * COPYRIGHT(c) 2018 STMicroelectronics
  15. *
  16. * Redistribution and use in source and binary forms, with or without modification,
  17. * are permitted provided that the following conditions are met:
  18. * 1. Redistributions of source code must retain the above copyright notice,
  19. * this list of conditions and the following disclaimer.
  20. * 2. Redistributions in binary form must reproduce the above copyright notice,
  21. * this list of conditions and the following disclaimer in the documentation
  22. * and/or other materials provided with the distribution.
  23. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  24. * may be used to endorse or promote products derived from this software
  25. * without specific prior written permission.
  26. *
  27. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  28. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  29. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  30. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  31. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  32. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  33. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  34. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  35. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  36. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  37. *
  38. ******************************************************************************
  39. */
  40. /* USER CODE END Header */
  41. /* Includes ------------------------------------------------------------------*/
  42. #include "main.h"
  43. /* USER CODE BEGIN Includes */
  44. #include <drv_common.h>
  45. /* USER CODE END Includes */
  46. /* Private typedef -----------------------------------------------------------*/
  47. /* USER CODE BEGIN TD */
  48. /* USER CODE END TD */
  49. /* Private define ------------------------------------------------------------*/
  50. /* USER CODE BEGIN Define */
  51. /* USER CODE END Define */
  52. /* Private macro -------------------------------------------------------------*/
  53. /* USER CODE BEGIN Macro */
  54. /* USER CODE END Macro */
  55. /* Private variables ---------------------------------------------------------*/
  56. /* USER CODE BEGIN PV */
  57. /* USER CODE END PV */
  58. /* Private function prototypes -----------------------------------------------*/
  59. /* USER CODE BEGIN PFP */
  60. /* USER CODE END PFP */
  61. /* External functions --------------------------------------------------------*/
  62. /* USER CODE BEGIN ExternalFunctions */
  63. /* USER CODE END ExternalFunctions */
  64. /* USER CODE BEGIN 0 */
  65. /* USER CODE END 0 */
  66. /**
  67. * Initializes the Global MSP.
  68. */
  69. void HAL_MspInit(void)
  70. {
  71. /* USER CODE BEGIN MspInit 0 */
  72. /* USER CODE END MspInit 0 */
  73. __HAL_RCC_AFIO_CLK_ENABLE();
  74. __HAL_RCC_PWR_CLK_ENABLE();
  75. /* System interrupt init*/
  76. /**NOJTAG: JTAG-DP Disabled and SW-DP Enabled
  77. */
  78. __HAL_AFIO_REMAP_SWJ_NOJTAG();
  79. /* USER CODE BEGIN MspInit 1 */
  80. /* USER CODE END MspInit 1 */
  81. }
  82. /**
  83. * @brief UART MSP Initialization
  84. * This function configures the hardware resources used in this example
  85. * @param huart: UART handle pointer
  86. * @retval None
  87. */
  88. void HAL_UART_MspInit(UART_HandleTypeDef* huart)
  89. {
  90. GPIO_InitTypeDef GPIO_InitStruct = {0};
  91. if(huart->Instance==USART2)
  92. {
  93. /* USER CODE BEGIN USART2_MspInit 0 */
  94. /* USER CODE END USART2_MspInit 0 */
  95. /* Peripheral clock enable */
  96. __HAL_RCC_USART2_CLK_ENABLE();
  97. __HAL_RCC_GPIOD_CLK_ENABLE();
  98. /**USART2 GPIO Configuration
  99. PD5 ------> USART2_TX
  100. PD6 ------> USART2_RX
  101. */
  102. GPIO_InitStruct.Pin = GPIO_PIN_5;
  103. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  104. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
  105. HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
  106. GPIO_InitStruct.Pin = GPIO_PIN_6;
  107. GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  108. GPIO_InitStruct.Pull = GPIO_PULLUP;
  109. HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
  110. __HAL_AFIO_REMAP_USART2_ENABLE();
  111. /* USART2 interrupt Init */
  112. HAL_NVIC_SetPriority(USART2_IRQn, 0, 0);
  113. HAL_NVIC_EnableIRQ(USART2_IRQn);
  114. /* USER CODE BEGIN USART2_MspInit 1 */
  115. /* USER CODE END USART2_MspInit 1 */
  116. }
  117. }
  118. /**
  119. * @brief UART MSP De-Initialization
  120. * This function freeze the hardware resources used in this example
  121. * @param huart: UART handle pointer
  122. * @retval None
  123. */
  124. void HAL_UART_MspDeInit(UART_HandleTypeDef* huart)
  125. {
  126. if(huart->Instance==USART2)
  127. {
  128. /* USER CODE BEGIN USART2_MspDeInit 0 */
  129. /* USER CODE END USART2_MspDeInit 0 */
  130. /* Peripheral clock disable */
  131. __HAL_RCC_USART2_CLK_DISABLE();
  132. /**USART2 GPIO Configuration
  133. PD5 ------> USART2_TX
  134. PD6 ------> USART2_RX
  135. */
  136. HAL_GPIO_DeInit(GPIOD, GPIO_PIN_5|GPIO_PIN_6);
  137. /* USART2 interrupt DeInit */
  138. HAL_NVIC_DisableIRQ(USART2_IRQn);
  139. /* USER CODE BEGIN USART2_MspDeInit 1 */
  140. /* USER CODE END USART2_MspDeInit 1 */
  141. }
  142. }
  143. /* USER CODE BEGIN 1 */
  144. /* USER CODE END 1 */
  145. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/