1 /* USER CODE BEGIN Header */
2 /**
3 ******************************************************************************
4 * File Name : stm32f1xx_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) 2019 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 #include <drv_common.h>
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_AFIO_CLK_ENABLE();
91 __HAL_RCC_PWR_CLK_ENABLE();
92
93 /* System interrupt init*/
94
95 /**NOJTAG: JTAG-DP Disabled and SW-DP Enabled
96 */
97 __HAL_AFIO_REMAP_SWJ_NOJTAG();
98
99 /* USER CODE BEGIN MspInit 1 */
100
101 /* USER CODE END MspInit 1 */
102 }
103
104 /**
105 * @brief ADC MSP Initialization
106 * This function configures the hardware resources used in this example
107 * @param hadc: ADC handle pointer
108 * @retval None
109 */
HAL_ADC_MspInit(ADC_HandleTypeDef * hadc)110 void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc)
111 {
112
113 GPIO_InitTypeDef GPIO_InitStruct = {0};
114 if(hadc->Instance==ADC1)
115 {
116 /* USER CODE BEGIN ADC1_MspInit 0 */
117
118 /* USER CODE END ADC1_MspInit 0 */
119 /* Peripheral clock enable */
120 __HAL_RCC_ADC1_CLK_ENABLE();
121
122 __HAL_RCC_GPIOC_CLK_ENABLE();
123 /**ADC1 GPIO Configuration
124 PC0 ------> ADC1_IN10
125 PC1 ------> ADC1_IN11
126 */
127 GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1;
128 GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
129 HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
130
131 /* USER CODE BEGIN ADC1_MspInit 1 */
132
133 /* USER CODE END ADC1_MspInit 1 */
134 }
135
136 }
137
138 /**
139 * @brief ADC MSP De-Initialization
140 * This function freeze the hardware resources used in this example
141 * @param hadc: ADC handle pointer
142 * @retval None
143 */
144
HAL_ADC_MspDeInit(ADC_HandleTypeDef * hadc)145 void HAL_ADC_MspDeInit(ADC_HandleTypeDef* hadc)
146 {
147
148 if(hadc->Instance==ADC1)
149 {
150 /* USER CODE BEGIN ADC1_MspDeInit 0 */
151
152 /* USER CODE END ADC1_MspDeInit 0 */
153 /* Peripheral clock disable */
154 __HAL_RCC_ADC1_CLK_DISABLE();
155
156 /**ADC1 GPIO Configuration
157 PC0 ------> ADC1_IN10
158 PC1 ------> ADC1_IN11
159 */
160 HAL_GPIO_DeInit(GPIOC, GPIO_PIN_0|GPIO_PIN_1);
161
162 /* USER CODE BEGIN ADC1_MspDeInit 1 */
163
164 /* USER CODE END ADC1_MspDeInit 1 */
165 }
166
167 }
168
169 /**
170 * @brief RTC MSP Initialization
171 * This function configures the hardware resources used in this example
172 * @param hrtc: RTC handle pointer
173 * @retval None
174 */
HAL_RTC_MspInit(RTC_HandleTypeDef * hrtc)175 void HAL_RTC_MspInit(RTC_HandleTypeDef* hrtc)
176 {
177
178 if(hrtc->Instance==RTC)
179 {
180 /* USER CODE BEGIN RTC_MspInit 0 */
181
182 /* USER CODE END RTC_MspInit 0 */
183 HAL_PWR_EnableBkUpAccess();
184 /* Enable BKP CLK enable for backup registers */
185 __HAL_RCC_BKP_CLK_ENABLE();
186 /* Peripheral clock enable */
187 __HAL_RCC_RTC_ENABLE();
188 /* USER CODE BEGIN RTC_MspInit 1 */
189
190 /* USER CODE END RTC_MspInit 1 */
191 }
192
193 }
194
195 /**
196 * @brief RTC MSP De-Initialization
197 * This function freeze the hardware resources used in this example
198 * @param hrtc: RTC handle pointer
199 * @retval None
200 */
201
HAL_RTC_MspDeInit(RTC_HandleTypeDef * hrtc)202 void HAL_RTC_MspDeInit(RTC_HandleTypeDef* hrtc)
203 {
204
205 if(hrtc->Instance==RTC)
206 {
207 /* USER CODE BEGIN RTC_MspDeInit 0 */
208
209 /* USER CODE END RTC_MspDeInit 0 */
210 /* Peripheral clock disable */
211 __HAL_RCC_RTC_DISABLE();
212 /* USER CODE BEGIN RTC_MspDeInit 1 */
213
214 /* USER CODE END RTC_MspDeInit 1 */
215 }
216
217 }
218
219 /**
220 * @brief SPI MSP Initialization
221 * This function configures the hardware resources used in this example
222 * @param hspi: SPI handle pointer
223 * @retval None
224 */
HAL_SPI_MspInit(SPI_HandleTypeDef * hspi)225 void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi)
226 {
227
228 GPIO_InitTypeDef GPIO_InitStruct = {0};
229 if(hspi->Instance==SPI1)
230 {
231 /* USER CODE BEGIN SPI1_MspInit 0 */
232
233 /* USER CODE END SPI1_MspInit 0 */
234 /* Peripheral clock enable */
235 __HAL_RCC_SPI1_CLK_ENABLE();
236
237 __HAL_RCC_GPIOA_CLK_ENABLE();
238 /**SPI1 GPIO Configuration
239 PA5 ------> SPI1_SCK
240 PA6 ------> SPI1_MISO
241 PA7 ------> SPI1_MOSI
242 */
243 GPIO_InitStruct.Pin = GPIO_PIN_5|GPIO_PIN_7;
244 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
245 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
246 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
247
248 GPIO_InitStruct.Pin = GPIO_PIN_6;
249 GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
250 GPIO_InitStruct.Pull = GPIO_NOPULL;
251 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
252
253 /* USER CODE BEGIN SPI1_MspInit 1 */
254
255 /* USER CODE END SPI1_MspInit 1 */
256 }
257 else if(hspi->Instance==SPI2)
258 {
259 /* USER CODE BEGIN SPI2_MspInit 0 */
260
261 /* USER CODE END SPI2_MspInit 0 */
262 /* Peripheral clock enable */
263 __HAL_RCC_SPI2_CLK_ENABLE();
264
265 __HAL_RCC_GPIOB_CLK_ENABLE();
266 /**SPI2 GPIO Configuration
267 PB13 ------> SPI2_SCK
268 PB14 ------> SPI2_MISO
269 PB15 ------> SPI2_MOSI
270 */
271 GPIO_InitStruct.Pin = GPIO_PIN_13|GPIO_PIN_15;
272 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
273 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
274 HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
275
276 GPIO_InitStruct.Pin = GPIO_PIN_14;
277 GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
278 GPIO_InitStruct.Pull = GPIO_NOPULL;
279 HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
280
281 /* USER CODE BEGIN SPI2_MspInit 1 */
282
283 /* USER CODE END SPI2_MspInit 1 */
284 }
285
286 }
287
288 /**
289 * @brief SPI MSP De-Initialization
290 * This function freeze the hardware resources used in this example
291 * @param hspi: SPI handle pointer
292 * @retval None
293 */
294
HAL_SPI_MspDeInit(SPI_HandleTypeDef * hspi)295 void HAL_SPI_MspDeInit(SPI_HandleTypeDef* hspi)
296 {
297
298 if(hspi->Instance==SPI1)
299 {
300 /* USER CODE BEGIN SPI1_MspDeInit 0 */
301
302 /* USER CODE END SPI1_MspDeInit 0 */
303 /* Peripheral clock disable */
304 __HAL_RCC_SPI1_CLK_DISABLE();
305
306 /**SPI1 GPIO Configuration
307 PA5 ------> SPI1_SCK
308 PA6 ------> SPI1_MISO
309 PA7 ------> SPI1_MOSI
310 */
311 HAL_GPIO_DeInit(GPIOA, GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7);
312
313 /* USER CODE BEGIN SPI1_MspDeInit 1 */
314
315 /* USER CODE END SPI1_MspDeInit 1 */
316 }
317 else if(hspi->Instance==SPI2)
318 {
319 /* USER CODE BEGIN SPI2_MspDeInit 0 */
320
321 /* USER CODE END SPI2_MspDeInit 0 */
322 /* Peripheral clock disable */
323 __HAL_RCC_SPI2_CLK_DISABLE();
324
325 /**SPI2 GPIO Configuration
326 PB13 ------> SPI2_SCK
327 PB14 ------> SPI2_MISO
328 PB15 ------> SPI2_MOSI
329 */
330 HAL_GPIO_DeInit(GPIOB, GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15);
331
332 /* USER CODE BEGIN SPI2_MspDeInit 1 */
333
334 /* USER CODE END SPI2_MspDeInit 1 */
335 }
336
337 }
338
339 /**
340 * @brief UART MSP Initialization
341 * This function configures the hardware resources used in this example
342 * @param huart: UART handle pointer
343 * @retval None
344 */
HAL_UART_MspInit(UART_HandleTypeDef * huart)345 void HAL_UART_MspInit(UART_HandleTypeDef* huart)
346 {
347
348 GPIO_InitTypeDef GPIO_InitStruct = {0};
349 if(huart->Instance==UART4)
350 {
351 /* USER CODE BEGIN UART4_MspInit 0 */
352
353 /* USER CODE END UART4_MspInit 0 */
354 /* Peripheral clock enable */
355 __HAL_RCC_UART4_CLK_ENABLE();
356
357 __HAL_RCC_GPIOC_CLK_ENABLE();
358 /**UART4 GPIO Configuration
359 PC10 ------> UART4_TX
360 PC11 ------> UART4_RX
361 */
362 GPIO_InitStruct.Pin = GPIO_PIN_10;
363 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
364 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
365 HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
366
367 GPIO_InitStruct.Pin = GPIO_PIN_11;
368 GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
369 GPIO_InitStruct.Pull = GPIO_PULLUP;
370 HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
371
372 /* USER CODE BEGIN UART4_MspInit 1 */
373
374 /* USER CODE END UART4_MspInit 1 */
375 }
376 else if(huart->Instance==USART1)
377 {
378 /* USER CODE BEGIN USART1_MspInit 0 */
379
380 /* USER CODE END USART1_MspInit 0 */
381 /* Peripheral clock enable */
382 __HAL_RCC_USART1_CLK_ENABLE();
383
384 __HAL_RCC_GPIOA_CLK_ENABLE();
385 /**USART1 GPIO Configuration
386 PA9 ------> USART1_TX
387 PA10 ------> USART1_RX
388 */
389 GPIO_InitStruct.Pin = GPIO_PIN_9;
390 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
391 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
392 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
393
394 GPIO_InitStruct.Pin = GPIO_PIN_10;
395 GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
396 GPIO_InitStruct.Pull = GPIO_PULLUP;
397 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
398
399 /* USER CODE BEGIN USART1_MspInit 1 */
400
401 /* USER CODE END USART1_MspInit 1 */
402 }
403 else if(huart->Instance==USART2)
404 {
405 /* USER CODE BEGIN USART2_MspInit 0 */
406
407 /* USER CODE END USART2_MspInit 0 */
408 /* Peripheral clock enable */
409 __HAL_RCC_USART2_CLK_ENABLE();
410
411 __HAL_RCC_GPIOA_CLK_ENABLE();
412 /**USART2 GPIO Configuration
413 PA2 ------> USART2_TX
414 PA3 ------> USART2_RX
415 */
416 GPIO_InitStruct.Pin = GPIO_PIN_2;
417 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
418 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
419 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
420
421 GPIO_InitStruct.Pin = GPIO_PIN_3;
422 GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
423 GPIO_InitStruct.Pull = GPIO_PULLUP;
424 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
425
426 /* USER CODE BEGIN USART2_MspInit 1 */
427
428 /* USER CODE END USART2_MspInit 1 */
429 }
430 else if(huart->Instance==USART3)
431 {
432 /* USER CODE BEGIN USART3_MspInit 0 */
433
434 /* USER CODE END USART3_MspInit 0 */
435 /* Peripheral clock enable */
436 __HAL_RCC_USART3_CLK_ENABLE();
437
438 __HAL_RCC_GPIOB_CLK_ENABLE();
439 /**USART3 GPIO Configuration
440 PB10 ------> USART3_TX
441 PB11 ------> USART3_RX
442 */
443 GPIO_InitStruct.Pin = GPIO_PIN_10;
444 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
445 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
446 HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
447
448 GPIO_InitStruct.Pin = GPIO_PIN_11;
449 GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
450 GPIO_InitStruct.Pull = GPIO_PULLUP;
451 HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
452
453 /* USER CODE BEGIN USART3_MspInit 1 */
454
455 /* USER CODE END USART3_MspInit 1 */
456 }
457
458 }
459
460 /**
461 * @brief UART MSP De-Initialization
462 * This function freeze the hardware resources used in this example
463 * @param huart: UART handle pointer
464 * @retval None
465 */
466
HAL_UART_MspDeInit(UART_HandleTypeDef * huart)467 void HAL_UART_MspDeInit(UART_HandleTypeDef* huart)
468 {
469
470 if(huart->Instance==UART4)
471 {
472 /* USER CODE BEGIN UART4_MspDeInit 0 */
473
474 /* USER CODE END UART4_MspDeInit 0 */
475 /* Peripheral clock disable */
476 __HAL_RCC_UART4_CLK_DISABLE();
477
478 /**UART4 GPIO Configuration
479 PC10 ------> UART4_TX
480 PC11 ------> UART4_RX
481 */
482 HAL_GPIO_DeInit(GPIOC, GPIO_PIN_10|GPIO_PIN_11);
483
484 /* USER CODE BEGIN UART4_MspDeInit 1 */
485
486 /* USER CODE END UART4_MspDeInit 1 */
487 }
488 else if(huart->Instance==USART1)
489 {
490 /* USER CODE BEGIN USART1_MspDeInit 0 */
491
492 /* USER CODE END USART1_MspDeInit 0 */
493 /* Peripheral clock disable */
494 __HAL_RCC_USART1_CLK_DISABLE();
495
496 /**USART1 GPIO Configuration
497 PA9 ------> USART1_TX
498 PA10 ------> USART1_RX
499 */
500 HAL_GPIO_DeInit(GPIOA, GPIO_PIN_9|GPIO_PIN_10);
501
502 /* USER CODE BEGIN USART1_MspDeInit 1 */
503
504 /* USER CODE END USART1_MspDeInit 1 */
505 }
506 else if(huart->Instance==USART2)
507 {
508 /* USER CODE BEGIN USART2_MspDeInit 0 */
509
510 /* USER CODE END USART2_MspDeInit 0 */
511 /* Peripheral clock disable */
512 __HAL_RCC_USART2_CLK_DISABLE();
513
514 /**USART2 GPIO Configuration
515 PA2 ------> USART2_TX
516 PA3 ------> USART2_RX
517 */
518 HAL_GPIO_DeInit(GPIOA, GPIO_PIN_2|GPIO_PIN_3);
519
520 /* USER CODE BEGIN USART2_MspDeInit 1 */
521
522 /* USER CODE END USART2_MspDeInit 1 */
523 }
524 else if(huart->Instance==USART3)
525 {
526 /* USER CODE BEGIN USART3_MspDeInit 0 */
527
528 /* USER CODE END USART3_MspDeInit 0 */
529 /* Peripheral clock disable */
530 __HAL_RCC_USART3_CLK_DISABLE();
531
532 /**USART3 GPIO Configuration
533 PB10 ------> USART3_TX
534 PB11 ------> USART3_RX
535 */
536 HAL_GPIO_DeInit(GPIOB, GPIO_PIN_10|GPIO_PIN_11);
537
538 /* USER CODE BEGIN USART3_MspDeInit 1 */
539
540 /* USER CODE END USART3_MspDeInit 1 */
541 }
542
543 }
544
545 /* USER CODE BEGIN 1 */
546
547 /* USER CODE END 1 */
548
549 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
550