Rev 21 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2 | mjames | 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 | * @attention |
||
9 | * |
||
10 | * <h2><center>© Copyright (c) 2020 STMicroelectronics. |
||
11 | * All rights reserved.</center></h2> |
||
12 | * |
||
13 | * This software component is licensed by ST under BSD 3-Clause license, |
||
14 | * the "License"; You may not use this file except in compliance with the |
||
15 | * License. You may obtain a copy of the License at: |
||
16 | * opensource.org/licenses/BSD-3-Clause |
||
17 | * |
||
18 | ****************************************************************************** |
||
19 | */ |
||
20 | /* USER CODE END Header */ |
||
21 | |||
22 | /* Includes ------------------------------------------------------------------*/ |
||
23 | #include "main.h" |
||
24 | /* USER CODE BEGIN Includes */ |
||
25 | |||
26 | /* USER CODE END Includes */ |
||
27 | |||
28 | /* Private typedef -----------------------------------------------------------*/ |
||
29 | /* USER CODE BEGIN TD */ |
||
30 | |||
31 | /* USER CODE END TD */ |
||
32 | |||
33 | /* Private define ------------------------------------------------------------*/ |
||
34 | /* USER CODE BEGIN Define */ |
||
35 | |||
36 | /* USER CODE END Define */ |
||
37 | |||
38 | /* Private macro -------------------------------------------------------------*/ |
||
39 | /* USER CODE BEGIN Macro */ |
||
40 | |||
41 | /* USER CODE END Macro */ |
||
42 | |||
43 | /* Private variables ---------------------------------------------------------*/ |
||
44 | /* USER CODE BEGIN PV */ |
||
45 | |||
46 | /* USER CODE END PV */ |
||
47 | |||
48 | /* Private function prototypes -----------------------------------------------*/ |
||
49 | /* USER CODE BEGIN PFP */ |
||
50 | |||
51 | /* USER CODE END PFP */ |
||
52 | |||
53 | /* External functions --------------------------------------------------------*/ |
||
54 | /* USER CODE BEGIN ExternalFunctions */ |
||
55 | |||
56 | /* USER CODE END ExternalFunctions */ |
||
57 | |||
58 | /* USER CODE BEGIN 0 */ |
||
59 | |||
60 | /* USER CODE END 0 */ |
||
61 | /** |
||
62 | * Initializes the Global MSP. |
||
63 | */ |
||
64 | void HAL_MspInit(void) |
||
65 | { |
||
66 | /* USER CODE BEGIN MspInit 0 */ |
||
67 | |||
68 | /* USER CODE END MspInit 0 */ |
||
69 | |||
70 | __HAL_RCC_AFIO_CLK_ENABLE(); |
||
71 | __HAL_RCC_PWR_CLK_ENABLE(); |
||
72 | |||
73 | /* System interrupt init*/ |
||
74 | |||
75 | /** NOJTAG: JTAG-DP Disabled and SW-DP Enabled |
||
76 | */ |
||
77 | __HAL_AFIO_REMAP_SWJ_NOJTAG(); |
||
78 | |||
79 | /* USER CODE BEGIN MspInit 1 */ |
||
80 | |||
81 | /* USER CODE END MspInit 1 */ |
||
82 | } |
||
83 | |||
84 | /** |
||
11 | mjames | 85 | * @brief I2C MSP Initialization |
86 | * This function configures the hardware resources used in this example |
||
87 | * @param hi2c: I2C handle pointer |
||
88 | * @retval None |
||
89 | */ |
||
90 | void HAL_I2C_MspInit(I2C_HandleTypeDef* hi2c) |
||
91 | { |
||
92 | GPIO_InitTypeDef GPIO_InitStruct = {0}; |
||
28 | mjames | 93 | if(hi2c->Instance==I2C1) |
11 | mjames | 94 | { |
28 | mjames | 95 | /* USER CODE BEGIN I2C1_MspInit 0 */ |
96 | |||
97 | /* USER CODE END I2C1_MspInit 0 */ |
||
98 | |||
99 | __HAL_RCC_GPIOB_CLK_ENABLE(); |
||
100 | /**I2C1 GPIO Configuration |
||
101 | PB8 ------> I2C1_SCL |
||
102 | PB9 ------> I2C1_SDA |
||
103 | */ |
||
104 | GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_9; |
||
105 | GPIO_InitStruct.Mode = GPIO_MODE_AF_OD; |
||
106 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; |
||
107 | HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); |
||
108 | |||
109 | __HAL_AFIO_REMAP_I2C1_ENABLE(); |
||
110 | |||
111 | /* Peripheral clock enable */ |
||
112 | __HAL_RCC_I2C1_CLK_ENABLE(); |
||
113 | /* USER CODE BEGIN I2C1_MspInit 1 */ |
||
114 | |||
115 | /* USER CODE END I2C1_MspInit 1 */ |
||
116 | } |
||
117 | else if(hi2c->Instance==I2C2) |
||
118 | { |
||
11 | mjames | 119 | /* USER CODE BEGIN I2C2_MspInit 0 */ |
16 | mjames | 120 | __HAL_RCC_I2C2_CLK_ENABLE(); |
11 | mjames | 121 | |
122 | /* USER CODE END I2C2_MspInit 0 */ |
||
123 | |||
124 | __HAL_RCC_GPIOB_CLK_ENABLE(); |
||
125 | /**I2C2 GPIO Configuration |
||
126 | PB10 ------> I2C2_SCL |
||
127 | PB11 ------> I2C2_SDA |
||
128 | */ |
||
129 | GPIO_InitStruct.Pin = GPIO_PIN_10|GPIO_PIN_11; |
||
130 | GPIO_InitStruct.Mode = GPIO_MODE_AF_OD; |
||
28 | mjames | 131 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; |
11 | mjames | 132 | HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); |
133 | |||
134 | /* Peripheral clock enable */ |
||
135 | __HAL_RCC_I2C2_CLK_ENABLE(); |
||
136 | /* USER CODE BEGIN I2C2_MspInit 1 */ |
||
137 | |||
138 | /* USER CODE END I2C2_MspInit 1 */ |
||
139 | } |
||
140 | |||
141 | } |
||
142 | |||
143 | /** |
||
144 | * @brief I2C MSP De-Initialization |
||
145 | * This function freeze the hardware resources used in this example |
||
146 | * @param hi2c: I2C handle pointer |
||
147 | * @retval None |
||
148 | */ |
||
149 | void HAL_I2C_MspDeInit(I2C_HandleTypeDef* hi2c) |
||
150 | { |
||
28 | mjames | 151 | if(hi2c->Instance==I2C1) |
11 | mjames | 152 | { |
28 | mjames | 153 | /* USER CODE BEGIN I2C1_MspDeInit 0 */ |
154 | |||
155 | /* USER CODE END I2C1_MspDeInit 0 */ |
||
156 | /* Peripheral clock disable */ |
||
157 | __HAL_RCC_I2C1_CLK_DISABLE(); |
||
158 | |||
159 | /**I2C1 GPIO Configuration |
||
160 | PB8 ------> I2C1_SCL |
||
161 | PB9 ------> I2C1_SDA |
||
162 | */ |
||
163 | HAL_GPIO_DeInit(GPIOB, GPIO_PIN_8); |
||
164 | |||
165 | HAL_GPIO_DeInit(GPIOB, GPIO_PIN_9); |
||
166 | |||
167 | /* USER CODE BEGIN I2C1_MspDeInit 1 */ |
||
168 | |||
169 | /* USER CODE END I2C1_MspDeInit 1 */ |
||
170 | } |
||
171 | else if(hi2c->Instance==I2C2) |
||
172 | { |
||
11 | mjames | 173 | /* USER CODE BEGIN I2C2_MspDeInit 0 */ |
174 | |||
175 | /* USER CODE END I2C2_MspDeInit 0 */ |
||
176 | /* Peripheral clock disable */ |
||
177 | __HAL_RCC_I2C2_CLK_DISABLE(); |
||
178 | |||
179 | /**I2C2 GPIO Configuration |
||
180 | PB10 ------> I2C2_SCL |
||
181 | PB11 ------> I2C2_SDA |
||
182 | */ |
||
183 | HAL_GPIO_DeInit(GPIOB, GPIO_PIN_10); |
||
184 | |||
185 | HAL_GPIO_DeInit(GPIOB, GPIO_PIN_11); |
||
186 | |||
187 | /* USER CODE BEGIN I2C2_MspDeInit 1 */ |
||
188 | |||
189 | /* USER CODE END I2C2_MspDeInit 1 */ |
||
190 | } |
||
191 | |||
192 | } |
||
193 | |||
194 | /** |
||
13 | mjames | 195 | * @brief RTC MSP Initialization |
196 | * This function configures the hardware resources used in this example |
||
197 | * @param hrtc: RTC handle pointer |
||
198 | * @retval None |
||
199 | */ |
||
200 | void HAL_RTC_MspInit(RTC_HandleTypeDef* hrtc) |
||
201 | { |
||
202 | if(hrtc->Instance==RTC) |
||
203 | { |
||
204 | /* USER CODE BEGIN RTC_MspInit 0 */ |
||
205 | |||
206 | /* USER CODE END RTC_MspInit 0 */ |
||
207 | HAL_PWR_EnableBkUpAccess(); |
||
208 | /* Enable BKP CLK enable for backup registers */ |
||
209 | __HAL_RCC_BKP_CLK_ENABLE(); |
||
210 | /* Peripheral clock enable */ |
||
211 | __HAL_RCC_RTC_ENABLE(); |
||
212 | /* USER CODE BEGIN RTC_MspInit 1 */ |
||
213 | |||
214 | /* USER CODE END RTC_MspInit 1 */ |
||
215 | } |
||
216 | |||
217 | } |
||
218 | |||
219 | /** |
||
220 | * @brief RTC MSP De-Initialization |
||
221 | * This function freeze the hardware resources used in this example |
||
222 | * @param hrtc: RTC handle pointer |
||
223 | * @retval None |
||
224 | */ |
||
225 | void HAL_RTC_MspDeInit(RTC_HandleTypeDef* hrtc) |
||
226 | { |
||
227 | if(hrtc->Instance==RTC) |
||
228 | { |
||
229 | /* USER CODE BEGIN RTC_MspDeInit 0 */ |
||
230 | |||
231 | /* USER CODE END RTC_MspDeInit 0 */ |
||
232 | /* Peripheral clock disable */ |
||
233 | __HAL_RCC_RTC_DISABLE(); |
||
234 | /* USER CODE BEGIN RTC_MspDeInit 1 */ |
||
235 | |||
236 | /* USER CODE END RTC_MspDeInit 1 */ |
||
237 | } |
||
238 | |||
239 | } |
||
240 | |||
241 | /** |
||
2 | mjames | 242 | * @brief SPI MSP Initialization |
243 | * This function configures the hardware resources used in this example |
||
244 | * @param hspi: SPI handle pointer |
||
245 | * @retval None |
||
246 | */ |
||
247 | void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi) |
||
248 | { |
||
249 | GPIO_InitTypeDef GPIO_InitStruct = {0}; |
||
250 | if(hspi->Instance==SPI1) |
||
251 | { |
||
252 | /* USER CODE BEGIN SPI1_MspInit 0 */ |
||
253 | |||
254 | /* USER CODE END SPI1_MspInit 0 */ |
||
255 | /* Peripheral clock enable */ |
||
256 | __HAL_RCC_SPI1_CLK_ENABLE(); |
||
257 | |||
258 | __HAL_RCC_GPIOA_CLK_ENABLE(); |
||
259 | /**SPI1 GPIO Configuration |
||
260 | PA5 ------> SPI1_SCK |
||
261 | PA7 ------> SPI1_MOSI |
||
262 | */ |
||
263 | GPIO_InitStruct.Pin = SPI_SCK_Pin|SPI_MOSI_Pin; |
||
264 | GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; |
||
265 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; |
||
266 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
||
267 | |||
268 | /* USER CODE BEGIN SPI1_MspInit 1 */ |
||
269 | |||
270 | /* USER CODE END SPI1_MspInit 1 */ |
||
271 | } |
||
272 | |||
273 | } |
||
274 | |||
275 | /** |
||
276 | * @brief SPI MSP De-Initialization |
||
277 | * This function freeze the hardware resources used in this example |
||
278 | * @param hspi: SPI handle pointer |
||
279 | * @retval None |
||
280 | */ |
||
281 | void HAL_SPI_MspDeInit(SPI_HandleTypeDef* hspi) |
||
282 | { |
||
283 | if(hspi->Instance==SPI1) |
||
284 | { |
||
285 | /* USER CODE BEGIN SPI1_MspDeInit 0 */ |
||
286 | |||
287 | /* USER CODE END SPI1_MspDeInit 0 */ |
||
288 | /* Peripheral clock disable */ |
||
289 | __HAL_RCC_SPI1_CLK_DISABLE(); |
||
290 | |||
291 | /**SPI1 GPIO Configuration |
||
292 | PA5 ------> SPI1_SCK |
||
293 | PA7 ------> SPI1_MOSI |
||
294 | */ |
||
295 | HAL_GPIO_DeInit(GPIOA, SPI_SCK_Pin|SPI_MOSI_Pin); |
||
296 | |||
297 | /* USER CODE BEGIN SPI1_MspDeInit 1 */ |
||
298 | |||
299 | /* USER CODE END SPI1_MspDeInit 1 */ |
||
300 | } |
||
301 | |||
302 | } |
||
303 | |||
304 | /** |
||
9 | mjames | 305 | * @brief TIM_OC MSP Initialization |
306 | * This function configures the hardware resources used in this example |
||
307 | * @param htim_oc: TIM_OC handle pointer |
||
308 | * @retval None |
||
309 | */ |
||
310 | void HAL_TIM_OC_MspInit(TIM_HandleTypeDef* htim_oc) |
||
311 | { |
||
312 | if(htim_oc->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 | |||
324 | } |
||
325 | |||
326 | /** |
||
2 | mjames | 327 | * @brief TIM_Encoder MSP Initialization |
328 | * This function configures the hardware resources used in this example |
||
329 | * @param htim_encoder: TIM_Encoder handle pointer |
||
330 | * @retval None |
||
331 | */ |
||
332 | void HAL_TIM_Encoder_MspInit(TIM_HandleTypeDef* htim_encoder) |
||
333 | { |
||
334 | GPIO_InitTypeDef GPIO_InitStruct = {0}; |
||
335 | if(htim_encoder->Instance==TIM4) |
||
336 | { |
||
337 | /* USER CODE BEGIN TIM4_MspInit 0 */ |
||
338 | |||
339 | /* USER CODE END TIM4_MspInit 0 */ |
||
340 | /* Peripheral clock enable */ |
||
341 | __HAL_RCC_TIM4_CLK_ENABLE(); |
||
342 | |||
343 | __HAL_RCC_GPIOB_CLK_ENABLE(); |
||
344 | /**TIM4 GPIO Configuration |
||
345 | PB6 ------> TIM4_CH1 |
||
346 | PB7 ------> TIM4_CH2 |
||
347 | */ |
||
21 | mjames | 348 | GPIO_InitStruct.Pin = encoder_1_Pin|encoder_2_Pin; |
2 | mjames | 349 | GPIO_InitStruct.Mode = GPIO_MODE_INPUT; |
16 | mjames | 350 | GPIO_InitStruct.Pull = GPIO_PULLUP; |
2 | mjames | 351 | HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); |
352 | |||
353 | /* USER CODE BEGIN TIM4_MspInit 1 */ |
||
354 | |||
355 | /* USER CODE END TIM4_MspInit 1 */ |
||
356 | } |
||
357 | |||
358 | } |
||
359 | |||
360 | /** |
||
9 | mjames | 361 | * @brief TIM_OC MSP De-Initialization |
362 | * This function freeze the hardware resources used in this example |
||
363 | * @param htim_oc: TIM_OC handle pointer |
||
364 | * @retval None |
||
365 | */ |
||
366 | void HAL_TIM_OC_MspDeInit(TIM_HandleTypeDef* htim_oc) |
||
367 | { |
||
368 | if(htim_oc->Instance==TIM3) |
||
369 | { |
||
370 | /* USER CODE BEGIN TIM3_MspDeInit 0 */ |
||
371 | |||
372 | /* USER CODE END TIM3_MspDeInit 0 */ |
||
373 | /* Peripheral clock disable */ |
||
374 | __HAL_RCC_TIM3_CLK_DISABLE(); |
||
375 | /* USER CODE BEGIN TIM3_MspDeInit 1 */ |
||
376 | |||
377 | /* USER CODE END TIM3_MspDeInit 1 */ |
||
378 | } |
||
379 | |||
380 | } |
||
381 | |||
382 | /** |
||
2 | mjames | 383 | * @brief TIM_Encoder MSP De-Initialization |
384 | * This function freeze the hardware resources used in this example |
||
385 | * @param htim_encoder: TIM_Encoder handle pointer |
||
386 | * @retval None |
||
387 | */ |
||
388 | void HAL_TIM_Encoder_MspDeInit(TIM_HandleTypeDef* htim_encoder) |
||
389 | { |
||
390 | if(htim_encoder->Instance==TIM4) |
||
391 | { |
||
392 | /* USER CODE BEGIN TIM4_MspDeInit 0 */ |
||
393 | |||
394 | /* USER CODE END TIM4_MspDeInit 0 */ |
||
395 | /* Peripheral clock disable */ |
||
396 | __HAL_RCC_TIM4_CLK_DISABLE(); |
||
397 | |||
398 | /**TIM4 GPIO Configuration |
||
399 | PB6 ------> TIM4_CH1 |
||
400 | PB7 ------> TIM4_CH2 |
||
401 | */ |
||
21 | mjames | 402 | HAL_GPIO_DeInit(GPIOB, encoder_1_Pin|encoder_2_Pin); |
2 | mjames | 403 | |
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 | */ |
||
417 | void HAL_UART_MspInit(UART_HandleTypeDef* huart) |
||
418 | { |
||
419 | GPIO_InitTypeDef GPIO_InitStruct = {0}; |
||
420 | if(huart->Instance==USART1) |
||
421 | { |
||
422 | /* USER CODE BEGIN USART1_MspInit 0 */ |
||
423 | |||
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_NOPULL; |
||
441 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
||
442 | |||
443 | /* USART1 interrupt Init */ |
||
444 | HAL_NVIC_SetPriority(USART1_IRQn, 0, 0); |
||
445 | HAL_NVIC_EnableIRQ(USART1_IRQn); |
||
446 | /* USER CODE BEGIN USART1_MspInit 1 */ |
||
447 | |||
448 | /* USER CODE END USART1_MspInit 1 */ |
||
449 | } |
||
450 | |||
451 | } |
||
452 | |||
453 | /** |
||
454 | * @brief UART MSP De-Initialization |
||
455 | * This function freeze the hardware resources used in this example |
||
456 | * @param huart: UART handle pointer |
||
457 | * @retval None |
||
458 | */ |
||
459 | void HAL_UART_MspDeInit(UART_HandleTypeDef* huart) |
||
460 | { |
||
461 | if(huart->Instance==USART1) |
||
462 | { |
||
463 | /* USER CODE BEGIN USART1_MspDeInit 0 */ |
||
464 | |||
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 | |||
479 | /* USER CODE END USART1_MspDeInit 1 */ |
||
480 | } |
||
481 | |||
482 | } |
||
483 | |||
484 | /* USER CODE BEGIN 1 */ |
||
485 | |||
486 | /* USER CODE END 1 */ |
||
487 | |||
488 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |