1 /* USER CODE BEGIN Header */
2 /**
3 ******************************************************************************
4 * File Name : stm32f4xx_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 #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 void HAL_TIM_MspPostInit(TIM_HandleTypeDef *htim);
83 /**
84 * Initializes the Global MSP.
85 */
HAL_MspInit(void)86 void HAL_MspInit(void)
87 {
88 /* USER CODE BEGIN MspInit 0 */
89
90 /* USER CODE END MspInit 0 */
91
92 __HAL_RCC_SYSCFG_CLK_ENABLE();
93 __HAL_RCC_PWR_CLK_ENABLE();
94
95 /* System interrupt init*/
96
97 /* USER CODE BEGIN MspInit 1 */
98
99 /* USER CODE END MspInit 1 */
100 }
101
102 /**
103 * @brief DAC MSP Initialization
104 * This function configures the hardware resources used in this example
105 * @param hdac: DAC handle pointer
106 * @retval None
107 */
HAL_DAC_MspInit(DAC_HandleTypeDef * hdac)108 void HAL_DAC_MspInit(DAC_HandleTypeDef* hdac)
109 {
110 GPIO_InitTypeDef GPIO_InitStruct = {0};
111 if(hdac->Instance==DAC)
112 {
113 /* USER CODE BEGIN DAC_MspInit 0 */
114
115 /* USER CODE END DAC_MspInit 0 */
116 /* Peripheral clock enable */
117 __HAL_RCC_DAC_CLK_ENABLE();
118
119 __HAL_RCC_GPIOA_CLK_ENABLE();
120 /**DAC GPIO Configuration
121 PA4 ------> DAC_OUT1
122 PA5 ------> DAC_OUT2
123 */
124 GPIO_InitStruct.Pin = GPIO_PIN_4|GPIO_PIN_5;
125 GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
126 GPIO_InitStruct.Pull = GPIO_NOPULL;
127 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
128
129 /* USER CODE BEGIN DAC_MspInit 1 */
130
131 /* USER CODE END DAC_MspInit 1 */
132 }
133
134 }
135
136 /**
137 * @brief DAC MSP De-Initialization
138 * This function freeze the hardware resources used in this example
139 * @param hdac: DAC handle pointer
140 * @retval None
141 */
HAL_DAC_MspDeInit(DAC_HandleTypeDef * hdac)142 void HAL_DAC_MspDeInit(DAC_HandleTypeDef* hdac)
143 {
144 if(hdac->Instance==DAC)
145 {
146 /* USER CODE BEGIN DAC_MspDeInit 0 */
147
148 /* USER CODE END DAC_MspDeInit 0 */
149 /* Peripheral clock disable */
150 __HAL_RCC_DAC_CLK_DISABLE();
151
152 /**DAC GPIO Configuration
153 PA4 ------> DAC_OUT1
154 PA5 ------> DAC_OUT2
155 */
156 HAL_GPIO_DeInit(GPIOA, GPIO_PIN_4|GPIO_PIN_5);
157
158 /* USER CODE BEGIN DAC_MspDeInit 1 */
159
160 /* USER CODE END DAC_MspDeInit 1 */
161 }
162
163 }
164
165 /**
166 * @brief ETH MSP Initialization
167 * This function configures the hardware resources used in this example
168 * @param heth: ETH handle pointer
169 * @retval None
170 */
HAL_ETH_MspInit(ETH_HandleTypeDef * heth)171 void HAL_ETH_MspInit(ETH_HandleTypeDef* heth)
172 {
173 GPIO_InitTypeDef GPIO_InitStruct = {0};
174 if(heth->Instance==ETH)
175 {
176 /* USER CODE BEGIN ETH_MspInit 0 */
177
178 /* USER CODE END ETH_MspInit 0 */
179 /* Peripheral clock enable */
180 __HAL_RCC_ETH_CLK_ENABLE();
181
182 __HAL_RCC_GPIOC_CLK_ENABLE();
183 __HAL_RCC_GPIOA_CLK_ENABLE();
184 __HAL_RCC_GPIOG_CLK_ENABLE();
185 /**ETH GPIO Configuration
186 PC1 ------> ETH_MDC
187 PA1 ------> ETH_REF_CLK
188 PA2 ------> ETH_MDIO
189 PA7 ------> ETH_CRS_DV
190 PC4 ------> ETH_RXD0
191 PC5 ------> ETH_RXD1
192 PG11 ------> ETH_TX_EN
193 PG13 ------> ETH_TXD0
194 PG14 ------> ETH_TXD1
195 */
196 GPIO_InitStruct.Pin = GPIO_PIN_1|GPIO_PIN_4|GPIO_PIN_5;
197 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
198 GPIO_InitStruct.Pull = GPIO_NOPULL;
199 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
200 GPIO_InitStruct.Alternate = GPIO_AF11_ETH;
201 HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
202
203 GPIO_InitStruct.Pin = GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_7;
204 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
205 GPIO_InitStruct.Pull = GPIO_NOPULL;
206 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
207 GPIO_InitStruct.Alternate = GPIO_AF11_ETH;
208 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
209
210 GPIO_InitStruct.Pin = GPIO_PIN_11|GPIO_PIN_13|GPIO_PIN_14;
211 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
212 GPIO_InitStruct.Pull = GPIO_NOPULL;
213 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
214 GPIO_InitStruct.Alternate = GPIO_AF11_ETH;
215 HAL_GPIO_Init(GPIOG, &GPIO_InitStruct);
216
217 /* USER CODE BEGIN ETH_MspInit 1 */
218
219 /* USER CODE END ETH_MspInit 1 */
220 }
221
222 }
223
224 /**
225 * @brief ETH MSP De-Initialization
226 * This function freeze the hardware resources used in this example
227 * @param heth: ETH handle pointer
228 * @retval None
229 */
HAL_ETH_MspDeInit(ETH_HandleTypeDef * heth)230 void HAL_ETH_MspDeInit(ETH_HandleTypeDef* heth)
231 {
232 if(heth->Instance==ETH)
233 {
234 /* USER CODE BEGIN ETH_MspDeInit 0 */
235
236 /* USER CODE END ETH_MspDeInit 0 */
237 /* Peripheral clock disable */
238 __HAL_RCC_ETH_CLK_DISABLE();
239
240 /**ETH GPIO Configuration
241 PC1 ------> ETH_MDC
242 PA1 ------> ETH_REF_CLK
243 PA2 ------> ETH_MDIO
244 PA7 ------> ETH_CRS_DV
245 PC4 ------> ETH_RXD0
246 PC5 ------> ETH_RXD1
247 PG11 ------> ETH_TX_EN
248 PG13 ------> ETH_TXD0
249 PG14 ------> ETH_TXD1
250 */
251 HAL_GPIO_DeInit(GPIOC, GPIO_PIN_1|GPIO_PIN_4|GPIO_PIN_5);
252
253 HAL_GPIO_DeInit(GPIOA, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_7);
254
255 HAL_GPIO_DeInit(GPIOG, GPIO_PIN_11|GPIO_PIN_13|GPIO_PIN_14);
256
257 /* USER CODE BEGIN ETH_MspDeInit 1 */
258
259 /* USER CODE END ETH_MspDeInit 1 */
260 }
261
262 }
263
264 /**
265 * @brief RTC MSP Initialization
266 * This function configures the hardware resources used in this example
267 * @param hrtc: RTC handle pointer
268 * @retval None
269 */
HAL_RTC_MspInit(RTC_HandleTypeDef * hrtc)270 void HAL_RTC_MspInit(RTC_HandleTypeDef* hrtc)
271 {
272 if(hrtc->Instance==RTC)
273 {
274 /* USER CODE BEGIN RTC_MspInit 0 */
275
276 /* USER CODE END RTC_MspInit 0 */
277 /* Peripheral clock enable */
278 __HAL_RCC_RTC_ENABLE();
279 /* USER CODE BEGIN RTC_MspInit 1 */
280
281 /* USER CODE END RTC_MspInit 1 */
282 }
283
284 }
285
286 /**
287 * @brief RTC MSP De-Initialization
288 * This function freeze the hardware resources used in this example
289 * @param hrtc: RTC handle pointer
290 * @retval None
291 */
HAL_RTC_MspDeInit(RTC_HandleTypeDef * hrtc)292 void HAL_RTC_MspDeInit(RTC_HandleTypeDef* hrtc)
293 {
294 if(hrtc->Instance==RTC)
295 {
296 /* USER CODE BEGIN RTC_MspDeInit 0 */
297
298 /* USER CODE END RTC_MspDeInit 0 */
299 /* Peripheral clock disable */
300 __HAL_RCC_RTC_DISABLE();
301 /* USER CODE BEGIN RTC_MspDeInit 1 */
302
303 /* USER CODE END RTC_MspDeInit 1 */
304 }
305
306 }
307
308 /**
309 * @brief SD MSP Initialization
310 * This function configures the hardware resources used in this example
311 * @param hsd: SD handle pointer
312 * @retval None
313 */
HAL_SD_MspInit(SD_HandleTypeDef * hsd)314 void HAL_SD_MspInit(SD_HandleTypeDef* hsd)
315 {
316 GPIO_InitTypeDef GPIO_InitStruct = {0};
317 if(hsd->Instance==SDIO)
318 {
319 /* USER CODE BEGIN SDIO_MspInit 0 */
320
321 /* USER CODE END SDIO_MspInit 0 */
322 /* Peripheral clock enable */
323 __HAL_RCC_SDIO_CLK_ENABLE();
324
325 __HAL_RCC_GPIOC_CLK_ENABLE();
326 __HAL_RCC_GPIOD_CLK_ENABLE();
327 /**SDIO GPIO Configuration
328 PC8 ------> SDIO_D0
329 PC9 ------> SDIO_D1
330 PC10 ------> SDIO_D2
331 PC11 ------> SDIO_D3
332 PC12 ------> SDIO_CK
333 PD2 ------> SDIO_CMD
334 */
335 GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_11
336 |GPIO_PIN_12;
337 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
338 GPIO_InitStruct.Pull = GPIO_NOPULL;
339 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
340 GPIO_InitStruct.Alternate = GPIO_AF12_SDIO;
341 HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
342
343 GPIO_InitStruct.Pin = GPIO_PIN_2;
344 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
345 GPIO_InitStruct.Pull = GPIO_NOPULL;
346 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
347 GPIO_InitStruct.Alternate = GPIO_AF12_SDIO;
348 HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
349
350 /* USER CODE BEGIN SDIO_MspInit 1 */
351
352 /* USER CODE END SDIO_MspInit 1 */
353 }
354
355 }
356
357 /**
358 * @brief SD MSP De-Initialization
359 * This function freeze the hardware resources used in this example
360 * @param hsd: SD handle pointer
361 * @retval None
362 */
HAL_SD_MspDeInit(SD_HandleTypeDef * hsd)363 void HAL_SD_MspDeInit(SD_HandleTypeDef* hsd)
364 {
365 if(hsd->Instance==SDIO)
366 {
367 /* USER CODE BEGIN SDIO_MspDeInit 0 */
368
369 /* USER CODE END SDIO_MspDeInit 0 */
370 /* Peripheral clock disable */
371 __HAL_RCC_SDIO_CLK_DISABLE();
372
373 /**SDIO GPIO Configuration
374 PC8 ------> SDIO_D0
375 PC9 ------> SDIO_D1
376 PC10 ------> SDIO_D2
377 PC11 ------> SDIO_D3
378 PC12 ------> SDIO_CK
379 PD2 ------> SDIO_CMD
380 */
381 HAL_GPIO_DeInit(GPIOC, GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_11
382 |GPIO_PIN_12);
383
384 HAL_GPIO_DeInit(GPIOD, GPIO_PIN_2);
385
386 /* USER CODE BEGIN SDIO_MspDeInit 1 */
387
388 /* USER CODE END SDIO_MspDeInit 1 */
389 }
390
391 }
392
393 /**
394 * @brief SPI MSP Initialization
395 * This function configures the hardware resources used in this example
396 * @param hspi: SPI handle pointer
397 * @retval None
398 */
HAL_SPI_MspInit(SPI_HandleTypeDef * hspi)399 void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi)
400 {
401 GPIO_InitTypeDef GPIO_InitStruct = {0};
402 if(hspi->Instance==SPI1)
403 {
404 /* USER CODE BEGIN SPI1_MspInit 0 */
405
406 /* USER CODE END SPI1_MspInit 0 */
407 /* Peripheral clock enable */
408 __HAL_RCC_SPI1_CLK_ENABLE();
409
410 __HAL_RCC_GPIOB_CLK_ENABLE();
411 /**SPI1 GPIO Configuration
412 PB3 ------> SPI1_SCK
413 PB4 ------> SPI1_MISO
414 PB5 ------> SPI1_MOSI
415 */
416 GPIO_InitStruct.Pin = GPIO_PIN_3|GPIO_PIN_4|GPIO_PIN_5;
417 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
418 GPIO_InitStruct.Pull = GPIO_NOPULL;
419 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
420 GPIO_InitStruct.Alternate = GPIO_AF5_SPI1;
421 HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
422
423 /* SPI1 interrupt Init */
424 HAL_NVIC_SetPriority(SPI1_IRQn, 0, 0);
425 HAL_NVIC_EnableIRQ(SPI1_IRQn);
426 /* USER CODE BEGIN SPI1_MspInit 1 */
427
428 /* USER CODE END SPI1_MspInit 1 */
429 }
430 else if(hspi->Instance==SPI2)
431 {
432 /* USER CODE BEGIN SPI2_MspInit 0 */
433
434 /* USER CODE END SPI2_MspInit 0 */
435 /* Peripheral clock enable */
436 __HAL_RCC_SPI2_CLK_ENABLE();
437
438 __HAL_RCC_GPIOC_CLK_ENABLE();
439 __HAL_RCC_GPIOB_CLK_ENABLE();
440 /**SPI2 GPIO Configuration
441 PC2 ------> SPI2_MISO
442 PC3 ------> SPI2_MOSI
443 PB13 ------> SPI2_SCK
444 */
445 GPIO_InitStruct.Pin = GPIO_PIN_2|GPIO_PIN_3;
446 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
447 GPIO_InitStruct.Pull = GPIO_NOPULL;
448 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
449 GPIO_InitStruct.Alternate = GPIO_AF5_SPI2;
450 HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
451
452 GPIO_InitStruct.Pin = GPIO_PIN_13;
453 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
454 GPIO_InitStruct.Pull = GPIO_NOPULL;
455 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
456 GPIO_InitStruct.Alternate = GPIO_AF5_SPI2;
457 HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
458
459 /* USER CODE BEGIN SPI2_MspInit 1 */
460
461 /* USER CODE END SPI2_MspInit 1 */
462 }
463
464 }
465
466 /**
467 * @brief SPI MSP De-Initialization
468 * This function freeze the hardware resources used in this example
469 * @param hspi: SPI handle pointer
470 * @retval None
471 */
HAL_SPI_MspDeInit(SPI_HandleTypeDef * hspi)472 void HAL_SPI_MspDeInit(SPI_HandleTypeDef* hspi)
473 {
474 if(hspi->Instance==SPI1)
475 {
476 /* USER CODE BEGIN SPI1_MspDeInit 0 */
477
478 /* USER CODE END SPI1_MspDeInit 0 */
479 /* Peripheral clock disable */
480 __HAL_RCC_SPI1_CLK_DISABLE();
481
482 /**SPI1 GPIO Configuration
483 PB3 ------> SPI1_SCK
484 PB4 ------> SPI1_MISO
485 PB5 ------> SPI1_MOSI
486 */
487 HAL_GPIO_DeInit(GPIOB, GPIO_PIN_3|GPIO_PIN_4|GPIO_PIN_5);
488
489 /* SPI1 interrupt DeInit */
490 HAL_NVIC_DisableIRQ(SPI1_IRQn);
491 /* USER CODE BEGIN SPI1_MspDeInit 1 */
492
493 /* USER CODE END SPI1_MspDeInit 1 */
494 }
495 else if(hspi->Instance==SPI2)
496 {
497 /* USER CODE BEGIN SPI2_MspDeInit 0 */
498
499 /* USER CODE END SPI2_MspDeInit 0 */
500 /* Peripheral clock disable */
501 __HAL_RCC_SPI2_CLK_DISABLE();
502
503 /**SPI2 GPIO Configuration
504 PC2 ------> SPI2_MISO
505 PC3 ------> SPI2_MOSI
506 PB13 ------> SPI2_SCK
507 */
508 HAL_GPIO_DeInit(GPIOC, GPIO_PIN_2|GPIO_PIN_3);
509
510 HAL_GPIO_DeInit(GPIOB, GPIO_PIN_13);
511
512 /* USER CODE BEGIN SPI2_MspDeInit 1 */
513
514 /* USER CODE END SPI2_MspDeInit 1 */
515 }
516
517 }
518
519 /**
520 * @brief TIM_Base MSP Initialization
521 * This function configures the hardware resources used in this example
522 * @param htim_base: TIM_Base handle pointer
523 * @retval None
524 */
HAL_TIM_Base_MspInit(TIM_HandleTypeDef * htim_base)525 void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* htim_base)
526 {
527 if(htim_base->Instance==TIM2)
528 {
529 /* USER CODE BEGIN TIM2_MspInit 0 */
530
531 /* USER CODE END TIM2_MspInit 0 */
532 /* Peripheral clock enable */
533 __HAL_RCC_TIM2_CLK_ENABLE();
534 /* USER CODE BEGIN TIM2_MspInit 1 */
535
536 /* USER CODE END TIM2_MspInit 1 */
537 }
538 else if(htim_base->Instance==TIM11)
539 {
540 /* USER CODE BEGIN TIM11_MspInit 0 */
541
542 /* USER CODE END TIM11_MspInit 0 */
543 /* Peripheral clock enable */
544 __HAL_RCC_TIM11_CLK_ENABLE();
545 /* USER CODE BEGIN TIM11_MspInit 1 */
546
547 /* USER CODE END TIM11_MspInit 1 */
548 }
549 else if(htim_base->Instance==TIM13)
550 {
551 /* USER CODE BEGIN TIM13_MspInit 0 */
552
553 /* USER CODE END TIM13_MspInit 0 */
554 /* Peripheral clock enable */
555 __HAL_RCC_TIM13_CLK_ENABLE();
556 /* USER CODE BEGIN TIM13_MspInit 1 */
557
558 /* USER CODE END TIM13_MspInit 1 */
559 }
560 else if(htim_base->Instance==TIM14)
561 {
562 /* USER CODE BEGIN TIM14_MspInit 0 */
563
564 /* USER CODE END TIM14_MspInit 0 */
565 /* Peripheral clock enable */
566 __HAL_RCC_TIM14_CLK_ENABLE();
567 /* USER CODE BEGIN TIM14_MspInit 1 */
568
569 /* USER CODE END TIM14_MspInit 1 */
570 }
571
572 }
573
574 /**
575 * @brief TIM_Encoder MSP Initialization
576 * This function configures the hardware resources used in this example
577 * @param htim_encoder: TIM_Encoder handle pointer
578 * @retval None
579 */
HAL_TIM_Encoder_MspInit(TIM_HandleTypeDef * htim_encoder)580 void HAL_TIM_Encoder_MspInit(TIM_HandleTypeDef* htim_encoder)
581 {
582 GPIO_InitTypeDef GPIO_InitStruct = {0};
583 if(htim_encoder->Instance==TIM4)
584 {
585 /* USER CODE BEGIN TIM4_MspInit 0 */
586
587 /* USER CODE END TIM4_MspInit 0 */
588 /* Peripheral clock enable */
589 __HAL_RCC_TIM4_CLK_ENABLE();
590
591 __HAL_RCC_GPIOB_CLK_ENABLE();
592 /**TIM4 GPIO Configuration
593 PB6 ------> TIM4_CH1
594 PB7 ------> TIM4_CH2
595 */
596 GPIO_InitStruct.Pin = GPIO_PIN_6|GPIO_PIN_7;
597 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
598 GPIO_InitStruct.Pull = GPIO_NOPULL;
599 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
600 GPIO_InitStruct.Alternate = GPIO_AF2_TIM4;
601 HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
602
603 /* USER CODE BEGIN TIM4_MspInit 1 */
604
605 /* USER CODE END TIM4_MspInit 1 */
606 }
607
608 }
609
HAL_TIM_MspPostInit(TIM_HandleTypeDef * htim)610 void HAL_TIM_MspPostInit(TIM_HandleTypeDef* htim)
611 {
612 GPIO_InitTypeDef GPIO_InitStruct = {0};
613 if(htim->Instance==TIM2)
614 {
615 /* USER CODE BEGIN TIM2_MspPostInit 0 */
616
617 /* USER CODE END TIM2_MspPostInit 0 */
618
619 __HAL_RCC_GPIOA_CLK_ENABLE();
620 /**TIM2 GPIO Configuration
621 PA3 ------> TIM2_CH4
622 */
623 GPIO_InitStruct.Pin = GPIO_PIN_3;
624 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
625 GPIO_InitStruct.Pull = GPIO_NOPULL;
626 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
627 GPIO_InitStruct.Alternate = GPIO_AF1_TIM2;
628 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
629
630 /* USER CODE BEGIN TIM2_MspPostInit 1 */
631
632 /* USER CODE END TIM2_MspPostInit 1 */
633 }
634
635 }
636 /**
637 * @brief TIM_Base MSP De-Initialization
638 * This function freeze the hardware resources used in this example
639 * @param htim_base: TIM_Base handle pointer
640 * @retval None
641 */
HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef * htim_base)642 void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* htim_base)
643 {
644 if(htim_base->Instance==TIM2)
645 {
646 /* USER CODE BEGIN TIM2_MspDeInit 0 */
647
648 /* USER CODE END TIM2_MspDeInit 0 */
649 /* Peripheral clock disable */
650 __HAL_RCC_TIM2_CLK_DISABLE();
651 /* USER CODE BEGIN TIM2_MspDeInit 1 */
652
653 /* USER CODE END TIM2_MspDeInit 1 */
654 }
655 else if(htim_base->Instance==TIM11)
656 {
657 /* USER CODE BEGIN TIM11_MspDeInit 0 */
658
659 /* USER CODE END TIM11_MspDeInit 0 */
660 /* Peripheral clock disable */
661 __HAL_RCC_TIM11_CLK_DISABLE();
662 /* USER CODE BEGIN TIM11_MspDeInit 1 */
663
664 /* USER CODE END TIM11_MspDeInit 1 */
665 }
666 else if(htim_base->Instance==TIM13)
667 {
668 /* USER CODE BEGIN TIM13_MspDeInit 0 */
669
670 /* USER CODE END TIM13_MspDeInit 0 */
671 /* Peripheral clock disable */
672 __HAL_RCC_TIM13_CLK_DISABLE();
673 /* USER CODE BEGIN TIM13_MspDeInit 1 */
674
675 /* USER CODE END TIM13_MspDeInit 1 */
676 }
677 else if(htim_base->Instance==TIM14)
678 {
679 /* USER CODE BEGIN TIM14_MspDeInit 0 */
680
681 /* USER CODE END TIM14_MspDeInit 0 */
682 /* Peripheral clock disable */
683 __HAL_RCC_TIM14_CLK_DISABLE();
684 /* USER CODE BEGIN TIM14_MspDeInit 1 */
685
686 /* USER CODE END TIM14_MspDeInit 1 */
687 }
688
689 }
690
691 /**
692 * @brief TIM_Encoder MSP De-Initialization
693 * This function freeze the hardware resources used in this example
694 * @param htim_encoder: TIM_Encoder handle pointer
695 * @retval None
696 */
HAL_TIM_Encoder_MspDeInit(TIM_HandleTypeDef * htim_encoder)697 void HAL_TIM_Encoder_MspDeInit(TIM_HandleTypeDef* htim_encoder)
698 {
699 if(htim_encoder->Instance==TIM4)
700 {
701 /* USER CODE BEGIN TIM4_MspDeInit 0 */
702
703 /* USER CODE END TIM4_MspDeInit 0 */
704 /* Peripheral clock disable */
705 __HAL_RCC_TIM4_CLK_DISABLE();
706
707 /**TIM4 GPIO Configuration
708 PB6 ------> TIM4_CH1
709 PB7 ------> TIM4_CH2
710 */
711 HAL_GPIO_DeInit(GPIOB, GPIO_PIN_6|GPIO_PIN_7);
712
713 /* USER CODE BEGIN TIM4_MspDeInit 1 */
714
715 /* USER CODE END TIM4_MspDeInit 1 */
716 }
717
718 }
719
720 /**
721 * @brief UART MSP Initialization
722 * This function configures the hardware resources used in this example
723 * @param huart: UART handle pointer
724 * @retval None
725 */
HAL_UART_MspInit(UART_HandleTypeDef * huart)726 void HAL_UART_MspInit(UART_HandleTypeDef* huart)
727 {
728 GPIO_InitTypeDef GPIO_InitStruct = {0};
729 if(huart->Instance==USART1)
730 {
731 /* USER CODE BEGIN USART1_MspInit 0 */
732
733 /* USER CODE END USART1_MspInit 0 */
734 /* Peripheral clock enable */
735 __HAL_RCC_USART1_CLK_ENABLE();
736
737 __HAL_RCC_GPIOA_CLK_ENABLE();
738 /**USART1 GPIO Configuration
739 PA9 ------> USART1_TX
740 PA10 ------> USART1_RX
741 */
742 GPIO_InitStruct.Pin = GPIO_PIN_9|GPIO_PIN_10;
743 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
744 GPIO_InitStruct.Pull = GPIO_PULLUP;
745 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
746 GPIO_InitStruct.Alternate = GPIO_AF7_USART1;
747 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
748
749 /* USART1 interrupt Init */
750 HAL_NVIC_SetPriority(USART1_IRQn, 0, 0);
751 HAL_NVIC_EnableIRQ(USART1_IRQn);
752 /* USER CODE BEGIN USART1_MspInit 1 */
753
754 /* USER CODE END USART1_MspInit 1 */
755 }
756 else if(huart->Instance==USART3)
757 {
758 /* USER CODE BEGIN USART3_MspInit 0 */
759
760 /* USER CODE END USART3_MspInit 0 */
761 /* Peripheral clock enable */
762 __HAL_RCC_USART3_CLK_ENABLE();
763
764 __HAL_RCC_GPIOB_CLK_ENABLE();
765 /**USART3 GPIO Configuration
766 PB10 ------> USART3_TX
767 PB11 ------> USART3_RX
768 */
769 GPIO_InitStruct.Pin = GPIO_PIN_10|GPIO_PIN_11;
770 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
771 GPIO_InitStruct.Pull = GPIO_PULLUP;
772 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
773 GPIO_InitStruct.Alternate = GPIO_AF7_USART3;
774 HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
775
776 /* USER CODE BEGIN USART3_MspInit 1 */
777
778 /* USER CODE END USART3_MspInit 1 */
779 }
780
781 }
782
783 /**
784 * @brief UART MSP De-Initialization
785 * This function freeze the hardware resources used in this example
786 * @param huart: UART handle pointer
787 * @retval None
788 */
HAL_UART_MspDeInit(UART_HandleTypeDef * huart)789 void HAL_UART_MspDeInit(UART_HandleTypeDef* huart)
790 {
791 if(huart->Instance==USART1)
792 {
793 /* USER CODE BEGIN USART1_MspDeInit 0 */
794
795 /* USER CODE END USART1_MspDeInit 0 */
796 /* Peripheral clock disable */
797 __HAL_RCC_USART1_CLK_DISABLE();
798
799 /**USART1 GPIO Configuration
800 PA9 ------> USART1_TX
801 PA10 ------> USART1_RX
802 */
803 HAL_GPIO_DeInit(GPIOA, GPIO_PIN_9|GPIO_PIN_10);
804
805 /* USART1 interrupt DeInit */
806 HAL_NVIC_DisableIRQ(USART1_IRQn);
807 /* USER CODE BEGIN USART1_MspDeInit 1 */
808
809 /* USER CODE END USART1_MspDeInit 1 */
810 }
811 else if(huart->Instance==USART3)
812 {
813 /* USER CODE BEGIN USART3_MspDeInit 0 */
814
815 /* USER CODE END USART3_MspDeInit 0 */
816 /* Peripheral clock disable */
817 __HAL_RCC_USART3_CLK_DISABLE();
818
819 /**USART3 GPIO Configuration
820 PB10 ------> USART3_TX
821 PB11 ------> USART3_RX
822 */
823 HAL_GPIO_DeInit(GPIOB, GPIO_PIN_10|GPIO_PIN_11);
824
825 /* USER CODE BEGIN USART3_MspDeInit 1 */
826
827 /* USER CODE END USART3_MspDeInit 1 */
828 }
829
830 }
831
832 /**
833 * @brief PCD MSP Initialization
834 * This function configures the hardware resources used in this example
835 * @param hpcd: PCD handle pointer
836 * @retval None
837 */
HAL_PCD_MspInit(PCD_HandleTypeDef * hpcd)838 void HAL_PCD_MspInit(PCD_HandleTypeDef* hpcd)
839 {
840 GPIO_InitTypeDef GPIO_InitStruct = {0};
841 if(hpcd->Instance==USB_OTG_FS)
842 {
843 /* USER CODE BEGIN USB_OTG_FS_MspInit 0 */
844
845 /* USER CODE END USB_OTG_FS_MspInit 0 */
846
847 __HAL_RCC_GPIOA_CLK_ENABLE();
848 /**USB_OTG_FS GPIO Configuration
849 PA11 ------> USB_OTG_FS_DM
850 PA12 ------> USB_OTG_FS_DP
851 */
852 GPIO_InitStruct.Pin = GPIO_PIN_11|GPIO_PIN_12;
853 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
854 GPIO_InitStruct.Pull = GPIO_NOPULL;
855 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
856 GPIO_InitStruct.Alternate = GPIO_AF10_OTG_FS;
857 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
858
859 /* Peripheral clock enable */
860 __HAL_RCC_USB_OTG_FS_CLK_ENABLE();
861 /* USB_OTG_FS interrupt Init */
862 HAL_NVIC_SetPriority(OTG_FS_IRQn, 0, 0);
863 HAL_NVIC_EnableIRQ(OTG_FS_IRQn);
864 /* USER CODE BEGIN USB_OTG_FS_MspInit 1 */
865
866 /* USER CODE END USB_OTG_FS_MspInit 1 */
867 }
868
869 }
870
871 /**
872 * @brief PCD MSP De-Initialization
873 * This function freeze the hardware resources used in this example
874 * @param hpcd: PCD handle pointer
875 * @retval None
876 */
HAL_PCD_MspDeInit(PCD_HandleTypeDef * hpcd)877 void HAL_PCD_MspDeInit(PCD_HandleTypeDef* hpcd)
878 {
879 if(hpcd->Instance==USB_OTG_FS)
880 {
881 /* USER CODE BEGIN USB_OTG_FS_MspDeInit 0 */
882
883 /* USER CODE END USB_OTG_FS_MspDeInit 0 */
884 /* Peripheral clock disable */
885 __HAL_RCC_USB_OTG_FS_CLK_DISABLE();
886
887 /**USB_OTG_FS GPIO Configuration
888 PA11 ------> USB_OTG_FS_DM
889 PA12 ------> USB_OTG_FS_DP
890 */
891 HAL_GPIO_DeInit(GPIOA, GPIO_PIN_11|GPIO_PIN_12);
892
893 /* USB_OTG_FS interrupt DeInit */
894 HAL_NVIC_DisableIRQ(OTG_FS_IRQn);
895 /* USER CODE BEGIN USB_OTG_FS_MspDeInit 1 */
896
897 /* USER CODE END USB_OTG_FS_MspDeInit 1 */
898 }
899
900 }
901
902 static uint32_t FSMC_Initialized = 0;
903
HAL_FSMC_MspInit(void)904 static void HAL_FSMC_MspInit(void)
905 {
906 /* USER CODE BEGIN FSMC_MspInit 0 */
907
908 /* USER CODE END FSMC_MspInit 0 */
909 GPIO_InitTypeDef GPIO_InitStruct ={0};
910 if (FSMC_Initialized)
911 {
912 return;
913 }
914 FSMC_Initialized = 1;
915
916 /* Peripheral clock enable */
917 __HAL_RCC_FSMC_CLK_ENABLE();
918
919 /** FSMC GPIO Configuration
920 PF0 ------> FSMC_A0
921 PF1 ------> FSMC_A1
922 PF2 ------> FSMC_A2
923 PF3 ------> FSMC_A3
924 PF4 ------> FSMC_A4
925 PF5 ------> FSMC_A5
926 PF12 ------> FSMC_A6
927 PF13 ------> FSMC_A7
928 PF14 ------> FSMC_A8
929 PF15 ------> FSMC_A9
930 PG0 ------> FSMC_A10
931 PG1 ------> FSMC_A11
932 PE7 ------> FSMC_D4
933 PE8 ------> FSMC_D5
934 PE9 ------> FSMC_D6
935 PE10 ------> FSMC_D7
936 PE11 ------> FSMC_D8
937 PE12 ------> FSMC_D9
938 PE13 ------> FSMC_D10
939 PE14 ------> FSMC_D11
940 PE15 ------> FSMC_D12
941 PD8 ------> FSMC_D13
942 PD9 ------> FSMC_D14
943 PD10 ------> FSMC_D15
944 PD11 ------> FSMC_A16
945 PD12 ------> FSMC_A17
946 PD13 ------> FSMC_A18
947 PD14 ------> FSMC_D0
948 PD15 ------> FSMC_D1
949 PG2 ------> FSMC_A12
950 PG3 ------> FSMC_A13
951 PG4 ------> FSMC_A14
952 PG5 ------> FSMC_A15
953 PD0 ------> FSMC_D2
954 PD1 ------> FSMC_D3
955 PD4 ------> FSMC_NOE
956 PD5 ------> FSMC_NWE
957 PG10 ------> FSMC_NE3
958 PG12 ------> FSMC_NE4
959 PE0 ------> FSMC_NBL0
960 PE1 ------> FSMC_NBL1
961 */
962 GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3
963 |GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_12|GPIO_PIN_13
964 |GPIO_PIN_14|GPIO_PIN_15;
965 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
966 GPIO_InitStruct.Pull = GPIO_NOPULL;
967 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
968 GPIO_InitStruct.Alternate = GPIO_AF12_FSMC;
969 HAL_GPIO_Init(GPIOF, &GPIO_InitStruct);
970
971 GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3
972 |GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_10|GPIO_PIN_12;
973 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
974 GPIO_InitStruct.Pull = GPIO_NOPULL;
975 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
976 GPIO_InitStruct.Alternate = GPIO_AF12_FSMC;
977 HAL_GPIO_Init(GPIOG, &GPIO_InitStruct);
978
979 GPIO_InitStruct.Pin = GPIO_PIN_7|GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10
980 |GPIO_PIN_11|GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14
981 |GPIO_PIN_15|GPIO_PIN_0|GPIO_PIN_1;
982 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
983 GPIO_InitStruct.Pull = GPIO_NOPULL;
984 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
985 GPIO_InitStruct.Alternate = GPIO_AF12_FSMC;
986 HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
987
988 GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_11
989 |GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15
990 |GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_4|GPIO_PIN_5;
991 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
992 GPIO_InitStruct.Pull = GPIO_NOPULL;
993 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
994 GPIO_InitStruct.Alternate = GPIO_AF12_FSMC;
995 HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
996
997 /* USER CODE BEGIN FSMC_MspInit 1 */
998
999 /* USER CODE END FSMC_MspInit 1 */
1000 }
1001
HAL_SRAM_MspInit(SRAM_HandleTypeDef * hsram)1002 void HAL_SRAM_MspInit(SRAM_HandleTypeDef* hsram)
1003 {
1004 /* USER CODE BEGIN SRAM_MspInit 0 */
1005
1006 /* USER CODE END SRAM_MspInit 0 */
1007 HAL_FSMC_MspInit();
1008 /* USER CODE BEGIN SRAM_MspInit 1 */
1009
1010 /* USER CODE END SRAM_MspInit 1 */
1011 }
1012
1013 static uint32_t FSMC_DeInitialized = 0;
1014
HAL_FSMC_MspDeInit(void)1015 static void HAL_FSMC_MspDeInit(void)
1016 {
1017 /* USER CODE BEGIN FSMC_MspDeInit 0 */
1018
1019 /* USER CODE END FSMC_MspDeInit 0 */
1020 if (FSMC_DeInitialized)
1021 {
1022 return;
1023 }
1024 FSMC_DeInitialized = 1;
1025 /* Peripheral clock enable */
1026 __HAL_RCC_FSMC_CLK_DISABLE();
1027
1028 /** FSMC GPIO Configuration
1029 PF0 ------> FSMC_A0
1030 PF1 ------> FSMC_A1
1031 PF2 ------> FSMC_A2
1032 PF3 ------> FSMC_A3
1033 PF4 ------> FSMC_A4
1034 PF5 ------> FSMC_A5
1035 PF12 ------> FSMC_A6
1036 PF13 ------> FSMC_A7
1037 PF14 ------> FSMC_A8
1038 PF15 ------> FSMC_A9
1039 PG0 ------> FSMC_A10
1040 PG1 ------> FSMC_A11
1041 PE7 ------> FSMC_D4
1042 PE8 ------> FSMC_D5
1043 PE9 ------> FSMC_D6
1044 PE10 ------> FSMC_D7
1045 PE11 ------> FSMC_D8
1046 PE12 ------> FSMC_D9
1047 PE13 ------> FSMC_D10
1048 PE14 ------> FSMC_D11
1049 PE15 ------> FSMC_D12
1050 PD8 ------> FSMC_D13
1051 PD9 ------> FSMC_D14
1052 PD10 ------> FSMC_D15
1053 PD11 ------> FSMC_A16
1054 PD12 ------> FSMC_A17
1055 PD13 ------> FSMC_A18
1056 PD14 ------> FSMC_D0
1057 PD15 ------> FSMC_D1
1058 PG2 ------> FSMC_A12
1059 PG3 ------> FSMC_A13
1060 PG4 ------> FSMC_A14
1061 PG5 ------> FSMC_A15
1062 PD0 ------> FSMC_D2
1063 PD1 ------> FSMC_D3
1064 PD4 ------> FSMC_NOE
1065 PD5 ------> FSMC_NWE
1066 PG10 ------> FSMC_NE3
1067 PG12 ------> FSMC_NE4
1068 PE0 ------> FSMC_NBL0
1069 PE1 ------> FSMC_NBL1
1070 */
1071 HAL_GPIO_DeInit(GPIOF, GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3
1072 |GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_12|GPIO_PIN_13
1073 |GPIO_PIN_14|GPIO_PIN_15);
1074
1075 HAL_GPIO_DeInit(GPIOG, GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3
1076 |GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_10|GPIO_PIN_12);
1077
1078 HAL_GPIO_DeInit(GPIOE, GPIO_PIN_7|GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10
1079 |GPIO_PIN_11|GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14
1080 |GPIO_PIN_15|GPIO_PIN_0|GPIO_PIN_1);
1081
1082 HAL_GPIO_DeInit(GPIOD, GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_11
1083 |GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15
1084 |GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_4|GPIO_PIN_5);
1085
1086 /* USER CODE BEGIN FSMC_MspDeInit 1 */
1087
1088 /* USER CODE END FSMC_MspDeInit 1 */
1089 }
1090
HAL_SRAM_MspDeInit(SRAM_HandleTypeDef * hsram)1091 void HAL_SRAM_MspDeInit(SRAM_HandleTypeDef* hsram)
1092 {
1093 /* USER CODE BEGIN SRAM_MspDeInit 0 */
1094
1095 /* USER CODE END SRAM_MspDeInit 0 */
1096 HAL_FSMC_MspDeInit();
1097 /* USER CODE BEGIN SRAM_MspDeInit 1 */
1098
1099 /* USER CODE END SRAM_MspDeInit 1 */
1100 }
1101
1102 /* USER CODE BEGIN 1 */
1103
1104 /* USER CODE END 1 */
1105
1106 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
1107