1 /* USER CODE BEGIN Header */
2 /**
3   ******************************************************************************
4   * File Name          : stm32l4xx_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) 2020 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)64 void 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   __HAL_RCC_PWR_CLK_ENABLE();
72 
73   /* System interrupt init*/
74 
75   /* USER CODE BEGIN MspInit 1 */
76 
77   /* USER CODE END MspInit 1 */
78 }
79 
80 /**
81 * @brief UART MSP Initialization
82 * This function configures the hardware resources used in this example
83 * @param huart: UART handle pointer
84 * @retval None
85 */
HAL_UART_MspInit(UART_HandleTypeDef * huart)86 void HAL_UART_MspInit(UART_HandleTypeDef* huart)
87 {
88   GPIO_InitTypeDef GPIO_InitStruct = {0};
89   if(huart->Instance==USART2)
90   {
91   /* USER CODE BEGIN USART2_MspInit 0 */
92 
93   /* USER CODE END USART2_MspInit 0 */
94     /* Peripheral clock enable */
95     __HAL_RCC_USART2_CLK_ENABLE();
96 
97     __HAL_RCC_GPIOA_CLK_ENABLE();
98     /**USART2 GPIO Configuration
99     PA2     ------> USART2_TX
100     PA3     ------> USART2_RX
101     */
102     GPIO_InitStruct.Pin = USART_TX_Pin|USART_RX_Pin;
103     GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
104     GPIO_InitStruct.Pull = GPIO_PULLUP;
105     GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
106     GPIO_InitStruct.Alternate = GPIO_AF7_USART2;
107     HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
108 
109   /* USER CODE BEGIN USART2_MspInit 1 */
110 
111   /* USER CODE END USART2_MspInit 1 */
112   }
113 
114 }
115 
116 /**
117 * @brief UART MSP De-Initialization
118 * This function freeze the hardware resources used in this example
119 * @param huart: UART handle pointer
120 * @retval None
121 */
HAL_UART_MspDeInit(UART_HandleTypeDef * huart)122 void HAL_UART_MspDeInit(UART_HandleTypeDef* huart)
123 {
124   if(huart->Instance==USART2)
125   {
126   /* USER CODE BEGIN USART2_MspDeInit 0 */
127 
128   /* USER CODE END USART2_MspDeInit 0 */
129     /* Peripheral clock disable */
130     __HAL_RCC_USART2_CLK_DISABLE();
131 
132     /**USART2 GPIO Configuration
133     PA2     ------> USART2_TX
134     PA3     ------> USART2_RX
135     */
136     HAL_GPIO_DeInit(GPIOA, USART_TX_Pin|USART_RX_Pin);
137 
138   /* USER CODE BEGIN USART2_MspDeInit 1 */
139 
140   /* USER CODE END USART2_MspDeInit 1 */
141   }
142 
143 }
144 
145 /* USER CODE BEGIN 1 */
146 
147 /* USER CODE END 1 */
148 
149 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
150