Rev 15 | Rev 17 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 15 | Rev 16 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | /** |
1 | /** |
2 | ****************************************************************************** |
2 | ****************************************************************************** |
3 | * File Name : main.c |
3 | * File Name : main.c |
4 | * Description : Main program body |
4 | * Description : Main program body |
5 | ****************************************************************************** |
5 | ****************************************************************************** |
6 | * |
6 | * |
7 | * COPYRIGHT(c) 2016 STMicroelectronics |
7 | * COPYRIGHT(c) 2016 STMicroelectronics |
8 | * |
8 | * |
9 | * Redistribution and use in source and binary forms, with or without modification, |
9 | * Redistribution and use in source and binary forms, with or without modification, |
10 | * are permitted provided that the following conditions are met: |
10 | * are permitted provided that the following conditions are met: |
11 | * 1. Redistributions of source code must retain the above copyright notice, |
11 | * 1. Redistributions of source code must retain the above copyright notice, |
12 | * this list of conditions and the following disclaimer. |
12 | * this list of conditions and the following disclaimer. |
13 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
13 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
14 | * this list of conditions and the following disclaimer in the documentation |
14 | * this list of conditions and the following disclaimer in the documentation |
15 | * and/or other materials provided with the distribution. |
15 | * and/or other materials provided with the distribution. |
16 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
16 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
17 | * may be used to endorse or promote products derived from this software |
17 | * may be used to endorse or promote products derived from this software |
18 | * without specific prior written permission. |
18 | * without specific prior written permission. |
19 | * |
19 | * |
20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
21 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
21 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
23 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
23 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
24 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
24 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
25 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
25 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
26 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
26 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
27 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
27 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
28 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
29 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
30 | * |
30 | * |
31 | ****************************************************************************** |
31 | ****************************************************************************** |
32 | */ |
32 | */ |
33 | /* Includes ------------------------------------------------------------------*/ |
33 | /* Includes ------------------------------------------------------------------*/ |
34 | #include "stm32f1xx_hal.h" |
34 | #include "stm32f1xx_hal.h" |
35 | 35 | ||
36 | /* USER CODE BEGIN Includes */ |
36 | /* USER CODE BEGIN Includes */ |
37 | #include "ap_math.h" |
37 | #include "ap_math.h" |
Line 40... | Line 40... | ||
40 | #include "Font.h" |
40 | #include "Font.h" |
41 | #include "dials.h" |
41 | #include "dials.h" |
42 | #include "switches.h" |
42 | #include "switches.h" |
43 | #include <math.h> |
43 | #include <math.h> |
44 | #include "plx.h" |
44 | #include "plx.h" |
- | 45 | #include "eeprom.h" |
|
45 | 46 | ||
46 | /* USER CODE END Includes */ |
47 | /* USER CODE END Includes */ |
47 | 48 | ||
48 | /* Private variables ---------------------------------------------------------*/ |
49 | /* Private variables ---------------------------------------------------------*/ |
49 | SPI_HandleTypeDef hspi1; |
50 | SPI_HandleTypeDef hspi1; |
Line 62... | Line 63... | ||
62 | int16_t dial0[2] = |
63 | int16_t dial0[2] = |
63 | { 0, 0 }; |
64 | { 0, 0 }; |
64 | int16_t dial1[2] = |
65 | int16_t dial1[2] = |
65 | { -1, -1 }; |
66 | { -1, -1 }; |
66 | 67 | ||
- | 68 | /* Virtual address defined by the user: 0xFFFF value is prohibited */ |
|
- | 69 | uint16_t VirtAddVarTab[NumbOfVar] = {0x5555, 0x6666, 0x7777}; |
|
67 | 70 | ||
68 | union |
71 | union |
69 | { |
72 | { |
70 | PLX_SensorInfo Sensor[MAXRDG]; |
73 | PLX_SensorInfo Sensor[MAXRDG]; |
71 | char Bytes[MAXRDG * sizeof(PLX_SensorInfo)]; |
74 | char Bytes[MAXRDG * sizeof(PLX_SensorInfo)]; |
Line 74... | Line 77... | ||
74 | int Min[MAXRDG]; |
77 | int Min[MAXRDG]; |
75 | int PLXItems; |
78 | int PLXItems; |
76 | /* USER CODE END PV */ |
79 | /* USER CODE END PV */ |
77 | 80 | ||
78 | /* Private function prototypes -----------------------------------------------*/ |
81 | /* Private function prototypes -----------------------------------------------*/ |
79 | void |
- | |
80 | SystemClock_Config(void); |
82 | void SystemClock_Config(void); |
81 | void |
- | |
82 | Error_Handler(void); |
83 | void Error_Handler(void); |
83 | static void |
- | |
84 | MX_GPIO_Init(void); |
84 | static void MX_GPIO_Init(void); |
85 | static void |
- | |
86 | MX_SPI1_Init(void); |
85 | static void MX_SPI1_Init(void); |
87 | static void |
- | |
88 | MX_USART2_UART_Init(void); |
86 | static void MX_USART2_UART_Init(void); |
89 | static void |
- | |
90 | MX_USART1_UART_Init(void); |
87 | static void MX_USART1_UART_Init(void); |
91 | 88 | ||
92 | /* USER CODE BEGIN PFP */ |
89 | /* USER CODE BEGIN PFP */ |
93 | /* Private function prototypes -----------------------------------------------*/ |
90 | /* Private function prototypes -----------------------------------------------*/ |
94 | 91 | ||
95 | /* USER CODE END PFP */ |
92 | /* USER CODE END PFP */ |
Line 266... | Line 263... | ||
266 | /* USER CODE END 0 */ |
263 | /* USER CODE END 0 */ |
267 | 264 | ||
268 | int main(void) |
265 | int main(void) |
269 | { |
266 | { |
270 | 267 | ||
271 | /* USER CODE BEGIN 1 */ |
268 | /* USER CODE BEGIN 1 */ |
272 | 269 | ||
273 | GPIO_InitTypeDef GPIO_InitStruct; |
270 | GPIO_InitTypeDef GPIO_InitStruct; |
274 | 271 | ||
275 | __HAL_RCC_SPI1_CLK_ENABLE() |
272 | __HAL_RCC_SPI1_CLK_ENABLE() |
276 | ; |
273 | ; |
277 | __HAL_RCC_USART1_CLK_ENABLE() |
274 | __HAL_RCC_USART1_CLK_ENABLE() |
278 | ; // PLX main port |
275 | ; // PLX main port |
279 | __HAL_RCC_USART2_CLK_ENABLE() |
276 | __HAL_RCC_USART2_CLK_ENABLE() |
280 | ; // debug port |
277 | ; // debug port |
281 | /* USER CODE END 1 */ |
278 | /* USER CODE END 1 */ |
282 | 279 | ||
283 | /* MCU Configuration----------------------------------------------------------*/ |
280 | /* MCU Configuration----------------------------------------------------------*/ |
284 | 281 | ||
285 | /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ |
282 | /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ |
286 | HAL_Init(); |
283 | HAL_Init(); |
287 | 284 | ||
288 | /* Configure the system clock */ |
285 | /* Configure the system clock */ |
289 | SystemClock_Config(); |
286 | SystemClock_Config(); |
290 | 287 | ||
291 | /* Initialize all configured peripherals */ |
288 | /* Initialize all configured peripherals */ |
292 | MX_GPIO_Init(); |
289 | MX_GPIO_Init(); |
293 | MX_SPI1_Init(); |
290 | MX_SPI1_Init(); |
294 | MX_USART2_UART_Init(); |
291 | MX_USART2_UART_Init(); |
295 | MX_USART1_UART_Init(); |
292 | MX_USART1_UART_Init(); |
296 | 293 | ||
297 | #if 0 |
- | |
298 | /* USER CODE BEGIN 2 */ |
294 | /* USER CODE BEGIN 2 */ |
299 | /* Need to set AF mode for output pins DURR. */ |
- | |
300 | /* SPI bus AF pin selects */ |
295 | /* SPI bus AF pin selects */ |
301 | GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; |
- | |
302 | 296 | ||
303 | GPIO_InitStruct.Pin = GPIO_PIN_5 | GPIO_PIN_7; |
- | |
304 | GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; |
- | |
305 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
- | |
306 | 297 | ||
307 | /* USART2 AF pin selects */ |
- | |
308 | GPIO_InitStruct.Pin = GPIO_PIN_2; |
- | |
309 | GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; |
- | |
310 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
- | |
311 | - | ||
312 | /* USART1 AF pin selects */ |
- | |
313 | GPIO_InitStruct.Pin = GPIO_PIN_9; |
- | |
314 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
- | |
315 | #endif |
- | |
316 | /* Turn on USART2 IRQ */ |
298 | /* Turn on USART2 IRQ */ |
317 | HAL_NVIC_SetPriority(USART2_IRQn, 4, 0); |
299 | HAL_NVIC_SetPriority(USART2_IRQn, 4, 0); |
318 | HAL_NVIC_EnableIRQ(USART2_IRQn); |
300 | HAL_NVIC_EnableIRQ(USART2_IRQn); |
319 | 301 | ||
320 | /* Turn on USART1 IRQ */ |
302 | /* Turn on USART1 IRQ */ |
321 | HAL_NVIC_SetPriority(USART1_IRQn, 2, 0); |
303 | HAL_NVIC_SetPriority(USART1_IRQn, 2, 0); |
Line 326... | Line 308... | ||
326 | init_usart_ctl(&uc2, huart2.Instance); |
308 | init_usart_ctl(&uc2, huart2.Instance); |
327 | 309 | ||
328 | EnableSerialRxInterrupt(&uc1); |
310 | EnableSerialRxInterrupt(&uc1); |
329 | EnableSerialRxInterrupt(&uc2); |
311 | EnableSerialRxInterrupt(&uc2); |
330 | 312 | ||
- | 313 | EE_Init(); |
|
- | 314 | ||
331 | ap_init(); // set up the approximate math library |
315 | ap_init(); // set up the approximate math library |
332 | 316 | ||
333 | int disp; |
317 | int disp; |
334 | 318 | ||
335 | ssd1306_begin(1, 0); |
319 | ssd1306_begin(1, 0); |
Line 356... | Line 340... | ||
356 | } |
340 | } |
357 | 341 | ||
358 | 342 | ||
359 | InitSwitches(); |
343 | InitSwitches(); |
360 | 344 | ||
361 | /* USER CODE END 2 */ |
345 | /* USER CODE END 2 */ |
362 | 346 | ||
363 | /* Infinite loop */ |
347 | /* Infinite loop */ |
364 | /* USER CODE BEGIN WHILE */ |
348 | /* USER CODE BEGIN WHILE */ |
365 | uint32_t Ticks = HAL_GetTick() + 100; |
349 | uint32_t Ticks = HAL_GetTick() + 100; |
366 | 350 | ||
367 | int i; |
351 | int i; |
368 | 352 | ||
369 | // PLX decoder protocol |
353 | // PLX decoder protocol |
Line 436... | Line 420... | ||
436 | } |
420 | } |
437 | } |
421 | } |
438 | 422 | ||
439 | HAL_Delay(1); |
423 | HAL_Delay(1); |
440 | } |
424 | } |
441 | /* USER CODE END WHILE */ |
425 | /* USER CODE END WHILE */ |
- | 426 | ||
- | 427 | /* USER CODE BEGIN 3 */ |
|
442 | 428 | ||
- | 429 | ||
443 | /* USER CODE BEGIN 3 */ |
430 | /* USER CODE END 3 */ |
444 | 431 | ||
445 | } |
432 | } |
446 | /* USER CODE END 3 */ |
- | |
447 | 433 | ||
448 | /** System Clock Configuration |
434 | /** System Clock Configuration |
449 | */ |
435 | */ |
450 | void SystemClock_Config(void) |
436 | void SystemClock_Config(void) |
451 | { |
437 | { |
452 | 438 | ||
453 | RCC_OscInitTypeDef RCC_OscInitStruct; |
439 | RCC_OscInitTypeDef RCC_OscInitStruct; |
454 | RCC_ClkInitTypeDef RCC_ClkInitStruct; |
440 | RCC_ClkInitTypeDef RCC_ClkInitStruct; |
455 | - | ||
456 | RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; |
- | |
457 | RCC_OscInitStruct.HSEState = RCC_HSE_BYPASS; |
- | |
458 | RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1; |
- | |
459 | RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; |
- | |
460 | RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; |
- | |
461 | RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9; |
- | |
462 | if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) |
- | |
463 | { |
- | |
464 | Error_Handler(); |
- | |
465 | } |
- | |
466 | 441 | ||
- | 442 | RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; |
|
- | 443 | RCC_OscInitStruct.HSEState = RCC_HSE_BYPASS; |
|
- | 444 | RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1; |
|
- | 445 | RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; |
|
- | 446 | RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; |
|
- | 447 | RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9; |
|
- | 448 | if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) |
|
- | 449 | { |
|
- | 450 | Error_Handler(); |
|
- | 451 | } |
|
- | 452 | ||
467 | RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK |
453 | RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK |
468 | | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2; |
454 | |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2; |
469 | RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; |
455 | RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; |
470 | RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; |
456 | RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; |
471 | RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2; |
457 | RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2; |
472 | RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; |
458 | RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; |
473 | if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK) |
459 | if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK) |
474 | { |
460 | { |
475 | Error_Handler(); |
461 | Error_Handler(); |
476 | } |
462 | } |
477 | 463 | ||
478 | HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq() / 1000); |
464 | HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000); |
479 | 465 | ||
480 | HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK); |
466 | HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK); |
481 | 467 | ||
482 | /* SysTick_IRQn interrupt configuration */ |
468 | /* SysTick_IRQn interrupt configuration */ |
483 | HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0); |
469 | HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0); |
484 | } |
470 | } |
485 | 471 | ||
486 | /* SPI1 init function */ |
472 | /* SPI1 init function */ |
487 | static void MX_SPI1_Init(void) |
473 | static void MX_SPI1_Init(void) |
488 | { |
474 | { |
489 | 475 | ||
490 | hspi1.Instance = SPI1; |
476 | hspi1.Instance = SPI1; |
491 | hspi1.Init.Mode = SPI_MODE_MASTER; |
477 | hspi1.Init.Mode = SPI_MODE_MASTER; |
492 | hspi1.Init.Direction = SPI_DIRECTION_1LINE; |
478 | hspi1.Init.Direction = SPI_DIRECTION_1LINE; |
493 | hspi1.Init.DataSize = SPI_DATASIZE_8BIT; |
479 | hspi1.Init.DataSize = SPI_DATASIZE_8BIT; |
494 | hspi1.Init.CLKPolarity = SPI_POLARITY_HIGH; |
480 | hspi1.Init.CLKPolarity = SPI_POLARITY_HIGH; |
495 | hspi1.Init.CLKPhase = SPI_PHASE_1EDGE; |
481 | hspi1.Init.CLKPhase = SPI_PHASE_1EDGE; |
496 | hspi1.Init.NSS = SPI_NSS_SOFT; |
482 | hspi1.Init.NSS = SPI_NSS_SOFT; |
497 | hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_8; |
483 | hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_8; |
498 | hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB; |
484 | hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB; |
499 | hspi1.Init.TIMode = SPI_TIMODE_DISABLE; |
485 | hspi1.Init.TIMode = SPI_TIMODE_DISABLE; |
500 | hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE; |
486 | hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE; |
501 | hspi1.Init.CRCPolynomial = 10; |
487 | hspi1.Init.CRCPolynomial = 10; |
502 | if (HAL_SPI_Init(&hspi1) != HAL_OK) |
488 | if (HAL_SPI_Init(&hspi1) != HAL_OK) |
503 | { |
489 | { |
504 | Error_Handler(); |
490 | Error_Handler(); |
505 | } |
491 | } |
506 | 492 | ||
507 | } |
493 | } |
508 | 494 | ||
509 | /* USART1 init function */ |
495 | /* USART1 init function */ |
510 | static void MX_USART1_UART_Init(void) |
496 | static void MX_USART1_UART_Init(void) |
511 | { |
497 | { |
512 | 498 | ||
513 | huart1.Instance = USART1; |
499 | huart1.Instance = USART1; |
514 | huart1.Init.BaudRate = 19200; |
500 | huart1.Init.BaudRate = 19200; |
515 | huart1.Init.WordLength = UART_WORDLENGTH_8B; |
501 | huart1.Init.WordLength = UART_WORDLENGTH_8B; |
516 | huart1.Init.StopBits = UART_STOPBITS_1; |
502 | huart1.Init.StopBits = UART_STOPBITS_1; |
517 | huart1.Init.Parity = UART_PARITY_NONE; |
503 | huart1.Init.Parity = UART_PARITY_NONE; |
518 | huart1.Init.Mode = UART_MODE_TX_RX; |
504 | huart1.Init.Mode = UART_MODE_TX_RX; |
519 | huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE; |
505 | huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE; |
520 | huart1.Init.OverSampling = UART_OVERSAMPLING_16; |
506 | huart1.Init.OverSampling = UART_OVERSAMPLING_16; |
521 | if (HAL_UART_Init(&huart1) != HAL_OK) |
507 | if (HAL_UART_Init(&huart1) != HAL_OK) |
522 | { |
508 | { |
523 | Error_Handler(); |
509 | Error_Handler(); |
524 | } |
510 | } |
525 | 511 | ||
526 | } |
512 | } |
527 | 513 | ||
528 | /* USART2 init function */ |
514 | /* USART2 init function */ |
529 | static void MX_USART2_UART_Init(void) |
515 | static void MX_USART2_UART_Init(void) |
530 | { |
516 | { |
531 | 517 | ||
532 | huart2.Instance = USART2; |
518 | huart2.Instance = USART2; |
533 | huart2.Init.BaudRate = 115200; |
519 | huart2.Init.BaudRate = 115200; |
534 | huart2.Init.WordLength = UART_WORDLENGTH_8B; |
520 | huart2.Init.WordLength = UART_WORDLENGTH_8B; |
535 | huart2.Init.StopBits = UART_STOPBITS_1; |
521 | huart2.Init.StopBits = UART_STOPBITS_1; |
536 | huart2.Init.Parity = UART_PARITY_NONE; |
522 | huart2.Init.Parity = UART_PARITY_NONE; |
537 | huart2.Init.Mode = UART_MODE_TX_RX; |
523 | huart2.Init.Mode = UART_MODE_TX_RX; |
538 | huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE; |
524 | huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE; |
539 | huart2.Init.OverSampling = UART_OVERSAMPLING_16; |
525 | huart2.Init.OverSampling = UART_OVERSAMPLING_16; |
540 | if (HAL_UART_Init(&huart2) != HAL_OK) |
526 | if (HAL_UART_Init(&huart2) != HAL_OK) |
541 | { |
527 | { |
542 | Error_Handler(); |
528 | Error_Handler(); |
543 | } |
529 | } |
544 | 530 | ||
545 | } |
531 | } |
546 | 532 | ||
547 | /** Configure pins as |
533 | /** Configure pins as |
548 | * Analog |
534 | * Analog |
549 | * Input |
535 | * Input |
550 | * Output |
536 | * Output |
551 | * EVENT_OUT |
537 | * EVENT_OUT |
552 | * EXTI |
538 | * EXTI |
553 | */ |
539 | */ |
554 | static void MX_GPIO_Init(void) |
540 | static void MX_GPIO_Init(void) |
555 | { |
541 | { |
556 | 542 | ||
557 | GPIO_InitTypeDef GPIO_InitStruct; |
543 | GPIO_InitTypeDef GPIO_InitStruct; |
558 | 544 | ||
559 | /* GPIO Ports Clock Enable */ |
545 | /* GPIO Ports Clock Enable */ |
560 | __HAL_RCC_GPIOD_CLK_ENABLE() |
546 | __HAL_RCC_GPIOD_CLK_ENABLE(); |
561 | ; |
- | |
562 | __HAL_RCC_GPIOA_CLK_ENABLE() |
547 | __HAL_RCC_GPIOA_CLK_ENABLE(); |
563 | ; |
- | |
564 | __HAL_RCC_GPIOC_CLK_ENABLE() |
548 | __HAL_RCC_GPIOC_CLK_ENABLE(); |
565 | ; |
- | |
566 | __HAL_RCC_GPIOB_CLK_ENABLE() |
549 | __HAL_RCC_GPIOB_CLK_ENABLE(); |
567 | ; |
- | |
568 | 550 | ||
569 | /*Configure GPIO pin Output Level */ |
551 | /*Configure GPIO pin Output Level */ |
570 | HAL_GPIO_WritePin(SPI_NSS1_GPIO_Port, SPI_NSS1_Pin, GPIO_PIN_SET); |
552 | HAL_GPIO_WritePin(SPI_NSS1_GPIO_Port, SPI_NSS1_Pin, GPIO_PIN_SET); |
571 | 553 | ||
572 | /*Configure GPIO pin Output Level */ |
554 | /*Configure GPIO pin Output Level */ |
573 | HAL_GPIO_WritePin(SPI1CD_GPIO_Port, SPI1CD_Pin, GPIO_PIN_RESET); |
555 | HAL_GPIO_WritePin(SPI1CD_GPIO_Port, SPI1CD_Pin, GPIO_PIN_RESET); |
574 | 556 | ||
575 | /*Configure GPIO pin Output Level */ |
557 | /*Configure GPIO pin Output Level */ |
576 | HAL_GPIO_WritePin(GPIOC, |
- | |
577 | SPI_RESET_Pin | USART3_INVERT_Pin | USB_PWR_Pin, GPIO_PIN_RESET); |
558 | HAL_GPIO_WritePin(GPIOC, SPI_RESET_Pin|USART3_INVERT_Pin|USB_PWR_Pin, GPIO_PIN_RESET); |
578 | 559 | ||
579 | /*Configure GPIO pin Output Level */ |
560 | /*Configure GPIO pin Output Level */ |
580 | HAL_GPIO_WritePin(SPI_NSS2_GPIO_Port, SPI_NSS2_Pin, GPIO_PIN_SET); |
561 | HAL_GPIO_WritePin(SPI_NSS2_GPIO_Port, SPI_NSS2_Pin, GPIO_PIN_SET); |
581 | 562 | ||
582 | /*Configure GPIO pins : SPI_NSS1_Pin SPI1CD_Pin */ |
563 | /*Configure GPIO pins : SPI_NSS1_Pin SPI1CD_Pin */ |
583 | GPIO_InitStruct.Pin = SPI_NSS1_Pin | SPI1CD_Pin; |
564 | GPIO_InitStruct.Pin = SPI_NSS1_Pin|SPI1CD_Pin; |
584 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; |
565 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; |
585 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; |
566 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; |
586 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
567 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
587 | 568 | ||
588 | /*Configure GPIO pins : SPI_RESET_Pin SPI_NSS2_Pin USART3_INVERT_Pin USB_PWR_Pin */ |
569 | /*Configure GPIO pins : SPI_RESET_Pin SPI_NSS2_Pin USART3_INVERT_Pin USB_PWR_Pin */ |
589 | GPIO_InitStruct.Pin = SPI_RESET_Pin | SPI_NSS2_Pin | USART3_INVERT_Pin |
570 | GPIO_InitStruct.Pin = SPI_RESET_Pin|SPI_NSS2_Pin|USART3_INVERT_Pin|USB_PWR_Pin; |
590 | | USB_PWR_Pin; |
- | |
591 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; |
571 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; |
592 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; |
572 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; |
593 | HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); |
573 | HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); |
594 | 574 | ||
595 | /*Configure GPIO pins : SW1_PUSH_Pin SW1_I_Pin SW1_Q_Pin SW2_PUSH_Pin */ |
575 | /*Configure GPIO pins : SW1_PUSH_Pin SW1_I_Pin SW1_Q_Pin SW2_PUSH_Pin */ |
596 | GPIO_InitStruct.Pin = SW1_PUSH_Pin | SW1_I_Pin | SW1_Q_Pin | SW2_PUSH_Pin; |
576 | GPIO_InitStruct.Pin = SW1_PUSH_Pin|SW1_I_Pin|SW1_Q_Pin|SW2_PUSH_Pin; |
597 | GPIO_InitStruct.Mode = GPIO_MODE_INPUT; |
577 | GPIO_InitStruct.Mode = GPIO_MODE_INPUT; |
598 | GPIO_InitStruct.Pull = GPIO_PULLUP; |
578 | GPIO_InitStruct.Pull = GPIO_PULLUP; |
599 | HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); |
579 | HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); |
600 | 580 | ||
601 | /*Configure GPIO pins : SW2_I_Pin SW2_Q_Pin */ |
581 | /*Configure GPIO pins : SW2_I_Pin SW2_Q_Pin */ |
602 | GPIO_InitStruct.Pin = SW2_I_Pin | SW2_Q_Pin; |
582 | GPIO_InitStruct.Pin = SW2_I_Pin|SW2_Q_Pin; |
603 | GPIO_InitStruct.Mode = GPIO_MODE_INPUT; |
583 | GPIO_InitStruct.Mode = GPIO_MODE_INPUT; |
604 | GPIO_InitStruct.Pull = GPIO_PULLUP; |
584 | GPIO_InitStruct.Pull = GPIO_PULLUP; |
605 | HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); |
585 | HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); |
606 | 586 | ||
607 | } |
587 | } |
608 | 588 | ||
609 | /* USER CODE BEGIN 4 */ |
589 | /* USER CODE BEGIN 4 */ |
610 | 590 | ||
611 | /* USER CODE END 4 */ |
591 | /* USER CODE END 4 */ |
612 | 592 | ||
613 | /** |
593 | /** |
614 | * @brief This function is executed in case of error occurrence. |
594 | * @brief This function is executed in case of error occurrence. |
615 | * @param None |
595 | * @param None |
616 | * @retval None |
596 | * @retval None |
617 | */ |
597 | */ |
618 | void Error_Handler(void) |
598 | void Error_Handler(void) |
619 | { |
599 | { |
620 | /* USER CODE BEGIN Error_Handler */ |
600 | /* USER CODE BEGIN Error_Handler */ |
621 | /* User can add his own implementation to report the HAL error return state */ |
601 | /* User can add his own implementation to report the HAL error return state */ |
622 | while (1) |
602 | while (1) |
623 | { |
603 | { |
624 | } |
604 | } |
625 | /* USER CODE END Error_Handler */ |
605 | /* USER CODE END Error_Handler */ |
626 | } |
606 | } |
627 | 607 | ||
628 | #ifdef USE_FULL_ASSERT |
608 | #ifdef USE_FULL_ASSERT |
629 | 609 | ||
630 | /** |
610 | /** |
631 | * @brief Reports the name of the source file and the source line number |
611 | * @brief Reports the name of the source file and the source line number |
632 | * where the assert_param error has occurred. |
612 | * where the assert_param error has occurred. |
633 | * @param file: pointer to the source file name |
613 | * @param file: pointer to the source file name |
634 | * @param line: assert_param error line source number |
614 | * @param line: assert_param error line source number |
635 | * @retval None |
615 | * @retval None |
636 | */ |
616 | */ |
637 | void assert_failed(uint8_t* file, uint32_t line) |
617 | void assert_failed(uint8_t* file, uint32_t line) |
638 | { |
618 | { |
639 | /* USER CODE BEGIN 6 */ |
619 | /* USER CODE BEGIN 6 */ |
640 | /* User can add his own implementation to report the file name and line number, |
620 | /* User can add his own implementation to report the file name and line number, |
641 | ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ |
621 | ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ |
642 | /* USER CODE END 6 */ |
622 | /* USER CODE END 6 */ |
643 | 623 | ||
644 | } |
624 | } |
645 | 625 | ||
646 | #endif |
626 | #endif |
647 | 627 | ||
648 | /** |
628 | /** |
649 | * @} |
629 | * @} |
650 | */ |
630 | */ |
651 | 631 | ||
652 | /** |
632 | /** |
653 | * @} |
633 | * @} |
654 | */ |
634 | */ |
655 | 635 | ||
656 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
636 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |