1 /* USER CODE BEGIN Header */
2 /**
3 ******************************************************************************
4 * File Name : stm32wbxx_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>© 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 /* System interrupt init*/
71
72 /* USER CODE BEGIN MspInit 1 */
73
74 /* USER CODE END MspInit 1 */
75 }
76
77 /**
78 * @brief ADC MSP Initialization
79 * This function configures the hardware resources used in this example
80 * @param hadc: ADC handle pointer
81 * @retval None
82 */
HAL_ADC_MspInit(ADC_HandleTypeDef * hadc)83 void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc)
84 {
85 GPIO_InitTypeDef GPIO_InitStruct = {0};
86 if(hadc->Instance==ADC1)
87 {
88 /* USER CODE BEGIN ADC1_MspInit 0 */
89
90 /* USER CODE END ADC1_MspInit 0 */
91 /* Peripheral clock enable */
92 __HAL_RCC_ADC_CLK_ENABLE();
93
94 __HAL_RCC_GPIOA_CLK_ENABLE();
95 /**ADC1 GPIO Configuration
96 PA0 ------> ADC1_IN5
97 */
98 GPIO_InitStruct.Pin = GPIO_PIN_0;
99 GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
100 GPIO_InitStruct.Pull = GPIO_NOPULL;
101 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
102
103 /* USER CODE BEGIN ADC1_MspInit 1 */
104
105 /* USER CODE END ADC1_MspInit 1 */
106 }
107
108 }
109
110 /**
111 * @brief ADC MSP De-Initialization
112 * This function freeze the hardware resources used in this example
113 * @param hadc: ADC handle pointer
114 * @retval None
115 */
HAL_ADC_MspDeInit(ADC_HandleTypeDef * hadc)116 void HAL_ADC_MspDeInit(ADC_HandleTypeDef* hadc)
117 {
118 if(hadc->Instance==ADC1)
119 {
120 /* USER CODE BEGIN ADC1_MspDeInit 0 */
121
122 /* USER CODE END ADC1_MspDeInit 0 */
123 /* Peripheral clock disable */
124 __HAL_RCC_ADC_CLK_DISABLE();
125
126 /**ADC1 GPIO Configuration
127 PA0 ------> ADC1_IN5
128 */
129 HAL_GPIO_DeInit(GPIOA, GPIO_PIN_0);
130
131 /* USER CODE BEGIN ADC1_MspDeInit 1 */
132
133 /* USER CODE END ADC1_MspDeInit 1 */
134 }
135
136 }
137
138 /**
139 * @brief I2C MSP Initialization
140 * This function configures the hardware resources used in this example
141 * @param hi2c: I2C handle pointer
142 * @retval None
143 */
HAL_I2C_MspInit(I2C_HandleTypeDef * hi2c)144 void HAL_I2C_MspInit(I2C_HandleTypeDef* hi2c)
145 {
146 GPIO_InitTypeDef GPIO_InitStruct = {0};
147 if(hi2c->Instance==I2C1)
148 {
149 /* USER CODE BEGIN I2C1_MspInit 0 */
150
151 /* USER CODE END I2C1_MspInit 0 */
152
153 __HAL_RCC_GPIOB_CLK_ENABLE();
154 /**I2C1 GPIO Configuration
155 PB8 ------> I2C1_SCL
156 PB9 ------> I2C1_SDA
157 */
158 GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_9;
159 GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
160 GPIO_InitStruct.Pull = GPIO_PULLUP;
161 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
162 GPIO_InitStruct.Alternate = GPIO_AF4_I2C1;
163 HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
164
165 /* Peripheral clock enable */
166 __HAL_RCC_I2C1_CLK_ENABLE();
167 /* USER CODE BEGIN I2C1_MspInit 1 */
168
169 /* USER CODE END I2C1_MspInit 1 */
170 }
171
172 }
173
174 /**
175 * @brief I2C MSP De-Initialization
176 * This function freeze the hardware resources used in this example
177 * @param hi2c: I2C handle pointer
178 * @retval None
179 */
HAL_I2C_MspDeInit(I2C_HandleTypeDef * hi2c)180 void HAL_I2C_MspDeInit(I2C_HandleTypeDef* hi2c)
181 {
182 if(hi2c->Instance==I2C1)
183 {
184 /* USER CODE BEGIN I2C1_MspDeInit 0 */
185
186 /* USER CODE END I2C1_MspDeInit 0 */
187 /* Peripheral clock disable */
188 __HAL_RCC_I2C1_CLK_DISABLE();
189
190 /**I2C1 GPIO Configuration
191 PB8 ------> I2C1_SCL
192 PB9 ------> I2C1_SDA
193 */
194 HAL_GPIO_DeInit(GPIOB, GPIO_PIN_8);
195
196 HAL_GPIO_DeInit(GPIOB, GPIO_PIN_9);
197
198 /* USER CODE BEGIN I2C1_MspDeInit 1 */
199
200 /* USER CODE END I2C1_MspDeInit 1 */
201 }
202
203 }
204
205 /**
206 * @brief UART MSP Initialization
207 * This function configures the hardware resources used in this example
208 * @param huart: UART handle pointer
209 * @retval None
210 */
HAL_UART_MspInit(UART_HandleTypeDef * huart)211 void HAL_UART_MspInit(UART_HandleTypeDef* huart)
212 {
213 GPIO_InitTypeDef GPIO_InitStruct = {0};
214 if(huart->Instance==LPUART1)
215 {
216 /* USER CODE BEGIN LPUART1_MspInit 0 */
217
218 /* USER CODE END LPUART1_MspInit 0 */
219 /* Peripheral clock enable */
220 __HAL_RCC_LPUART1_CLK_ENABLE();
221
222 __HAL_RCC_GPIOB_CLK_ENABLE();
223 /**LPUART1 GPIO Configuration
224 PB10 ------> LPUART1_RX
225 PB11 ------> LPUART1_TX
226 */
227 GPIO_InitStruct.Pin = GPIO_PIN_10|GPIO_PIN_11;
228 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
229 GPIO_InitStruct.Pull = GPIO_PULLUP;
230 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
231 GPIO_InitStruct.Alternate = GPIO_AF8_LPUART1;
232 HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
233
234 /* USER CODE BEGIN LPUART1_MspInit 1 */
235
236 /* USER CODE END LPUART1_MspInit 1 */
237 }
238 else if(huart->Instance==USART1)
239 {
240 /* USER CODE BEGIN USART1_MspInit 0 */
241
242 /* USER CODE END USART1_MspInit 0 */
243 /* Peripheral clock enable */
244 __HAL_RCC_USART1_CLK_ENABLE();
245
246 __HAL_RCC_GPIOB_CLK_ENABLE();
247 /**USART1 GPIO Configuration
248 PB6 ------> USART1_TX
249 PB7 ------> USART1_RX
250 */
251 GPIO_InitStruct.Pin = GPIO_PIN_6|GPIO_PIN_7;
252 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
253 GPIO_InitStruct.Pull = GPIO_PULLUP;
254 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
255 GPIO_InitStruct.Alternate = GPIO_AF7_USART1;
256 HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
257
258 /* USER CODE BEGIN USART1_MspInit 1 */
259
260 /* USER CODE END USART1_MspInit 1 */
261 }
262
263 }
264
265 /**
266 * @brief UART MSP De-Initialization
267 * This function freeze the hardware resources used in this example
268 * @param huart: UART handle pointer
269 * @retval None
270 */
HAL_UART_MspDeInit(UART_HandleTypeDef * huart)271 void HAL_UART_MspDeInit(UART_HandleTypeDef* huart)
272 {
273 if(huart->Instance==LPUART1)
274 {
275 /* USER CODE BEGIN LPUART1_MspDeInit 0 */
276
277 /* USER CODE END LPUART1_MspDeInit 0 */
278 /* Peripheral clock disable */
279 __HAL_RCC_LPUART1_CLK_DISABLE();
280
281 /**LPUART1 GPIO Configuration
282 PB10 ------> LPUART1_RX
283 PB11 ------> LPUART1_TX
284 */
285 HAL_GPIO_DeInit(GPIOB, GPIO_PIN_10|GPIO_PIN_11);
286
287 /* USER CODE BEGIN LPUART1_MspDeInit 1 */
288
289 /* USER CODE END LPUART1_MspDeInit 1 */
290 }
291 else if(huart->Instance==USART1)
292 {
293 /* USER CODE BEGIN USART1_MspDeInit 0 */
294
295 /* USER CODE END USART1_MspDeInit 0 */
296 /* Peripheral clock disable */
297 __HAL_RCC_USART1_CLK_DISABLE();
298
299 /**USART1 GPIO Configuration
300 PB6 ------> USART1_TX
301 PB7 ------> USART1_RX
302 */
303 HAL_GPIO_DeInit(GPIOB, GPIO_PIN_6|GPIO_PIN_7);
304
305 /* USER CODE BEGIN USART1_MspDeInit 1 */
306
307 /* USER CODE END USART1_MspDeInit 1 */
308 }
309
310 }
311
312 /**
313 * @brief RTC MSP Initialization
314 * This function configures the hardware resources used in this example
315 * @param hrtc: RTC handle pointer
316 * @retval None
317 */
HAL_RTC_MspInit(RTC_HandleTypeDef * hrtc)318 void HAL_RTC_MspInit(RTC_HandleTypeDef* hrtc)
319 {
320 if(hrtc->Instance==RTC)
321 {
322 /* USER CODE BEGIN RTC_MspInit 0 */
323
324 /* USER CODE END RTC_MspInit 0 */
325 /* Peripheral clock enable */
326 __HAL_RCC_RTC_ENABLE();
327 __HAL_RCC_RTCAPB_CLK_ENABLE();
328 /* USER CODE BEGIN RTC_MspInit 1 */
329
330 /* USER CODE END RTC_MspInit 1 */
331 }
332
333 }
334
335 /**
336 * @brief RTC MSP De-Initialization
337 * This function freeze the hardware resources used in this example
338 * @param hrtc: RTC handle pointer
339 * @retval None
340 */
HAL_RTC_MspDeInit(RTC_HandleTypeDef * hrtc)341 void HAL_RTC_MspDeInit(RTC_HandleTypeDef* hrtc)
342 {
343 if(hrtc->Instance==RTC)
344 {
345 /* USER CODE BEGIN RTC_MspDeInit 0 */
346
347 /* USER CODE END RTC_MspDeInit 0 */
348 /* Peripheral clock disable */
349 __HAL_RCC_RTC_DISABLE();
350 __HAL_RCC_RTCAPB_CLK_DISABLE();
351 /* USER CODE BEGIN RTC_MspDeInit 1 */
352
353 /* USER CODE END RTC_MspDeInit 1 */
354 }
355
356 }
357
358 /**
359 * @brief SPI MSP Initialization
360 * This function configures the hardware resources used in this example
361 * @param hspi: SPI handle pointer
362 * @retval None
363 */
HAL_SPI_MspInit(SPI_HandleTypeDef * hspi)364 void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi)
365 {
366 GPIO_InitTypeDef GPIO_InitStruct = {0};
367 if(hspi->Instance==SPI1)
368 {
369 /* USER CODE BEGIN SPI1_MspInit 0 */
370
371 /* USER CODE END SPI1_MspInit 0 */
372 /* Peripheral clock enable */
373 __HAL_RCC_SPI1_CLK_ENABLE();
374
375 __HAL_RCC_GPIOA_CLK_ENABLE();
376 /**SPI1 GPIO Configuration
377 PA1 ------> SPI1_SCK
378 PA6 ------> SPI1_MISO
379 PA7 ------> SPI1_MOSI
380 */
381 GPIO_InitStruct.Pin = GPIO_PIN_1|GPIO_PIN_6|GPIO_PIN_7;
382 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
383 GPIO_InitStruct.Pull = GPIO_NOPULL;
384 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
385 GPIO_InitStruct.Alternate = GPIO_AF5_SPI1;
386 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
387
388 /* USER CODE BEGIN SPI1_MspInit 1 */
389
390 /* USER CODE END SPI1_MspInit 1 */
391 }
392 else if(hspi->Instance==SPI2)
393 {
394 /* USER CODE BEGIN SPI2_MspInit 0 */
395
396 /* USER CODE END SPI2_MspInit 0 */
397 /* Peripheral clock enable */
398 __HAL_RCC_SPI2_CLK_ENABLE();
399
400 __HAL_RCC_GPIOC_CLK_ENABLE();
401 __HAL_RCC_GPIOA_CLK_ENABLE();
402 /**SPI2 GPIO Configuration
403 PC1 ------> SPI2_MOSI
404 PC2 ------> SPI2_MISO
405 PA9 ------> SPI2_SCK
406 */
407 GPIO_InitStruct.Pin = GPIO_PIN_1;
408 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
409 GPIO_InitStruct.Pull = GPIO_NOPULL;
410 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
411 GPIO_InitStruct.Alternate = GPIO_AF3_SPI2;
412 HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
413
414 GPIO_InitStruct.Pin = GPIO_PIN_2;
415 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
416 GPIO_InitStruct.Pull = GPIO_NOPULL;
417 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
418 GPIO_InitStruct.Alternate = GPIO_AF5_SPI2;
419 HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
420
421 GPIO_InitStruct.Pin = GPIO_PIN_9;
422 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
423 GPIO_InitStruct.Pull = GPIO_NOPULL;
424 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
425 GPIO_InitStruct.Alternate = GPIO_AF5_SPI2;
426 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
427
428 /* USER CODE BEGIN SPI2_MspInit 1 */
429
430 /* USER CODE END SPI2_MspInit 1 */
431 }
432
433 }
434
435 /**
436 * @brief SPI MSP De-Initialization
437 * This function freeze the hardware resources used in this example
438 * @param hspi: SPI handle pointer
439 * @retval None
440 */
HAL_SPI_MspDeInit(SPI_HandleTypeDef * hspi)441 void HAL_SPI_MspDeInit(SPI_HandleTypeDef* hspi)
442 {
443 if(hspi->Instance==SPI1)
444 {
445 /* USER CODE BEGIN SPI1_MspDeInit 0 */
446
447 /* USER CODE END SPI1_MspDeInit 0 */
448 /* Peripheral clock disable */
449 __HAL_RCC_SPI1_CLK_DISABLE();
450
451 /**SPI1 GPIO Configuration
452 PA1 ------> SPI1_SCK
453 PA6 ------> SPI1_MISO
454 PA7 ------> SPI1_MOSI
455 */
456 HAL_GPIO_DeInit(GPIOA, GPIO_PIN_1|GPIO_PIN_6|GPIO_PIN_7);
457
458 /* USER CODE BEGIN SPI1_MspDeInit 1 */
459
460 /* USER CODE END SPI1_MspDeInit 1 */
461 }
462 else if(hspi->Instance==SPI2)
463 {
464 /* USER CODE BEGIN SPI2_MspDeInit 0 */
465
466 /* USER CODE END SPI2_MspDeInit 0 */
467 /* Peripheral clock disable */
468 __HAL_RCC_SPI2_CLK_DISABLE();
469
470 /**SPI2 GPIO Configuration
471 PC1 ------> SPI2_MOSI
472 PC2 ------> SPI2_MISO
473 PA9 ------> SPI2_SCK
474 */
475 HAL_GPIO_DeInit(GPIOC, GPIO_PIN_1|GPIO_PIN_2);
476
477 HAL_GPIO_DeInit(GPIOA, GPIO_PIN_9);
478
479 /* USER CODE BEGIN SPI2_MspDeInit 1 */
480
481 /* USER CODE END SPI2_MspDeInit 1 */
482 }
483
484 }
485
486 /**
487 * @brief TIM_Base MSP Initialization
488 * This function configures the hardware resources used in this example
489 * @param htim_base: TIM_Base handle pointer
490 * @retval None
491 */
HAL_TIM_Base_MspInit(TIM_HandleTypeDef * htim_base)492 void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* htim_base)
493 {
494 if(htim_base->Instance==TIM16)
495 {
496 /* USER CODE BEGIN TIM16_MspInit 0 */
497
498 /* USER CODE END TIM16_MspInit 0 */
499 /* Peripheral clock enable */
500 __HAL_RCC_TIM16_CLK_ENABLE();
501 /* USER CODE BEGIN TIM16_MspInit 1 */
502
503 /* USER CODE END TIM16_MspInit 1 */
504 }
505 else if(htim_base->Instance==TIM17)
506 {
507 /* USER CODE BEGIN TIM17_MspInit 0 */
508
509 /* USER CODE END TIM17_MspInit 0 */
510 /* Peripheral clock enable */
511 __HAL_RCC_TIM17_CLK_ENABLE();
512 /* USER CODE BEGIN TIM17_MspInit 1 */
513
514 /* USER CODE END TIM17_MspInit 1 */
515 }
516
517 }
518
519 /**
520 * @brief TIM_Base MSP De-Initialization
521 * This function freeze the hardware resources used in this example
522 * @param htim_base: TIM_Base handle pointer
523 * @retval None
524 */
HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef * htim_base)525 void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* htim_base)
526 {
527 if(htim_base->Instance==TIM16)
528 {
529 /* USER CODE BEGIN TIM16_MspDeInit 0 */
530
531 /* USER CODE END TIM16_MspDeInit 0 */
532 /* Peripheral clock disable */
533 __HAL_RCC_TIM16_CLK_DISABLE();
534 /* USER CODE BEGIN TIM16_MspDeInit 1 */
535
536 /* USER CODE END TIM16_MspDeInit 1 */
537 }
538 else if(htim_base->Instance==TIM17)
539 {
540 /* USER CODE BEGIN TIM17_MspDeInit 0 */
541
542 /* USER CODE END TIM17_MspDeInit 0 */
543 /* Peripheral clock disable */
544 __HAL_RCC_TIM17_CLK_DISABLE();
545 /* USER CODE BEGIN TIM17_MspDeInit 1 */
546
547 /* USER CODE END TIM17_MspDeInit 1 */
548 }
549
550 }
551
552 /**
553 * @brief PCD MSP Initialization
554 * This function configures the hardware resources used in this example
555 * @param hpcd: PCD handle pointer
556 * @retval None
557 */
HAL_PCD_MspInit(PCD_HandleTypeDef * hpcd)558 void HAL_PCD_MspInit(PCD_HandleTypeDef* hpcd)
559 {
560 GPIO_InitTypeDef GPIO_InitStruct = {0};
561 if(hpcd->Instance==USB)
562 {
563 /* USER CODE BEGIN USB_MspInit 0 */
564
565 /* USER CODE END USB_MspInit 0 */
566
567 __HAL_RCC_GPIOA_CLK_ENABLE();
568 /**USB GPIO Configuration
569 PA11 ------> USB_DM
570 PA12 ------> USB_DP
571 */
572 GPIO_InitStruct.Pin = GPIO_PIN_11|GPIO_PIN_12;
573 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
574 GPIO_InitStruct.Pull = GPIO_NOPULL;
575 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
576 GPIO_InitStruct.Alternate = GPIO_AF10_USB;
577 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
578
579 /* Peripheral clock enable */
580 __HAL_RCC_USB_CLK_ENABLE();
581 /* USER CODE BEGIN USB_MspInit 1 */
582
583 /* USER CODE END USB_MspInit 1 */
584 }
585
586 }
587
588 /**
589 * @brief PCD MSP De-Initialization
590 * This function freeze the hardware resources used in this example
591 * @param hpcd: PCD handle pointer
592 * @retval None
593 */
HAL_PCD_MspDeInit(PCD_HandleTypeDef * hpcd)594 void HAL_PCD_MspDeInit(PCD_HandleTypeDef* hpcd)
595 {
596 if(hpcd->Instance==USB)
597 {
598 /* USER CODE BEGIN USB_MspDeInit 0 */
599
600 /* USER CODE END USB_MspDeInit 0 */
601 /* Peripheral clock disable */
602 __HAL_RCC_USB_CLK_DISABLE();
603
604 /**USB GPIO Configuration
605 PA11 ------> USB_DM
606 PA12 ------> USB_DP
607 */
608 HAL_GPIO_DeInit(GPIOA, GPIO_PIN_11|GPIO_PIN_12);
609
610 /* USER CODE BEGIN USB_MspDeInit 1 */
611
612 /* USER CODE END USB_MspDeInit 1 */
613 }
614
615 }
616
617 /* USER CODE BEGIN 1 */
618
619 /* USER CODE END 1 */
620
621 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
622