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) 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_AFIO_CLK_ENABLE();
93   __HAL_RCC_PWR_CLK_ENABLE();
94 
95   /* System interrupt init*/
96 
97   /**NOJTAG: JTAG-DP Disabled and SW-DP Enabled
98   */
99   __HAL_AFIO_REMAP_SWJ_NOJTAG();
100 
101   /* USER CODE BEGIN MspInit 1 */
102 
103   /* USER CODE END MspInit 1 */
104 }
105 
106 /**
107 * @brief ADC MSP Initialization
108 * This function configures the hardware resources used in this example
109 * @param hadc: ADC handle pointer
110 * @retval None
111 */
HAL_ADC_MspInit(ADC_HandleTypeDef * hadc)112 void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc)
113 {
114 
115   GPIO_InitTypeDef GPIO_InitStruct = {0};
116   if(hadc->Instance==ADC1)
117   {
118   /* USER CODE BEGIN ADC1_MspInit 0 */
119 
120   /* USER CODE END ADC1_MspInit 0 */
121     /* Peripheral clock enable */
122     __HAL_RCC_ADC1_CLK_ENABLE();
123 
124     __HAL_RCC_GPIOB_CLK_ENABLE();
125     /**ADC1 GPIO Configuration
126     PB1     ------> ADC1_IN9
127     */
128     GPIO_InitStruct.Pin = GPIO_PIN_1;
129     GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
130     HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
131 
132   /* USER CODE BEGIN ADC1_MspInit 1 */
133 
134   /* USER CODE END ADC1_MspInit 1 */
135   }
136 
137 }
138 
139 /**
140 * @brief ADC MSP De-Initialization
141 * This function freeze the hardware resources used in this example
142 * @param hadc: ADC handle pointer
143 * @retval None
144 */
145 
HAL_ADC_MspDeInit(ADC_HandleTypeDef * hadc)146 void HAL_ADC_MspDeInit(ADC_HandleTypeDef* hadc)
147 {
148 
149   if(hadc->Instance==ADC1)
150   {
151   /* USER CODE BEGIN ADC1_MspDeInit 0 */
152 
153   /* USER CODE END ADC1_MspDeInit 0 */
154     /* Peripheral clock disable */
155     __HAL_RCC_ADC1_CLK_DISABLE();
156 
157     /**ADC1 GPIO Configuration
158     PB1     ------> ADC1_IN9
159     */
160     HAL_GPIO_DeInit(GPIOB, 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==SPI2)
230   {
231   /* USER CODE BEGIN SPI2_MspInit 0 */
232 
233   /* USER CODE END SPI2_MspInit 0 */
234     /* Peripheral clock enable */
235     __HAL_RCC_SPI2_CLK_ENABLE();
236 
237     __HAL_RCC_GPIOB_CLK_ENABLE();
238     /**SPI2 GPIO Configuration
239     PB13     ------> SPI2_SCK
240     PB14     ------> SPI2_MISO
241     PB15     ------> SPI2_MOSI
242     */
243     GPIO_InitStruct.Pin = GPIO_PIN_13|GPIO_PIN_15;
244     GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
245     GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
246     HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
247 
248     GPIO_InitStruct.Pin = GPIO_PIN_14;
249     GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
250     GPIO_InitStruct.Pull = GPIO_NOPULL;
251     HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
252 
253   /* USER CODE BEGIN SPI2_MspInit 1 */
254 
255   /* USER CODE END SPI2_MspInit 1 */
256   }
257 
258 }
259 
260 /**
261 * @brief SPI MSP De-Initialization
262 * This function freeze the hardware resources used in this example
263 * @param hspi: SPI handle pointer
264 * @retval None
265 */
266 
HAL_SPI_MspDeInit(SPI_HandleTypeDef * hspi)267 void HAL_SPI_MspDeInit(SPI_HandleTypeDef* hspi)
268 {
269 
270   if(hspi->Instance==SPI2)
271   {
272   /* USER CODE BEGIN SPI2_MspDeInit 0 */
273 
274   /* USER CODE END SPI2_MspDeInit 0 */
275     /* Peripheral clock disable */
276     __HAL_RCC_SPI2_CLK_DISABLE();
277 
278     /**SPI2 GPIO Configuration
279     PB13     ------> SPI2_SCK
280     PB14     ------> SPI2_MISO
281     PB15     ------> SPI2_MOSI
282     */
283     HAL_GPIO_DeInit(GPIOB, GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15);
284 
285   /* USER CODE BEGIN SPI2_MspDeInit 1 */
286 
287   /* USER CODE END SPI2_MspDeInit 1 */
288   }
289 
290 }
291 
292 /**
293 * @brief TIM_Base MSP Initialization
294 * This function configures the hardware resources used in this example
295 * @param htim_base: TIM_Base handle pointer
296 * @retval None
297 */
HAL_TIM_Base_MspInit(TIM_HandleTypeDef * htim_base)298 void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* htim_base)
299 {
300 
301   if(htim_base->Instance==TIM2)
302   {
303   /* USER CODE BEGIN TIM2_MspInit 0 */
304 
305   /* USER CODE END TIM2_MspInit 0 */
306     /* Peripheral clock enable */
307     __HAL_RCC_TIM2_CLK_ENABLE();
308   /* USER CODE BEGIN TIM2_MspInit 1 */
309 
310   /* USER CODE END TIM2_MspInit 1 */
311   }
312   else if(htim_base->Instance==TIM3)
313   {
314   /* USER CODE BEGIN TIM3_MspInit 0 */
315 
316   /* USER CODE END TIM3_MspInit 0 */
317     /* Peripheral clock enable */
318     __HAL_RCC_TIM3_CLK_ENABLE();
319   /* USER CODE BEGIN TIM3_MspInit 1 */
320 
321   /* USER CODE END TIM3_MspInit 1 */
322   }
323   else if(htim_base->Instance==TIM4)
324   {
325   /* USER CODE BEGIN TIM4_MspInit 0 */
326 
327   /* USER CODE END TIM4_MspInit 0 */
328     /* Peripheral clock enable */
329     __HAL_RCC_TIM4_CLK_ENABLE();
330   /* USER CODE BEGIN TIM4_MspInit 1 */
331 
332   /* USER CODE END TIM4_MspInit 1 */
333   }
334 
335 }
336 
HAL_TIM_MspPostInit(TIM_HandleTypeDef * htim)337 void HAL_TIM_MspPostInit(TIM_HandleTypeDef* htim)
338 {
339 
340   GPIO_InitTypeDef GPIO_InitStruct = {0};
341   if(htim->Instance==TIM3)
342   {
343   /* USER CODE BEGIN TIM3_MspPostInit 0 */
344 
345   /* USER CODE END TIM3_MspPostInit 0 */
346 
347     __HAL_RCC_GPIOC_CLK_ENABLE();
348     /**TIM3 GPIO Configuration
349     PC6     ------> TIM3_CH1
350     PC7     ------> TIM3_CH2
351     */
352     GPIO_InitStruct.Pin = GPIO_PIN_6|GPIO_PIN_7;
353     GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
354     GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
355     HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
356 
357     __HAL_AFIO_REMAP_TIM3_ENABLE();
358 
359   /* USER CODE BEGIN TIM3_MspPostInit 1 */
360 
361   /* USER CODE END TIM3_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 */
371 
HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef * htim_base)372 void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* htim_base)
373 {
374 
375   if(htim_base->Instance==TIM2)
376   {
377   /* USER CODE BEGIN TIM2_MspDeInit 0 */
378 
379   /* USER CODE END TIM2_MspDeInit 0 */
380     /* Peripheral clock disable */
381     __HAL_RCC_TIM2_CLK_DISABLE();
382   /* USER CODE BEGIN TIM2_MspDeInit 1 */
383 
384   /* USER CODE END TIM2_MspDeInit 1 */
385   }
386   else if(htim_base->Instance==TIM3)
387   {
388   /* USER CODE BEGIN TIM3_MspDeInit 0 */
389 
390   /* USER CODE END TIM3_MspDeInit 0 */
391     /* Peripheral clock disable */
392     __HAL_RCC_TIM3_CLK_DISABLE();
393   /* USER CODE BEGIN TIM3_MspDeInit 1 */
394 
395   /* USER CODE END TIM3_MspDeInit 1 */
396   }
397   else if(htim_base->Instance==TIM4)
398   {
399   /* USER CODE BEGIN TIM4_MspDeInit 0 */
400 
401   /* USER CODE END TIM4_MspDeInit 0 */
402     /* Peripheral clock disable */
403     __HAL_RCC_TIM4_CLK_DISABLE();
404   /* USER CODE BEGIN TIM4_MspDeInit 1 */
405 
406   /* USER CODE END TIM4_MspDeInit 1 */
407   }
408 
409 }
410 
411 /**
412 * @brief UART MSP Initialization
413 * This function configures the hardware resources used in this example
414 * @param huart: UART handle pointer
415 * @retval None
416 */
HAL_UART_MspInit(UART_HandleTypeDef * huart)417 void HAL_UART_MspInit(UART_HandleTypeDef* huart)
418 {
419 
420   GPIO_InitTypeDef GPIO_InitStruct = {0};
421   if(huart->Instance==USART1)
422   {
423   /* USER CODE BEGIN USART1_MspInit 0 */
424   /* USER CODE END USART1_MspInit 0 */
425     /* Peripheral clock enable */
426     __HAL_RCC_USART1_CLK_ENABLE();
427 
428     __HAL_RCC_GPIOA_CLK_ENABLE();
429     /**USART1 GPIO Configuration
430     PA9     ------> USART1_TX
431     PA10     ------> USART1_RX
432     */
433     GPIO_InitStruct.Pin = GPIO_PIN_9;
434     GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
435     GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
436     HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
437 
438     GPIO_InitStruct.Pin = GPIO_PIN_10;
439     GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
440     GPIO_InitStruct.Pull = GPIO_PULLUP;
441     HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
442 
443     /* USART1 interrupt Init */
444     HAL_NVIC_SetPriority(USART1_IRQn, 5, 0);
445     HAL_NVIC_EnableIRQ(USART1_IRQn);
446   /* USER CODE BEGIN USART1_MspInit 1 */
447   /* USER CODE END USART1_MspInit 1 */
448   }
449 
450 }
451 
452 /**
453 * @brief UART MSP De-Initialization
454 * This function freeze the hardware resources used in this example
455 * @param huart: UART handle pointer
456 * @retval None
457 */
458 
HAL_UART_MspDeInit(UART_HandleTypeDef * huart)459 void HAL_UART_MspDeInit(UART_HandleTypeDef* huart)
460 {
461 
462   if(huart->Instance==USART1)
463   {
464   /* USER CODE BEGIN USART1_MspDeInit 0 */
465   /* USER CODE END USART1_MspDeInit 0 */
466     /* Peripheral clock disable */
467     __HAL_RCC_USART1_CLK_DISABLE();
468 
469     /**USART1 GPIO Configuration
470     PA9     ------> USART1_TX
471     PA10     ------> USART1_RX
472     */
473     HAL_GPIO_DeInit(GPIOA, GPIO_PIN_9|GPIO_PIN_10);
474 
475     /* USART1 interrupt DeInit */
476     HAL_NVIC_DisableIRQ(USART1_IRQn);
477   /* USER CODE BEGIN USART1_MspDeInit 1 */
478   /* USER CODE END USART1_MspDeInit 1 */
479   }
480 
481 }
482 
483 /* USER CODE BEGIN 1 */
484 
485 /* USER CODE END 1 */
486 
487 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
488