stm32h7xx_hal_msp.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /* USER CODE BEGIN Header */
  2. /**
  3. ******************************************************************************
  4. * @file stm32h7xx_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) 2021 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. extern void _Error_Handler(char *s, int num);
  25. #define Error_Handler() _Error_Handler(__FILE__, __LINE__)
  26. /* USER CODE END Includes */
  27. /* Private typedef -----------------------------------------------------------*/
  28. /* USER CODE BEGIN TD */
  29. /* USER CODE END TD */
  30. /* Private define ------------------------------------------------------------*/
  31. /* USER CODE BEGIN Define */
  32. /* USER CODE END Define */
  33. /* Private macro -------------------------------------------------------------*/
  34. /* USER CODE BEGIN Macro */
  35. /* USER CODE END Macro */
  36. /* Private variables ---------------------------------------------------------*/
  37. /* USER CODE BEGIN PV */
  38. /* USER CODE END PV */
  39. /* Private function prototypes -----------------------------------------------*/
  40. /* USER CODE BEGIN PFP */
  41. /* USER CODE END PFP */
  42. /* External functions --------------------------------------------------------*/
  43. /* USER CODE BEGIN ExternalFunctions */
  44. /* USER CODE END ExternalFunctions */
  45. /* USER CODE BEGIN 0 */
  46. /* USER CODE END 0 */
  47. /**
  48. * Initializes the Global MSP.
  49. */
  50. void HAL_MspInit(void)
  51. {
  52. /* USER CODE BEGIN MspInit 0 */
  53. /* USER CODE END MspInit 0 */
  54. __HAL_RCC_SYSCFG_CLK_ENABLE();
  55. /* System interrupt init*/
  56. /* USER CODE BEGIN MspInit 1 */
  57. /* USER CODE END MspInit 1 */
  58. }
  59. /**
  60. * @brief UART MSP Initialization
  61. * This function configures the hardware resources used in this example
  62. * @param huart: UART handle pointer
  63. * @retval None
  64. */
  65. void HAL_UART_MspInit(UART_HandleTypeDef* huart)
  66. {
  67. GPIO_InitTypeDef GPIO_InitStruct = {0};
  68. RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
  69. if(huart->Instance==USART1)
  70. {
  71. /* USER CODE BEGIN USART1_MspInit 0 */
  72. /* USER CODE END USART1_MspInit 0 */
  73. /** Initializes the peripherals clock
  74. */
  75. PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_USART1;
  76. PeriphClkInitStruct.Usart16ClockSelection = RCC_USART16CLKSOURCE_D2PCLK2;
  77. if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
  78. {
  79. Error_Handler();
  80. }
  81. /* Peripheral clock enable */
  82. __HAL_RCC_USART1_CLK_ENABLE();
  83. __HAL_RCC_GPIOA_CLK_ENABLE();
  84. /**USART1 GPIO Configuration
  85. PA10 ------> USART1_RX
  86. PA9 ------> USART1_TX
  87. */
  88. GPIO_InitStruct.Pin = GPIO_PIN_10|GPIO_PIN_9;
  89. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  90. GPIO_InitStruct.Pull = GPIO_NOPULL;
  91. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  92. GPIO_InitStruct.Alternate = GPIO_AF7_USART1;
  93. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  94. /* USER CODE BEGIN USART1_MspInit 1 */
  95. /* USER CODE END USART1_MspInit 1 */
  96. }
  97. }
  98. /**
  99. * @brief UART MSP De-Initialization
  100. * This function freeze the hardware resources used in this example
  101. * @param huart: UART handle pointer
  102. * @retval None
  103. */
  104. void HAL_UART_MspDeInit(UART_HandleTypeDef* huart)
  105. {
  106. if(huart->Instance==USART1)
  107. {
  108. /* USER CODE BEGIN USART1_MspDeInit 0 */
  109. /* USER CODE END USART1_MspDeInit 0 */
  110. /* Peripheral clock disable */
  111. __HAL_RCC_USART1_CLK_DISABLE();
  112. /**USART1 GPIO Configuration
  113. PA10 ------> USART1_RX
  114. PA9 ------> USART1_TX
  115. */
  116. HAL_GPIO_DeInit(GPIOA, GPIO_PIN_10|GPIO_PIN_9);
  117. /* USER CODE BEGIN USART1_MspDeInit 1 */
  118. /* USER CODE END USART1_MspDeInit 1 */
  119. }
  120. }
  121. /* USER CODE BEGIN 1 */
  122. /* USER CODE END 1 */
  123. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/