1 /* USER CODE BEGIN Header */
2 /**
3 ******************************************************************************
4 * File Name : stm32f0xx_hal_msp.c
5 * Description : This file provides code for the MSP Initialization
6 * and de-Initialization codes.
7 ******************************************************************************
8 ** This notice applies to any and all portions of this file
9 * that are not between comment pairs USER CODE BEGIN and
10 * USER CODE END. Other portions of this file, whether
11 * inserted by the user or by software development tools
12 * are owned by their respective copyright owners.
13 *
14 * COPYRIGHT(c) 2018 STMicroelectronics
15 *
16 * Redistribution and use in source and binary forms, with or without modification,
17 * are permitted provided that the following conditions are met:
18 * 1. Redistributions of source code must retain the above copyright notice,
19 * this list of conditions and the following disclaimer.
20 * 2. Redistributions in binary form must reproduce the above copyright notice,
21 * this list of conditions and the following disclaimer in the documentation
22 * and/or other materials provided with the distribution.
23 * 3. Neither the name of STMicroelectronics nor the names of its contributors
24 * may be used to endorse or promote products derived from this software
25 * without specific prior written permission.
26 *
27 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
28 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
30 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
31 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
33 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
34 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
35 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 *
38 ******************************************************************************
39 */
40 /* USER CODE END Header */
41
42 /* Includes ------------------------------------------------------------------*/
43 #include "main.h"
44 /* USER CODE BEGIN Includes */
45
46 /* USER CODE END Includes */
47
48 /* Private typedef -----------------------------------------------------------*/
49 /* USER CODE BEGIN TD */
50
51 /* USER CODE END TD */
52
53 /* Private define ------------------------------------------------------------*/
54 /* USER CODE BEGIN Define */
55
56 /* USER CODE END Define */
57
58 /* Private macro -------------------------------------------------------------*/
59 /* USER CODE BEGIN Macro */
60
61 /* USER CODE END Macro */
62
63 /* Private variables ---------------------------------------------------------*/
64 /* USER CODE BEGIN PV */
65
66 /* USER CODE END PV */
67
68 /* Private function prototypes -----------------------------------------------*/
69 /* USER CODE BEGIN PFP */
70
71 /* USER CODE END PFP */
72
73 /* External functions --------------------------------------------------------*/
74 /* USER CODE BEGIN ExternalFunctions */
75
76 /* USER CODE END ExternalFunctions */
77
78 /* USER CODE BEGIN 0 */
79
80 /* USER CODE END 0 */
81 /**
82 * Initializes the Global MSP.
83 */
HAL_MspInit(void)84 void HAL_MspInit(void)
85 {
86 /* USER CODE BEGIN MspInit 0 */
87
88 /* USER CODE END MspInit 0 */
89
90 __HAL_RCC_SYSCFG_CLK_ENABLE();
91 __HAL_RCC_PWR_CLK_ENABLE();
92
93 /* System interrupt init*/
94
95 /* USER CODE BEGIN MspInit 1 */
96
97 /* USER CODE END MspInit 1 */
98 }
99
100 /**
101 * @brief USART MSP Initialization
102 * This function configures the hardware resources used in this example
103 * @param husart: USART handle pointer
104 * @retval None
105 */
HAL_USART_MspInit(USART_HandleTypeDef * husart)106 void HAL_USART_MspInit(USART_HandleTypeDef* husart)
107 {
108
109 GPIO_InitTypeDef GPIO_InitStruct = {0};
110 if(husart->Instance==USART1)
111 {
112 /* USER CODE BEGIN USART1_MspInit 0 */
113
114 /* USER CODE END USART1_MspInit 0 */
115 /* Peripheral clock enable */
116 __HAL_RCC_USART1_CLK_ENABLE();
117 __HAL_RCC_GPIOA_CLK_ENABLE();
118 /**USART1 GPIO Configuration
119 PA8 ------> USART1_CK
120 PA9 ------> USART1_TX
121 PA10 ------> USART1_RX
122 */
123 GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10;
124 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
125 GPIO_InitStruct.Pull = GPIO_NOPULL;
126 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
127 GPIO_InitStruct.Alternate = GPIO_AF1_USART1;
128 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
129
130 /* USER CODE BEGIN USART1_MspInit 1 */
131
132 /* USER CODE END USART1_MspInit 1 */
133 }
134
135 }
136
137 /**
138 * @brief UART MSP Initialization
139 * This function configures the hardware resources used in this example
140 * @param huart: UART handle pointer
141 * @retval None
142 */
HAL_UART_MspInit(UART_HandleTypeDef * huart)143 void HAL_UART_MspInit(UART_HandleTypeDef* huart)
144 {
145
146 GPIO_InitTypeDef GPIO_InitStruct = {0};
147 if(huart->Instance==USART2)
148 {
149 /* USER CODE BEGIN USART2_MspInit 0 */
150
151 /* USER CODE END USART2_MspInit 0 */
152 /* Peripheral clock enable */
153 __HAL_RCC_USART2_CLK_ENABLE();
154
155 __HAL_RCC_GPIOA_CLK_ENABLE();
156 /**USART2 GPIO Configuration
157 PA2 ------> USART2_TX
158 PA3 ------> USART2_RX
159 */
160 GPIO_InitStruct.Pin = GPIO_PIN_2|GPIO_PIN_3;
161 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
162 GPIO_InitStruct.Pull = GPIO_PULLUP;
163 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
164 GPIO_InitStruct.Alternate = GPIO_AF1_USART2;
165 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
166
167 /* USER CODE BEGIN USART2_MspInit 1 */
168
169 /* USER CODE END USART2_MspInit 1 */
170 }
171
172 }
173
174 /**
175 * @brief USART MSP De-Initialization
176 * This function freeze the hardware resources used in this example
177 * @param husart: USART handle pointer
178 * @retval None
179 */
180
HAL_USART_MspDeInit(USART_HandleTypeDef * husart)181 void HAL_USART_MspDeInit(USART_HandleTypeDef* husart)
182 {
183
184 if(husart->Instance==USART1)
185 {
186 /* USER CODE BEGIN USART1_MspDeInit 0 */
187
188 /* USER CODE END USART1_MspDeInit 0 */
189 /* Peripheral clock disable */
190 __HAL_RCC_USART1_CLK_DISABLE();
191
192 /**USART1 GPIO Configuration
193 PA8 ------> USART1_CK
194 PA9 ------> USART1_TX
195 PA10 ------> USART1_RX
196 */
197 HAL_GPIO_DeInit(GPIOA, GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10);
198
199 /* USER CODE BEGIN USART1_MspDeInit 1 */
200
201 /* USER CODE END USART1_MspDeInit 1 */
202 }
203
204 }
205
206 /**
207 * @brief UART MSP De-Initialization
208 * This function freeze the hardware resources used in this example
209 * @param huart: UART handle pointer
210 * @retval None
211 */
212
HAL_UART_MspDeInit(UART_HandleTypeDef * huart)213 void HAL_UART_MspDeInit(UART_HandleTypeDef* huart)
214 {
215
216 if(huart->Instance==USART2)
217 {
218 /* USER CODE BEGIN USART2_MspDeInit 0 */
219
220 /* USER CODE END USART2_MspDeInit 0 */
221 /* Peripheral clock disable */
222 __HAL_RCC_USART2_CLK_DISABLE();
223 /**USART2 GPIO Configuration
224 PA2 ------> USART2_TX
225 PA3 ------> USART2_RX
226 */
227 HAL_GPIO_DeInit(GPIOA, GPIO_PIN_2|GPIO_PIN_3);
228
229 /* USER CODE BEGIN USART2_MspDeInit 1 */
230
231 /* USER CODE END USART2_MspDeInit 1 */
232 }
233
234 }
235
236 /* USER CODE BEGIN 1 */
237
238 /* USER CODE END 1 */
239
240 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
241