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   * 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_SYSCFG_CLK_ENABLE();
91   __HAL_RCC_PWR_CLK_ENABLE();
92 
93   /* System interrupt init*/
94 
95   /* USER CODE BEGIN MspInit 1 */
96 
97   /* USER CODE END MspInit 1 */
98 }
99 
100 /**
101 * @brief ADC MSP Initialization
102 * This function configures the hardware resources used in this example
103 * @param hadc: ADC handle pointer
104 * @retval None
105 */
HAL_ADC_MspInit(ADC_HandleTypeDef * hadc)106 void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc)
107 {
108 
109   GPIO_InitTypeDef GPIO_InitStruct = {0};
110   if(hadc->Instance==ADC1)
111   {
112   /* USER CODE BEGIN ADC1_MspInit 0 */
113 
114   /* USER CODE END ADC1_MspInit 0 */
115     /* Peripheral clock enable */
116     __HAL_RCC_ADC1_CLK_ENABLE();
117 
118     __HAL_RCC_GPIOB_CLK_ENABLE();
119     /**ADC1 GPIO Configuration
120     PB1     ------> ADC1_IN9
121     */
122     GPIO_InitStruct.Pin = GPIO_PIN_1;
123     GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
124     GPIO_InitStruct.Pull = GPIO_NOPULL;
125     HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
126 
127   /* USER CODE BEGIN ADC1_MspInit 1 */
128 
129   /* USER CODE END ADC1_MspInit 1 */
130   }
131 
132 }
133 
134 /**
135 * @brief ADC MSP De-Initialization
136 * This function freeze the hardware resources used in this example
137 * @param hadc: ADC handle pointer
138 * @retval None
139 */
140 
HAL_ADC_MspDeInit(ADC_HandleTypeDef * hadc)141 void HAL_ADC_MspDeInit(ADC_HandleTypeDef* hadc)
142 {
143 
144   if(hadc->Instance==ADC1)
145   {
146   /* USER CODE BEGIN ADC1_MspDeInit 0 */
147 
148   /* USER CODE END ADC1_MspDeInit 0 */
149     /* Peripheral clock disable */
150     __HAL_RCC_ADC1_CLK_DISABLE();
151 
152     /**ADC1 GPIO Configuration
153     PB1     ------> ADC1_IN9
154     */
155     HAL_GPIO_DeInit(GPIOB, GPIO_PIN_1);
156 
157   /* USER CODE BEGIN ADC1_MspDeInit 1 */
158 
159   /* USER CODE END ADC1_MspDeInit 1 */
160   }
161 
162 }
163 
164 /**
165 * @brief I2C MSP Initialization
166 * This function configures the hardware resources used in this example
167 * @param hi2c: I2C handle pointer
168 * @retval None
169 */
HAL_I2C_MspInit(I2C_HandleTypeDef * hi2c)170 void HAL_I2C_MspInit(I2C_HandleTypeDef* hi2c)
171 {
172 
173   GPIO_InitTypeDef GPIO_InitStruct = {0};
174   if(hi2c->Instance==I2C1)
175   {
176   /* USER CODE BEGIN I2C1_MspInit 0 */
177 
178   /* USER CODE END I2C1_MspInit 0 */
179 
180     __HAL_RCC_GPIOB_CLK_ENABLE();
181     /**I2C1 GPIO Configuration
182     PB6     ------> I2C1_SCL
183     PB7     ------> I2C1_SDA
184     */
185     GPIO_InitStruct.Pin = GPIO_PIN_6|GPIO_PIN_7;
186     GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
187     GPIO_InitStruct.Pull = GPIO_PULLUP;
188     GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
189     GPIO_InitStruct.Alternate = GPIO_AF4_I2C1;
190     HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
191 
192     /* Peripheral clock enable */
193     __HAL_RCC_I2C1_CLK_ENABLE();
194   /* USER CODE BEGIN I2C1_MspInit 1 */
195 
196   /* USER CODE END I2C1_MspInit 1 */
197   }
198 
199 }
200 
201 /**
202 * @brief I2C MSP De-Initialization
203 * This function freeze the hardware resources used in this example
204 * @param hi2c: I2C handle pointer
205 * @retval None
206 */
207 
HAL_I2C_MspDeInit(I2C_HandleTypeDef * hi2c)208 void HAL_I2C_MspDeInit(I2C_HandleTypeDef* hi2c)
209 {
210 
211   if(hi2c->Instance==I2C1)
212   {
213   /* USER CODE BEGIN I2C1_MspDeInit 0 */
214 
215   /* USER CODE END I2C1_MspDeInit 0 */
216     /* Peripheral clock disable */
217     __HAL_RCC_I2C1_CLK_DISABLE();
218 
219     /**I2C1 GPIO Configuration
220     PB6     ------> I2C1_SCL
221     PB7     ------> I2C1_SDA
222     */
223     HAL_GPIO_DeInit(GPIOB, GPIO_PIN_6|GPIO_PIN_7);
224 
225   /* USER CODE BEGIN I2C1_MspDeInit 1 */
226 
227   /* USER CODE END I2C1_MspDeInit 1 */
228   }
229 
230 }
231 
232 /**
233 * @brief RTC MSP Initialization
234 * This function configures the hardware resources used in this example
235 * @param hrtc: RTC handle pointer
236 * @retval None
237 */
HAL_RTC_MspInit(RTC_HandleTypeDef * hrtc)238 void HAL_RTC_MspInit(RTC_HandleTypeDef* hrtc)
239 {
240 
241   if(hrtc->Instance==RTC)
242   {
243   /* USER CODE BEGIN RTC_MspInit 0 */
244 
245   /* USER CODE END RTC_MspInit 0 */
246     /* Peripheral clock enable */
247     __HAL_RCC_RTC_ENABLE();
248   /* USER CODE BEGIN RTC_MspInit 1 */
249 
250   /* USER CODE END RTC_MspInit 1 */
251   }
252 
253 }
254 
255 /**
256 * @brief RTC MSP De-Initialization
257 * This function freeze the hardware resources used in this example
258 * @param hrtc: RTC handle pointer
259 * @retval None
260 */
261 
HAL_RTC_MspDeInit(RTC_HandleTypeDef * hrtc)262 void HAL_RTC_MspDeInit(RTC_HandleTypeDef* hrtc)
263 {
264 
265   if(hrtc->Instance==RTC)
266   {
267   /* USER CODE BEGIN RTC_MspDeInit 0 */
268 
269   /* USER CODE END RTC_MspDeInit 0 */
270     /* Peripheral clock disable */
271     __HAL_RCC_RTC_DISABLE();
272   /* USER CODE BEGIN RTC_MspDeInit 1 */
273 
274   /* USER CODE END RTC_MspDeInit 1 */
275   }
276 
277 }
278 
279 /**
280 * @brief SPI MSP Initialization
281 * This function configures the hardware resources used in this example
282 * @param hspi: SPI handle pointer
283 * @retval None
284 */
HAL_SPI_MspInit(SPI_HandleTypeDef * hspi)285 void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi)
286 {
287 
288   GPIO_InitTypeDef GPIO_InitStruct = {0};
289   if(hspi->Instance==SPI2)
290   {
291   /* USER CODE BEGIN SPI2_MspInit 0 */
292 
293   /* USER CODE END SPI2_MspInit 0 */
294     /* Peripheral clock enable */
295     __HAL_RCC_SPI2_CLK_ENABLE();
296 
297     __HAL_RCC_GPIOB_CLK_ENABLE();
298     /**SPI2 GPIO Configuration
299     PB13     ------> SPI2_SCK
300     PB14     ------> SPI2_MISO
301     PB15     ------> SPI2_MOSI
302     */
303     GPIO_InitStruct.Pin = GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15;
304     GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
305     GPIO_InitStruct.Pull = GPIO_NOPULL;
306     GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
307     GPIO_InitStruct.Alternate = GPIO_AF5_SPI2;
308     HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
309 
310   /* USER CODE BEGIN SPI2_MspInit 1 */
311 
312   /* USER CODE END SPI2_MspInit 1 */
313   }
314 
315 }
316 
317 /**
318 * @brief SPI MSP De-Initialization
319 * This function freeze the hardware resources used in this example
320 * @param hspi: SPI handle pointer
321 * @retval None
322 */
323 
HAL_SPI_MspDeInit(SPI_HandleTypeDef * hspi)324 void HAL_SPI_MspDeInit(SPI_HandleTypeDef* hspi)
325 {
326 
327   if(hspi->Instance==SPI2)
328   {
329   /* USER CODE BEGIN SPI2_MspDeInit 0 */
330 
331   /* USER CODE END SPI2_MspDeInit 0 */
332     /* Peripheral clock disable */
333     __HAL_RCC_SPI2_CLK_DISABLE();
334 
335     /**SPI2 GPIO Configuration
336     PB13     ------> SPI2_SCK
337     PB14     ------> SPI2_MISO
338     PB15     ------> SPI2_MOSI
339     */
340     HAL_GPIO_DeInit(GPIOB, GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15);
341 
342   /* USER CODE BEGIN SPI2_MspDeInit 1 */
343 
344   /* USER CODE END SPI2_MspDeInit 1 */
345   }
346 
347 }
348 
349 /**
350 * @brief UART MSP Initialization
351 * This function configures the hardware resources used in this example
352 * @param huart: UART handle pointer
353 * @retval None
354 */
HAL_UART_MspInit(UART_HandleTypeDef * huart)355 void HAL_UART_MspInit(UART_HandleTypeDef* huart)
356 {
357 
358   GPIO_InitTypeDef GPIO_InitStruct = {0};
359   if(huart->Instance==USART1)
360   {
361   /* USER CODE BEGIN USART1_MspInit 0 */
362 
363   /* USER CODE END USART1_MspInit 0 */
364     /* Peripheral clock enable */
365     __HAL_RCC_USART1_CLK_ENABLE();
366 
367     __HAL_RCC_GPIOA_CLK_ENABLE();
368     /**USART1 GPIO Configuration
369     PA9     ------> USART1_TX
370     PA10     ------> USART1_RX
371     */
372     GPIO_InitStruct.Pin = GPIO_PIN_9|GPIO_PIN_10;
373     GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
374     GPIO_InitStruct.Pull = GPIO_PULLUP;
375     GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
376     GPIO_InitStruct.Alternate = GPIO_AF7_USART1;
377     HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
378 
379   /* USER CODE BEGIN USART1_MspInit 1 */
380 
381   /* USER CODE END USART1_MspInit 1 */
382   }
383   else if(huart->Instance==USART2)
384   {
385   /* USER CODE BEGIN USART2_MspInit 0 */
386 
387   /* USER CODE END USART2_MspInit 0 */
388     /* Peripheral clock enable */
389     __HAL_RCC_USART2_CLK_ENABLE();
390 
391     __HAL_RCC_GPIOA_CLK_ENABLE();
392     /**USART2 GPIO Configuration
393     PA2     ------> USART2_TX
394     PA3     ------> USART2_RX
395     */
396     GPIO_InitStruct.Pin = GPIO_PIN_2|GPIO_PIN_3;
397     GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
398     GPIO_InitStruct.Pull = GPIO_PULLUP;
399     GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
400     GPIO_InitStruct.Alternate = GPIO_AF7_USART2;
401     HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
402 
403   /* USER CODE BEGIN USART2_MspInit 1 */
404 
405   /* USER CODE END USART2_MspInit 1 */
406   }
407 
408 }
409 
410 /**
411 * @brief UART MSP De-Initialization
412 * This function freeze the hardware resources used in this example
413 * @param huart: UART handle pointer
414 * @retval None
415 */
416 
HAL_UART_MspDeInit(UART_HandleTypeDef * huart)417 void HAL_UART_MspDeInit(UART_HandleTypeDef* huart)
418 {
419 
420   if(huart->Instance==USART1)
421   {
422   /* USER CODE BEGIN USART1_MspDeInit 0 */
423 
424   /* USER CODE END USART1_MspDeInit 0 */
425     /* Peripheral clock disable */
426     __HAL_RCC_USART1_CLK_DISABLE();
427 
428     /**USART1 GPIO Configuration
429     PA9     ------> USART1_TX
430     PA10     ------> USART1_RX
431     */
432     HAL_GPIO_DeInit(GPIOA, GPIO_PIN_9|GPIO_PIN_10);
433 
434   /* USER CODE BEGIN USART1_MspDeInit 1 */
435 
436   /* USER CODE END USART1_MspDeInit 1 */
437   }
438   else if(huart->Instance==USART2)
439   {
440   /* USER CODE BEGIN USART2_MspDeInit 0 */
441 
442   /* USER CODE END USART2_MspDeInit 0 */
443     /* Peripheral clock disable */
444     __HAL_RCC_USART2_CLK_DISABLE();
445 
446     /**USART2 GPIO Configuration
447     PA2     ------> USART2_TX
448     PA3     ------> USART2_RX
449     */
450     HAL_GPIO_DeInit(GPIOA, GPIO_PIN_2|GPIO_PIN_3);
451 
452   /* USER CODE BEGIN USART2_MspDeInit 1 */
453 
454   /* USER CODE END USART2_MspDeInit 1 */
455   }
456 
457 }
458 
459 /* USER CODE BEGIN 1 */
460 
461 /* USER CODE END 1 */
462 
463 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
464