stm32f1xx_hal_msp.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. #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. __HAL_RCC_AFIO_CLK_ENABLE();
  54. __HAL_RCC_PWR_CLK_ENABLE();
  55. /* System interrupt init*/
  56. /** NOJTAG: JTAG-DP Disabled and SW-DP Enabled
  57. */
  58. __HAL_AFIO_REMAP_SWJ_NOJTAG();
  59. /* USER CODE BEGIN MspInit 1 */
  60. /* USER CODE END MspInit 1 */
  61. }
  62. /**
  63. * @brief UART MSP Initialization
  64. * This function configures the hardware resources used in this example
  65. * @param huart: UART handle pointer
  66. * @retval None
  67. */
  68. void HAL_UART_MspInit(UART_HandleTypeDef* huart)
  69. {
  70. GPIO_InitTypeDef GPIO_InitStruct = {0};
  71. if(huart->Instance==USART1)
  72. {
  73. /* USER CODE BEGIN USART1_MspInit 0 */
  74. /* USER CODE END USART1_MspInit 0 */
  75. /* Peripheral clock enable */
  76. __HAL_RCC_USART1_CLK_ENABLE();
  77. __HAL_RCC_GPIOA_CLK_ENABLE();
  78. /**USART1 GPIO Configuration
  79. PA9 ------> USART1_TX
  80. PA10 ------> USART1_RX
  81. */
  82. GPIO_InitStruct.Pin = GPIO_PIN_9;
  83. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  84. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
  85. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  86. GPIO_InitStruct.Pin = GPIO_PIN_10;
  87. GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  88. GPIO_InitStruct.Pull = GPIO_NOPULL;
  89. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  90. /* USER CODE BEGIN USART1_MspInit 1 */
  91. /* USER CODE END USART1_MspInit 1 */
  92. }
  93. }
  94. /**
  95. * @brief UART MSP De-Initialization
  96. * This function freeze the hardware resources used in this example
  97. * @param huart: UART handle pointer
  98. * @retval None
  99. */
  100. void HAL_UART_MspDeInit(UART_HandleTypeDef* huart)
  101. {
  102. if(huart->Instance==USART1)
  103. {
  104. /* USER CODE BEGIN USART1_MspDeInit 0 */
  105. /* USER CODE END USART1_MspDeInit 0 */
  106. /* Peripheral clock disable */
  107. __HAL_RCC_USART1_CLK_DISABLE();
  108. /**USART1 GPIO Configuration
  109. PA9 ------> USART1_TX
  110. PA10 ------> USART1_RX
  111. */
  112. HAL_GPIO_DeInit(GPIOA, GPIO_PIN_9|GPIO_PIN_10);
  113. /* USER CODE BEGIN USART1_MspDeInit 1 */
  114. /* USER CODE END USART1_MspDeInit 1 */
  115. }
  116. }
  117. /* USER CODE BEGIN 1 */
  118. /* USER CODE END 1 */