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>© 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 22 /* Includes ------------------------------------------------------------------*/ 23 #include "main.h" 24 /* USER CODE BEGIN Includes */ 25 #include <drv_common.h> 26 /* USER CODE END Includes */ 27 28 /* Private typedef -----------------------------------------------------------*/ 29 /* USER CODE BEGIN TD */ 30 31 /* USER CODE END TD */ 32 33 /* Private define ------------------------------------------------------------*/ 34 /* USER CODE BEGIN Define */ 35 36 /* USER CODE END Define */ 37 38 /* Private macro -------------------------------------------------------------*/ 39 /* USER CODE BEGIN Macro */ 40 41 /* USER CODE END Macro */ 42 43 /* Private variables ---------------------------------------------------------*/ 44 /* USER CODE BEGIN PV */ 45 46 /* USER CODE END PV */ 47 48 /* Private function prototypes -----------------------------------------------*/ 49 /* USER CODE BEGIN PFP */ 50 51 /* USER CODE END PFP */ 52 53 /* External functions --------------------------------------------------------*/ 54 /* USER CODE BEGIN ExternalFunctions */ 55 56 /* USER CODE END ExternalFunctions */ 57 58 /* USER CODE BEGIN 0 */ 59 60 /* USER CODE END 0 */ 61 /** 62 * Initializes the Global MSP. 63 */ HAL_MspInit(void)64void HAL_MspInit(void) 65 { 66 /* USER CODE BEGIN MspInit 0 */ 67 68 /* USER CODE END MspInit 0 */ 69 70 __HAL_RCC_SYSCFG_CLK_ENABLE(); 71 72 /* System interrupt init*/ 73 74 /* USER CODE BEGIN MspInit 1 */ 75 76 /* USER CODE END MspInit 1 */ 77 } 78 79 /** 80 * @brief UART MSP Initialization 81 * This function configures the hardware resources used in this example 82 * @param huart: UART handle pointer 83 * @retval None 84 */ HAL_UART_MspInit(UART_HandleTypeDef * huart)85void HAL_UART_MspInit(UART_HandleTypeDef* huart) 86 { 87 GPIO_InitTypeDef GPIO_InitStruct = {0}; 88 RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0}; 89 if(huart->Instance==USART1) 90 { 91 /* USER CODE BEGIN USART1_MspInit 0 */ 92 93 /* USER CODE END USART1_MspInit 0 */ 94 /** Initializes the peripherals clock 95 */ 96 PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_USART1; 97 PeriphClkInitStruct.Usart16ClockSelection = RCC_USART16CLKSOURCE_D2PCLK2; 98 if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK) 99 { 100 Error_Handler(); 101 } 102 103 /* Peripheral clock enable */ 104 __HAL_RCC_USART1_CLK_ENABLE(); 105 106 __HAL_RCC_GPIOA_CLK_ENABLE(); 107 /**USART1 GPIO Configuration 108 PA10 ------> USART1_RX 109 PA9 ------> USART1_TX 110 */ 111 GPIO_InitStruct.Pin = GPIO_PIN_10|GPIO_PIN_9; 112 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; 113 GPIO_InitStruct.Pull = GPIO_NOPULL; 114 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; 115 GPIO_InitStruct.Alternate = GPIO_AF7_USART1; 116 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); 117 118 /* USER CODE BEGIN USART1_MspInit 1 */ 119 120 /* USER CODE END USART1_MspInit 1 */ 121 } 122 123 } 124 125 /** 126 * @brief UART MSP De-Initialization 127 * This function freeze the hardware resources used in this example 128 * @param huart: UART handle pointer 129 * @retval None 130 */ HAL_UART_MspDeInit(UART_HandleTypeDef * huart)131void HAL_UART_MspDeInit(UART_HandleTypeDef* huart) 132 { 133 if(huart->Instance==USART1) 134 { 135 /* USER CODE BEGIN USART1_MspDeInit 0 */ 136 137 /* USER CODE END USART1_MspDeInit 0 */ 138 /* Peripheral clock disable */ 139 __HAL_RCC_USART1_CLK_DISABLE(); 140 141 /**USART1 GPIO Configuration 142 PA10 ------> USART1_RX 143 PA9 ------> USART1_TX 144 */ 145 HAL_GPIO_DeInit(GPIOA, GPIO_PIN_10|GPIO_PIN_9); 146 147 /* USER CODE BEGIN USART1_MspDeInit 1 */ 148 149 /* USER CODE END USART1_MspDeInit 1 */ 150 } 151 152 } 153 154 /* USER CODE BEGIN 1 */ 155 156 /* USER CODE END 1 */ 157 158 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 159