1 /* USER CODE BEGIN Header */
2 /**
3 ******************************************************************************
4 * File Name : stm32f7xx_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_PWR_CLK_ENABLE();
91 __HAL_RCC_SYSCFG_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 ETH MSP Initialization
102 * This function configures the hardware resources used in this example
103 * @param heth: ETH handle pointer
104 * @retval None
105 */
HAL_ETH_MspInit(ETH_HandleTypeDef * heth)106 void HAL_ETH_MspInit(ETH_HandleTypeDef* heth)
107 {
108
109 GPIO_InitTypeDef GPIO_InitStruct = {0};
110 if(heth->Instance==ETH)
111 {
112 /* USER CODE BEGIN ETH_MspInit 0 */
113
114 /* USER CODE END ETH_MspInit 0 */
115 /* Peripheral clock enable */
116 __HAL_RCC_ETH_CLK_ENABLE();
117
118 __HAL_RCC_GPIOC_CLK_ENABLE();
119 __HAL_RCC_GPIOA_CLK_ENABLE();
120 __HAL_RCC_GPIOB_CLK_ENABLE();
121 __HAL_RCC_GPIOG_CLK_ENABLE();
122 /**ETH GPIO Configuration
123 PC1 ------> ETH_MDC
124 PA1 ------> ETH_REF_CLK
125 PA2 ------> ETH_MDIO
126 PA7 ------> ETH_CRS_DV
127 PC4 ------> ETH_RXD0
128 PC5 ------> ETH_RXD1
129 PB13 ------> ETH_TXD1
130 PG11 ------> ETH_TX_EN
131 PG13 ------> ETH_TXD0
132 */
133 GPIO_InitStruct.Pin = RMII_MDC_Pin|RMII_RXD0_Pin|RMII_RXD1_Pin;
134 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
135 GPIO_InitStruct.Pull = GPIO_NOPULL;
136 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
137 GPIO_InitStruct.Alternate = GPIO_AF11_ETH;
138 HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
139
140 GPIO_InitStruct.Pin = RMII_REF_CLK_Pin|RMII_MDIO_Pin|RMII_CRS_DV_Pin;
141 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
142 GPIO_InitStruct.Pull = GPIO_NOPULL;
143 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
144 GPIO_InitStruct.Alternate = GPIO_AF11_ETH;
145 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
146
147 GPIO_InitStruct.Pin = RMII_TXD1_Pin;
148 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
149 GPIO_InitStruct.Pull = GPIO_NOPULL;
150 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
151 GPIO_InitStruct.Alternate = GPIO_AF11_ETH;
152 HAL_GPIO_Init(RMII_TXD1_GPIO_Port, &GPIO_InitStruct);
153
154 GPIO_InitStruct.Pin = RMII_TX_EN_Pin|RMII_TXD0_Pin;
155 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
156 GPIO_InitStruct.Pull = GPIO_NOPULL;
157 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
158 GPIO_InitStruct.Alternate = GPIO_AF11_ETH;
159 HAL_GPIO_Init(GPIOG, &GPIO_InitStruct);
160
161 /* USER CODE BEGIN ETH_MspInit 1 */
162
163 /* USER CODE END ETH_MspInit 1 */
164 }
165
166 }
167
168 /**
169 * @brief ETH MSP De-Initialization
170 * This function freeze the hardware resources used in this example
171 * @param heth: ETH handle pointer
172 * @retval None
173 */
174
HAL_ETH_MspDeInit(ETH_HandleTypeDef * heth)175 void HAL_ETH_MspDeInit(ETH_HandleTypeDef* heth)
176 {
177
178 if(heth->Instance==ETH)
179 {
180 /* USER CODE BEGIN ETH_MspDeInit 0 */
181
182 /* USER CODE END ETH_MspDeInit 0 */
183 /* Peripheral clock disable */
184 __HAL_RCC_ETH_CLK_DISABLE();
185
186 /**ETH GPIO Configuration
187 PC1 ------> ETH_MDC
188 PA1 ------> ETH_REF_CLK
189 PA2 ------> ETH_MDIO
190 PA7 ------> ETH_CRS_DV
191 PC4 ------> ETH_RXD0
192 PC5 ------> ETH_RXD1
193 PB13 ------> ETH_TXD1
194 PG11 ------> ETH_TX_EN
195 PG13 ------> ETH_TXD0
196 */
197 HAL_GPIO_DeInit(GPIOC, RMII_MDC_Pin|RMII_RXD0_Pin|RMII_RXD1_Pin);
198
199 HAL_GPIO_DeInit(GPIOA, RMII_REF_CLK_Pin|RMII_MDIO_Pin|RMII_CRS_DV_Pin);
200
201 HAL_GPIO_DeInit(RMII_TXD1_GPIO_Port, RMII_TXD1_Pin);
202
203 HAL_GPIO_DeInit(GPIOG, RMII_TX_EN_Pin|RMII_TXD0_Pin);
204
205 /* USER CODE BEGIN ETH_MspDeInit 1 */
206
207 /* USER CODE END ETH_MspDeInit 1 */
208 }
209
210 }
211
212 /**
213 * @brief UART MSP Initialization
214 * This function configures the hardware resources used in this example
215 * @param huart: UART handle pointer
216 * @retval None
217 */
HAL_UART_MspInit(UART_HandleTypeDef * huart)218 void HAL_UART_MspInit(UART_HandleTypeDef* huart)
219 {
220
221 GPIO_InitTypeDef GPIO_InitStruct = {0};
222 if(huart->Instance==USART3)
223 {
224 /* USER CODE BEGIN USART3_MspInit 0 */
225
226 /* USER CODE END USART3_MspInit 0 */
227 /* Peripheral clock enable */
228 __HAL_RCC_USART3_CLK_ENABLE();
229
230 __HAL_RCC_GPIOD_CLK_ENABLE();
231 /**USART3 GPIO Configuration
232 PD8 ------> USART3_TX
233 PD9 ------> USART3_RX
234 */
235 GPIO_InitStruct.Pin = STLK_RX_Pin|STLK_TX_Pin;
236 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
237 GPIO_InitStruct.Pull = GPIO_PULLUP;
238 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
239 GPIO_InitStruct.Alternate = GPIO_AF7_USART3;
240 HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
241
242 /* USER CODE BEGIN USART3_MspInit 1 */
243
244 /* USER CODE END USART3_MspInit 1 */
245 }
246
247 }
248
249 /**
250 * @brief UART MSP De-Initialization
251 * This function freeze the hardware resources used in this example
252 * @param huart: UART handle pointer
253 * @retval None
254 */
255
HAL_UART_MspDeInit(UART_HandleTypeDef * huart)256 void HAL_UART_MspDeInit(UART_HandleTypeDef* huart)
257 {
258
259 if(huart->Instance==USART3)
260 {
261 /* USER CODE BEGIN USART3_MspDeInit 0 */
262
263 /* USER CODE END USART3_MspDeInit 0 */
264 /* Peripheral clock disable */
265 __HAL_RCC_USART3_CLK_DISABLE();
266
267 /**USART3 GPIO Configuration
268 PD8 ------> USART3_TX
269 PD9 ------> USART3_RX
270 */
271 HAL_GPIO_DeInit(GPIOD, STLK_RX_Pin|STLK_TX_Pin);
272
273 /* USER CODE BEGIN USART3_MspDeInit 1 */
274
275 /* USER CODE END USART3_MspDeInit 1 */
276 }
277
278 }
279
280 /**
281 * @brief PCD MSP Initialization
282 * This function configures the hardware resources used in this example
283 * @param hpcd: PCD handle pointer
284 * @retval None
285 */
HAL_PCD_MspInit(PCD_HandleTypeDef * hpcd)286 void HAL_PCD_MspInit(PCD_HandleTypeDef* hpcd)
287 {
288
289 GPIO_InitTypeDef GPIO_InitStruct = {0};
290 if(hpcd->Instance==USB_OTG_FS)
291 {
292 /* USER CODE BEGIN USB_OTG_FS_MspInit 0 */
293
294 /* USER CODE END USB_OTG_FS_MspInit 0 */
295
296 __HAL_RCC_GPIOA_CLK_ENABLE();
297 /**USB_OTG_FS GPIO Configuration
298 PA8 ------> USB_OTG_FS_SOF
299 PA9 ------> USB_OTG_FS_VBUS
300 PA10 ------> USB_OTG_FS_ID
301 PA11 ------> USB_OTG_FS_DM
302 PA12 ------> USB_OTG_FS_DP
303 */
304 GPIO_InitStruct.Pin = USB_SOF_Pin|USB_ID_Pin|USB_DM_Pin|USB_DP_Pin;
305 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
306 GPIO_InitStruct.Pull = GPIO_NOPULL;
307 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
308 GPIO_InitStruct.Alternate = GPIO_AF10_OTG_FS;
309 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
310
311 GPIO_InitStruct.Pin = USB_VBUS_Pin;
312 GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
313 GPIO_InitStruct.Pull = GPIO_NOPULL;
314 HAL_GPIO_Init(USB_VBUS_GPIO_Port, &GPIO_InitStruct);
315
316 /* Peripheral clock enable */
317 __HAL_RCC_USB_OTG_FS_CLK_ENABLE();
318 /* USER CODE BEGIN USB_OTG_FS_MspInit 1 */
319
320 /* USER CODE END USB_OTG_FS_MspInit 1 */
321 }
322
323 }
324
325 /**
326 * @brief PCD MSP De-Initialization
327 * This function freeze the hardware resources used in this example
328 * @param hpcd: PCD handle pointer
329 * @retval None
330 */
331
HAL_PCD_MspDeInit(PCD_HandleTypeDef * hpcd)332 void HAL_PCD_MspDeInit(PCD_HandleTypeDef* hpcd)
333 {
334
335 if(hpcd->Instance==USB_OTG_FS)
336 {
337 /* USER CODE BEGIN USB_OTG_FS_MspDeInit 0 */
338
339 /* USER CODE END USB_OTG_FS_MspDeInit 0 */
340 /* Peripheral clock disable */
341 __HAL_RCC_USB_OTG_FS_CLK_DISABLE();
342
343 /**USB_OTG_FS GPIO Configuration
344 PA8 ------> USB_OTG_FS_SOF
345 PA9 ------> USB_OTG_FS_VBUS
346 PA10 ------> USB_OTG_FS_ID
347 PA11 ------> USB_OTG_FS_DM
348 PA12 ------> USB_OTG_FS_DP
349 */
350 HAL_GPIO_DeInit(GPIOA, USB_SOF_Pin|USB_VBUS_Pin|USB_ID_Pin|USB_DM_Pin
351 |USB_DP_Pin);
352
353 /* USER CODE BEGIN USB_OTG_FS_MspDeInit 1 */
354
355 /* USER CODE END USB_OTG_FS_MspDeInit 1 */
356 }
357
358 }
359
360 /* USER CODE BEGIN 1 */
361
362 /* USER CODE END 1 */
363
364 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
365