1 /* USER CODE BEGIN Header */
2 /**
3   ******************************************************************************
4   * @file         stm32l5xx_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 
22 /* Includes ------------------------------------------------------------------*/
23 #include "main.h"
24 /* USER CODE BEGIN Includes */
25 
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   RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
90   if(huart->Instance==LPUART1)
91   {
92   /* USER CODE BEGIN LPUART1_MspInit 0 */
93 
94   /* USER CODE END LPUART1_MspInit 0 */
95   /** Initializes the peripherals clock
96   */
97     PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_LPUART1;
98     PeriphClkInit.Lpuart1ClockSelection = RCC_LPUART1CLKSOURCE_PCLK1;
99     if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
100     {
101       Error_Handler();
102     }
103 
104     /* Peripheral clock enable */
105     __HAL_RCC_LPUART1_CLK_ENABLE();
106 
107     __HAL_RCC_GPIOG_CLK_ENABLE();
108     HAL_PWREx_EnableVddIO2();
109     /**LPUART1 GPIO Configuration
110     PG7     ------> LPUART1_TX
111     PG8     ------> LPUART1_RX
112     */
113     GPIO_InitStruct.Pin = GPIO_PIN_7|GPIO_PIN_8;
114     GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
115     GPIO_InitStruct.Pull = GPIO_NOPULL;
116     GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
117     GPIO_InitStruct.Alternate = GPIO_AF8_LPUART1;
118     HAL_GPIO_Init(GPIOG, &GPIO_InitStruct);
119 
120   /* USER CODE BEGIN LPUART1_MspInit 1 */
121 
122   /* USER CODE END LPUART1_MspInit 1 */
123   }
124 
125 }
126 
127 /**
128 * @brief UART MSP De-Initialization
129 * This function freeze the hardware resources used in this example
130 * @param huart: UART handle pointer
131 * @retval None
132 */
HAL_UART_MspDeInit(UART_HandleTypeDef * huart)133 void HAL_UART_MspDeInit(UART_HandleTypeDef* huart)
134 {
135   if(huart->Instance==LPUART1)
136   {
137   /* USER CODE BEGIN LPUART1_MspDeInit 0 */
138 
139   /* USER CODE END LPUART1_MspDeInit 0 */
140     /* Peripheral clock disable */
141     __HAL_RCC_LPUART1_CLK_DISABLE();
142 
143     /**LPUART1 GPIO Configuration
144     PG7     ------> LPUART1_TX
145     PG8     ------> LPUART1_RX
146     */
147     HAL_GPIO_DeInit(GPIOG, GPIO_PIN_7|GPIO_PIN_8);
148 
149   /* USER CODE BEGIN LPUART1_MspDeInit 1 */
150 
151   /* USER CODE END LPUART1_MspDeInit 1 */
152   }
153 
154 }
155 
156 /**
157   * @brief  This function is executed in case of error occurrence.
158   * @retval None
159   */
Error_Handler(void)160 void Error_Handler(void)
161 {
162   /* USER CODE BEGIN Error_Handler_Debug */
163   /* User can add his own implementation to report the HAL error return state */
164 
165   /* USER CODE END Error_Handler_Debug */
166 }
167 /* USER CODE BEGIN 1 */
168 
169 /* USER CODE END 1 */
170 
171 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
172