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 International N.V.
15   * All rights reserved.
16   *
17   * Redistribution and use in source and binary forms, with or without
18   * modification, are permitted, provided that the following conditions are met:
19   *
20   * 1. Redistribution of source code must retain the above copyright notice,
21   *    this list of conditions and the following disclaimer.
22   * 2. Redistributions in binary form must reproduce the above copyright notice,
23   *    this list of conditions and the following disclaimer in the documentation
24   *    and/or other materials provided with the distribution.
25   * 3. Neither the name of STMicroelectronics nor the names of other
26   *    contributors to this software may be used to endorse or promote products
27   *    derived from this software without specific written permission.
28   * 4. This software, including modifications and/or derivative works of this
29   *    software, must execute solely and exclusively on microcontroller or
30   *    microprocessor devices manufactured by or for STMicroelectronics.
31   * 5. Redistribution and use of this software other than as permitted under
32   *    this license is void and will automatically terminate your rights under
33   *    this license.
34   *
35   * THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS"
36   * AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT
37   * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
38   * PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY
39   * RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT
40   * SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
41   * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
42   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
43   * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
44   * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
45   * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
46   * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
47   *
48   ******************************************************************************
49   */
50 /* USER CODE END Header */
51 
52 /* Includes ------------------------------------------------------------------*/
53 #include "main.h"
54 /* USER CODE BEGIN Includes */
55 #include <drv_common.h>
56 /* USER CODE END Includes */
57 
58 /* Private typedef -----------------------------------------------------------*/
59 /* USER CODE BEGIN TD */
60 
61 /* USER CODE END TD */
62 
63 /* Private define ------------------------------------------------------------*/
64 /* USER CODE BEGIN Define */
65 
66 /* USER CODE END Define */
67 
68 /* Private macro -------------------------------------------------------------*/
69 /* USER CODE BEGIN Macro */
70 
71 /* USER CODE END Macro */
72 
73 /* Private variables ---------------------------------------------------------*/
74 /* USER CODE BEGIN PV */
75 
76 /* USER CODE END PV */
77 
78 /* Private function prototypes -----------------------------------------------*/
79 /* USER CODE BEGIN PFP */
80 
81 /* USER CODE END PFP */
82 
83 /* External functions --------------------------------------------------------*/
84 /* USER CODE BEGIN ExternalFunctions */
85 
86 /* USER CODE END ExternalFunctions */
87 
88 /* USER CODE BEGIN 0 */
89 
90 /* USER CODE END 0 */
91 /**
92   * Initializes the Global MSP.
93   */
HAL_MspInit(void)94 void HAL_MspInit(void)
95 {
96   /* USER CODE BEGIN MspInit 0 */
97 
98   /* USER CODE END MspInit 0 */
99 
100   __HAL_RCC_SYSCFG_CLK_ENABLE();
101   __HAL_RCC_PWR_CLK_ENABLE();
102 
103   HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_0);
104 
105   /* System interrupt init*/
106 
107   /* USER CODE BEGIN MspInit 1 */
108 
109   /* USER CODE END MspInit 1 */
110 }
111 
112 /**
113 * @brief SPI MSP Initialization
114 * This function configures the hardware resources used in this example
115 * @param hspi: SPI handle pointer
116 * @retval None
117 */
HAL_SPI_MspInit(SPI_HandleTypeDef * hspi)118 void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi)
119 {
120   GPIO_InitTypeDef GPIO_InitStruct = {0};
121   if(hspi->Instance==SPI1)
122   {
123   /* USER CODE BEGIN SPI1_MspInit 0 */
124 
125   /* USER CODE END SPI1_MspInit 0 */
126     /* Peripheral clock enable */
127     __HAL_RCC_SPI1_CLK_ENABLE();
128 
129     __HAL_RCC_GPIOA_CLK_ENABLE();
130     /**SPI1 GPIO Configuration
131     PA5     ------> SPI1_SCK
132     PA6     ------> SPI1_MISO
133     PA7     ------> SPI1_MOSI
134     */
135     GPIO_InitStruct.Pin = SPI1_SCK_Pin|SPI1_MISO_Pin|SPI1_MOSI_Pin;
136     GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
137     GPIO_InitStruct.Pull = GPIO_NOPULL;
138     GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
139     GPIO_InitStruct.Alternate = GPIO_AF5_SPI1;
140     HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
141 
142   /* USER CODE BEGIN SPI1_MspInit 1 */
143 
144   /* USER CODE END SPI1_MspInit 1 */
145   }
146 
147 }
148 
149 /**
150 * @brief SPI MSP De-Initialization
151 * This function freeze the hardware resources used in this example
152 * @param hspi: SPI handle pointer
153 * @retval None
154 */
HAL_SPI_MspDeInit(SPI_HandleTypeDef * hspi)155 void HAL_SPI_MspDeInit(SPI_HandleTypeDef* hspi)
156 {
157   if(hspi->Instance==SPI1)
158   {
159   /* USER CODE BEGIN SPI1_MspDeInit 0 */
160 
161   /* USER CODE END SPI1_MspDeInit 0 */
162     /* Peripheral clock disable */
163     __HAL_RCC_SPI1_CLK_DISABLE();
164 
165     /**SPI1 GPIO Configuration
166     PA5     ------> SPI1_SCK
167     PA6     ------> SPI1_MISO
168     PA7     ------> SPI1_MOSI
169     */
170     HAL_GPIO_DeInit(GPIOA, SPI1_SCK_Pin|SPI1_MISO_Pin|SPI1_MOSI_Pin);
171 
172   /* USER CODE BEGIN SPI1_MspDeInit 1 */
173 
174   /* USER CODE END SPI1_MspDeInit 1 */
175   }
176 
177 }
178 
179 /**
180 * @brief UART MSP Initialization
181 * This function configures the hardware resources used in this example
182 * @param huart: UART handle pointer
183 * @retval None
184 */
HAL_UART_MspInit(UART_HandleTypeDef * huart)185 void HAL_UART_MspInit(UART_HandleTypeDef* huart)
186 {
187   GPIO_InitTypeDef GPIO_InitStruct = {0};
188   if(huart->Instance==USART1)
189   {
190   /* USER CODE BEGIN USART1_MspInit 0 */
191 
192   /* USER CODE END USART1_MspInit 0 */
193     /* Peripheral clock enable */
194     __HAL_RCC_USART1_CLK_ENABLE();
195 
196     __HAL_RCC_GPIOB_CLK_ENABLE();
197     /**USART1 GPIO Configuration
198     PB6     ------> USART1_TX
199     PB7     ------> USART1_RX
200     */
201     GPIO_InitStruct.Pin = GPIO_PIN_6|GPIO_PIN_7;
202     GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
203     GPIO_InitStruct.Pull = GPIO_PULLUP;
204     GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
205     GPIO_InitStruct.Alternate = GPIO_AF7_USART1;
206     HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
207 
208   /* USER CODE BEGIN USART1_MspInit 1 */
209 
210   /* USER CODE END USART1_MspInit 1 */
211   }
212 
213 }
214 
215 /**
216 * @brief UART MSP De-Initialization
217 * This function freeze the hardware resources used in this example
218 * @param huart: UART handle pointer
219 * @retval None
220 */
HAL_UART_MspDeInit(UART_HandleTypeDef * huart)221 void HAL_UART_MspDeInit(UART_HandleTypeDef* huart)
222 {
223   if(huart->Instance==USART1)
224   {
225   /* USER CODE BEGIN USART1_MspDeInit 0 */
226 
227   /* USER CODE END USART1_MspDeInit 0 */
228     /* Peripheral clock disable */
229     __HAL_RCC_USART1_CLK_DISABLE();
230 
231     /**USART1 GPIO Configuration
232     PB6     ------> USART1_TX
233     PB7     ------> USART1_RX
234     */
235     HAL_GPIO_DeInit(GPIOB, GPIO_PIN_6|GPIO_PIN_7);
236 
237   /* USER CODE BEGIN USART1_MspDeInit 1 */
238 
239   /* USER CODE END USART1_MspDeInit 1 */
240   }
241 
242 }
243 
244 /* USER CODE BEGIN 1 */
245 
246 /* USER CODE END 1 */
247 
248 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
249