stm32f7xx_hal_msp.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /* USER CODE BEGIN Header */
  2. /**
  3. ******************************************************************************
  4. * @file stm32f7xx_hal_msp.c
  5. * @brief This file provides code for the MSP Initialization
  6. * and de-Initialization codes.
  7. ******************************************************************************
  8. * @attention
  9. *
  10. * Copyright (c) 2023 STMicroelectronics.
  11. * All rights reserved.
  12. *
  13. * This software is licensed under terms that can be found in the LICENSE file
  14. * in the root directory of this software component.
  15. * If no LICENSE file comes with this software, it is provided AS-IS.
  16. *
  17. ******************************************************************************
  18. */
  19. /* USER CODE END Header */
  20. /* Includes ------------------------------------------------------------------*/
  21. #include "main.h"
  22. /* USER CODE BEGIN Includes */
  23. #include <drv_common.h>
  24. /* USER CODE END Includes */
  25. /* Private typedef -----------------------------------------------------------*/
  26. /* USER CODE BEGIN TD */
  27. /* USER CODE END TD */
  28. /* Private define ------------------------------------------------------------*/
  29. /* USER CODE BEGIN Define */
  30. /* USER CODE END Define */
  31. /* Private macro -------------------------------------------------------------*/
  32. /* USER CODE BEGIN Macro */
  33. /* USER CODE END Macro */
  34. /* Private variables ---------------------------------------------------------*/
  35. /* USER CODE BEGIN PV */
  36. /* USER CODE END PV */
  37. /* Private function prototypes -----------------------------------------------*/
  38. /* USER CODE BEGIN PFP */
  39. /* USER CODE END PFP */
  40. /* External functions --------------------------------------------------------*/
  41. /* USER CODE BEGIN ExternalFunctions */
  42. /* USER CODE END ExternalFunctions */
  43. /* USER CODE BEGIN 0 */
  44. /* USER CODE END 0 */
  45. /**
  46. * Initializes the Global MSP.
  47. */
  48. void HAL_MspInit(void)
  49. {
  50. /* USER CODE BEGIN MspInit 0 */
  51. /* USER CODE END MspInit 0 */
  52. __HAL_RCC_PWR_CLK_ENABLE();
  53. __HAL_RCC_SYSCFG_CLK_ENABLE();
  54. /* System interrupt init*/
  55. /* USER CODE BEGIN MspInit 1 */
  56. /* USER CODE END MspInit 1 */
  57. }
  58. /**
  59. * @brief UART MSP Initialization
  60. * This function configures the hardware resources used in this example
  61. * @param huart: UART handle pointer
  62. * @retval None
  63. */
  64. void HAL_UART_MspInit(UART_HandleTypeDef* huart)
  65. {
  66. GPIO_InitTypeDef GPIO_InitStruct = {0};
  67. RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
  68. if(huart->Instance==USART6)
  69. {
  70. /* USER CODE BEGIN USART6_MspInit 0 */
  71. /* USER CODE END USART6_MspInit 0 */
  72. /** Initializes the peripherals clock
  73. */
  74. PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_USART6;
  75. PeriphClkInitStruct.Usart6ClockSelection = RCC_USART6CLKSOURCE_PCLK2;
  76. if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
  77. {
  78. Error_Handler();
  79. }
  80. /* Peripheral clock enable */
  81. __HAL_RCC_USART6_CLK_ENABLE();
  82. __HAL_RCC_GPIOC_CLK_ENABLE();
  83. /**USART6 GPIO Configuration
  84. PC7 ------> USART6_RX
  85. PC6 ------> USART6_TX
  86. */
  87. GPIO_InitStruct.Pin = GPIO_PIN_7|GPIO_PIN_6;
  88. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  89. GPIO_InitStruct.Pull = GPIO_NOPULL;
  90. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  91. GPIO_InitStruct.Alternate = GPIO_AF8_USART6;
  92. HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
  93. /* USER CODE BEGIN USART6_MspInit 1 */
  94. /* USER CODE END USART6_MspInit 1 */
  95. }
  96. }
  97. /**
  98. * @brief UART MSP De-Initialization
  99. * This function freeze the hardware resources used in this example
  100. * @param huart: UART handle pointer
  101. * @retval None
  102. */
  103. void HAL_UART_MspDeInit(UART_HandleTypeDef* huart)
  104. {
  105. if(huart->Instance==USART6)
  106. {
  107. /* USER CODE BEGIN USART6_MspDeInit 0 */
  108. /* USER CODE END USART6_MspDeInit 0 */
  109. /* Peripheral clock disable */
  110. __HAL_RCC_USART6_CLK_DISABLE();
  111. /**USART6 GPIO Configuration
  112. PC7 ------> USART6_RX
  113. PC6 ------> USART6_TX
  114. */
  115. HAL_GPIO_DeInit(GPIOC, GPIO_PIN_7|GPIO_PIN_6);
  116. /* USER CODE BEGIN USART6_MspDeInit 1 */
  117. /* USER CODE END USART6_MspDeInit 1 */
  118. }
  119. }
  120. /* USER CODE BEGIN 1 */
  121. /* USER CODE END 1 */