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 #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 ADC MSP Initialization
104 * This function configures the hardware resources used in this example
105 * @param hadc: ADC handle pointer
106 * @retval None
107 */
HAL_ADC_MspInit(ADC_HandleTypeDef * hadc)108 void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc)
109 {
110 GPIO_InitTypeDef GPIO_InitStruct = {0};
111 if(hadc->Instance==ADC1)
112 {
113 /* USER CODE BEGIN ADC1_MspInit 0 */
114
115 /* USER CODE END ADC1_MspInit 0 */
116 /* Peripheral clock enable */
117 __HAL_RCC_ADC1_CLK_ENABLE();
118
119 __HAL_RCC_GPIOA_CLK_ENABLE();
120 /**ADC GPIO Configuration
121 PA0 ------> ADC_IN0
122 */
123 GPIO_InitStruct.Pin = GPIO_PIN_0;
124 GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
125 GPIO_InitStruct.Pull = GPIO_NOPULL;
126 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
127
128 /* USER CODE BEGIN ADC1_MspInit 1 */
129
130 /* USER CODE END ADC1_MspInit 1 */
131 }
132
133 }
134
135 /**
136 * @brief ADC MSP De-Initialization
137 * This function freeze the hardware resources used in this example
138 * @param hadc: ADC handle pointer
139 * @retval None
140 */
HAL_ADC_MspDeInit(ADC_HandleTypeDef * hadc)141 void HAL_ADC_MspDeInit(ADC_HandleTypeDef* hadc)
142 {
143 if(hadc->Instance==ADC1)
144 {
145 /* USER CODE BEGIN ADC1_MspDeInit 0 */
146
147 /* USER CODE END ADC1_MspDeInit 0 */
148 /* Peripheral clock disable */
149 __HAL_RCC_ADC1_CLK_DISABLE();
150
151 /**ADC GPIO Configuration
152 PA0 ------> ADC_IN0
153 */
154 HAL_GPIO_DeInit(GPIOA, GPIO_PIN_0);
155
156 /* USER CODE BEGIN ADC1_MspDeInit 1 */
157
158 /* USER CODE END ADC1_MspDeInit 1 */
159 }
160
161 }
162
163 /**
164 * @brief RTC MSP Initialization
165 * This function configures the hardware resources used in this example
166 * @param hrtc: RTC handle pointer
167 * @retval None
168 */
HAL_RTC_MspInit(RTC_HandleTypeDef * hrtc)169 void HAL_RTC_MspInit(RTC_HandleTypeDef* hrtc)
170 {
171 if(hrtc->Instance==RTC)
172 {
173 /* USER CODE BEGIN RTC_MspInit 0 */
174
175 /* USER CODE END RTC_MspInit 0 */
176 /* Peripheral clock enable */
177 __HAL_RCC_RTC_ENABLE();
178 /* USER CODE BEGIN RTC_MspInit 1 */
179
180 /* USER CODE END RTC_MspInit 1 */
181 }
182
183 }
184
185 /**
186 * @brief RTC MSP De-Initialization
187 * This function freeze the hardware resources used in this example
188 * @param hrtc: RTC handle pointer
189 * @retval None
190 */
HAL_RTC_MspDeInit(RTC_HandleTypeDef * hrtc)191 void HAL_RTC_MspDeInit(RTC_HandleTypeDef* hrtc)
192 {
193 if(hrtc->Instance==RTC)
194 {
195 /* USER CODE BEGIN RTC_MspDeInit 0 */
196
197 /* USER CODE END RTC_MspDeInit 0 */
198 /* Peripheral clock disable */
199 __HAL_RCC_RTC_DISABLE();
200 /* USER CODE BEGIN RTC_MspDeInit 1 */
201
202 /* USER CODE END RTC_MspDeInit 1 */
203 }
204
205 }
206
207 /**
208 * @brief SPI MSP Initialization
209 * This function configures the hardware resources used in this example
210 * @param hspi: SPI handle pointer
211 * @retval None
212 */
HAL_SPI_MspInit(SPI_HandleTypeDef * hspi)213 void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi)
214 {
215 GPIO_InitTypeDef GPIO_InitStruct = {0};
216 if(hspi->Instance==SPI1)
217 {
218 /* USER CODE BEGIN SPI1_MspInit 0 */
219
220 /* USER CODE END SPI1_MspInit 0 */
221 /* Peripheral clock enable */
222 __HAL_RCC_SPI1_CLK_ENABLE();
223
224 __HAL_RCC_GPIOA_CLK_ENABLE();
225 __HAL_RCC_GPIOB_CLK_ENABLE();
226 /**SPI1 GPIO Configuration
227 PA6 ------> SPI1_MISO
228 PA7 ------> SPI1_MOSI
229 PB3 ------> SPI1_SCK
230 */
231 GPIO_InitStruct.Pin = GPIO_PIN_6|GPIO_PIN_7;
232 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
233 GPIO_InitStruct.Pull = GPIO_NOPULL;
234 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
235 GPIO_InitStruct.Alternate = GPIO_AF0_SPI1;
236 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
237
238 GPIO_InitStruct.Pin = GPIO_PIN_3;
239 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
240 GPIO_InitStruct.Pull = GPIO_NOPULL;
241 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
242 GPIO_InitStruct.Alternate = GPIO_AF0_SPI1;
243 HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
244
245 /* USER CODE BEGIN SPI1_MspInit 1 */
246
247 /* USER CODE END SPI1_MspInit 1 */
248 }
249
250 }
251
252 /**
253 * @brief SPI MSP De-Initialization
254 * This function freeze the hardware resources used in this example
255 * @param hspi: SPI handle pointer
256 * @retval None
257 */
HAL_SPI_MspDeInit(SPI_HandleTypeDef * hspi)258 void HAL_SPI_MspDeInit(SPI_HandleTypeDef* hspi)
259 {
260 if(hspi->Instance==SPI1)
261 {
262 /* USER CODE BEGIN SPI1_MspDeInit 0 */
263
264 /* USER CODE END SPI1_MspDeInit 0 */
265 /* Peripheral clock disable */
266 __HAL_RCC_SPI1_CLK_DISABLE();
267
268 /**SPI1 GPIO Configuration
269 PA6 ------> SPI1_MISO
270 PA7 ------> SPI1_MOSI
271 PB3 ------> SPI1_SCK
272 */
273 HAL_GPIO_DeInit(GPIOA, GPIO_PIN_6|GPIO_PIN_7);
274
275 HAL_GPIO_DeInit(GPIOB, GPIO_PIN_3);
276
277 /* USER CODE BEGIN SPI1_MspDeInit 1 */
278
279 /* USER CODE END SPI1_MspDeInit 1 */
280 }
281
282 }
283
284 /**
285 * @brief TIM_Base MSP Initialization
286 * This function configures the hardware resources used in this example
287 * @param htim_base: TIM_Base handle pointer
288 * @retval None
289 */
HAL_TIM_Base_MspInit(TIM_HandleTypeDef * htim_base)290 void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* htim_base)
291 {
292 if(htim_base->Instance==TIM2)
293 {
294 /* USER CODE BEGIN TIM2_MspInit 0 */
295
296 /* USER CODE END TIM2_MspInit 0 */
297 /* Peripheral clock enable */
298 __HAL_RCC_TIM2_CLK_ENABLE();
299 /* USER CODE BEGIN TIM2_MspInit 1 */
300
301 /* USER CODE END TIM2_MspInit 1 */
302 }
303 else if(htim_base->Instance==TIM14)
304 {
305 /* USER CODE BEGIN TIM14_MspInit 0 */
306
307 /* USER CODE END TIM14_MspInit 0 */
308 /* Peripheral clock enable */
309 __HAL_RCC_TIM14_CLK_ENABLE();
310 /* USER CODE BEGIN TIM14_MspInit 1 */
311
312 /* USER CODE END TIM14_MspInit 1 */
313 }
314 else if(htim_base->Instance==TIM16)
315 {
316 /* USER CODE BEGIN TIM16_MspInit 0 */
317
318 /* USER CODE END TIM16_MspInit 0 */
319 /* Peripheral clock enable */
320 __HAL_RCC_TIM16_CLK_ENABLE();
321 /* USER CODE BEGIN TIM16_MspInit 1 */
322
323 /* USER CODE END TIM16_MspInit 1 */
324 }
325 else if(htim_base->Instance==TIM17)
326 {
327 /* USER CODE BEGIN TIM17_MspInit 0 */
328
329 /* USER CODE END TIM17_MspInit 0 */
330 /* Peripheral clock enable */
331 __HAL_RCC_TIM17_CLK_ENABLE();
332 /* USER CODE BEGIN TIM17_MspInit 1 */
333
334 /* USER CODE END TIM17_MspInit 1 */
335 }
336
337 }
338
HAL_TIM_MspPostInit(TIM_HandleTypeDef * htim)339 void HAL_TIM_MspPostInit(TIM_HandleTypeDef* htim)
340 {
341 GPIO_InitTypeDef GPIO_InitStruct = {0};
342 if(htim->Instance==TIM2)
343 {
344 /* USER CODE BEGIN TIM2_MspPostInit 0 */
345
346 /* USER CODE END TIM2_MspPostInit 0 */
347
348 __HAL_RCC_GPIOB_CLK_ENABLE();
349 /**TIM2 GPIO Configuration
350 PB11 ------> TIM2_CH4
351 */
352 GPIO_InitStruct.Pin = GPIO_PIN_11;
353 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
354 GPIO_InitStruct.Pull = GPIO_NOPULL;
355 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
356 GPIO_InitStruct.Alternate = GPIO_AF2_TIM2;
357 HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
358
359 /* USER CODE BEGIN TIM2_MspPostInit 1 */
360
361 /* USER CODE END TIM2_MspPostInit 1 */
362 }
363
364 }
365 /**
366 * @brief TIM_Base MSP De-Initialization
367 * This function freeze the hardware resources used in this example
368 * @param htim_base: TIM_Base handle pointer
369 * @retval None
370 */
HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef * htim_base)371 void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* htim_base)
372 {
373 if(htim_base->Instance==TIM2)
374 {
375 /* USER CODE BEGIN TIM2_MspDeInit 0 */
376
377 /* USER CODE END TIM2_MspDeInit 0 */
378 /* Peripheral clock disable */
379 __HAL_RCC_TIM2_CLK_DISABLE();
380 /* USER CODE BEGIN TIM2_MspDeInit 1 */
381
382 /* USER CODE END TIM2_MspDeInit 1 */
383 }
384 else if(htim_base->Instance==TIM14)
385 {
386 /* USER CODE BEGIN TIM14_MspDeInit 0 */
387
388 /* USER CODE END TIM14_MspDeInit 0 */
389 /* Peripheral clock disable */
390 __HAL_RCC_TIM14_CLK_DISABLE();
391 /* USER CODE BEGIN TIM14_MspDeInit 1 */
392
393 /* USER CODE END TIM14_MspDeInit 1 */
394 }
395 else if(htim_base->Instance==TIM16)
396 {
397 /* USER CODE BEGIN TIM16_MspDeInit 0 */
398
399 /* USER CODE END TIM16_MspDeInit 0 */
400 /* Peripheral clock disable */
401 __HAL_RCC_TIM16_CLK_DISABLE();
402 /* USER CODE BEGIN TIM16_MspDeInit 1 */
403
404 /* USER CODE END TIM16_MspDeInit 1 */
405 }
406 else if(htim_base->Instance==TIM17)
407 {
408 /* USER CODE BEGIN TIM17_MspDeInit 0 */
409
410 /* USER CODE END TIM17_MspDeInit 0 */
411 /* Peripheral clock disable */
412 __HAL_RCC_TIM17_CLK_DISABLE();
413 /* USER CODE BEGIN TIM17_MspDeInit 1 */
414
415 /* USER CODE END TIM17_MspDeInit 1 */
416 }
417
418 }
419
420 /**
421 * @brief UART MSP Initialization
422 * This function configures the hardware resources used in this example
423 * @param huart: UART handle pointer
424 * @retval None
425 */
HAL_UART_MspInit(UART_HandleTypeDef * huart)426 void HAL_UART_MspInit(UART_HandleTypeDef* huart)
427 {
428 GPIO_InitTypeDef GPIO_InitStruct = {0};
429 if(huart->Instance==USART1)
430 {
431 /* USER CODE BEGIN USART1_MspInit 0 */
432
433 /* USER CODE END USART1_MspInit 0 */
434 /* Peripheral clock enable */
435 __HAL_RCC_USART1_CLK_ENABLE();
436
437 __HAL_RCC_GPIOA_CLK_ENABLE();
438 /**USART1 GPIO Configuration
439 PA9 ------> USART1_TX
440 PA10 ------> USART1_RX
441 */
442 GPIO_InitStruct.Pin = GPIO_PIN_9|GPIO_PIN_10;
443 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
444 GPIO_InitStruct.Pull = GPIO_PULLUP;
445 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
446 GPIO_InitStruct.Alternate = GPIO_AF1_USART1;
447 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
448
449 /* USER CODE BEGIN USART1_MspInit 1 */
450
451 /* USER CODE END USART1_MspInit 1 */
452 }
453 else if(huart->Instance==USART2)
454 {
455 /* USER CODE BEGIN USART2_MspInit 0 */
456
457 /* USER CODE END USART2_MspInit 0 */
458 /* Peripheral clock enable */
459 __HAL_RCC_USART2_CLK_ENABLE();
460
461 __HAL_RCC_GPIOA_CLK_ENABLE();
462 /**USART2 GPIO Configuration
463 PA2 ------> USART2_TX
464 PA3 ------> USART2_RX
465 */
466 GPIO_InitStruct.Pin = GPIO_PIN_2|GPIO_PIN_3;
467 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
468 GPIO_InitStruct.Pull = GPIO_PULLUP;
469 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
470 GPIO_InitStruct.Alternate = GPIO_AF1_USART2;
471 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
472
473 /* USER CODE BEGIN USART2_MspInit 1 */
474
475 /* USER CODE END USART2_MspInit 1 */
476 }
477
478 }
479
480 /**
481 * @brief UART MSP De-Initialization
482 * This function freeze the hardware resources used in this example
483 * @param huart: UART handle pointer
484 * @retval None
485 */
HAL_UART_MspDeInit(UART_HandleTypeDef * huart)486 void HAL_UART_MspDeInit(UART_HandleTypeDef* huart)
487 {
488 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
525 }
526
527 /* USER CODE BEGIN 1 */
528
529 /* USER CODE END 1 */
530
531 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
532