Rev 27 | Rev 29 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 27 | Rev 28 | ||
---|---|---|---|
Line -... | Line 1... | ||
- | 1 | /* USER CODE BEGIN Header */ |
|
1 | /** |
2 | /** |
2 | ****************************************************************************** |
3 | ****************************************************************************** |
3 | * File Name : main.c |
4 | * @file : main.c |
4 | * Description : Main program body |
5 | * @brief : Main program body |
5 | ****************************************************************************** |
6 | ****************************************************************************** |
- | 7 | * @attention |
|
6 | * |
8 | * |
7 | * COPYRIGHT(c) 2017 STMicroelectronics |
9 | * <h2><center>© Copyright (c) 2020 STMicroelectronics. |
- | 10 | * All rights reserved.</center></h2> |
|
8 | * |
11 | * |
9 | * Redistribution and use in source and binary forms, with or without modification, |
12 | * This software component is licensed by ST under BSD 3-Clause license, |
10 | * are permitted provided that the following conditions are met: |
13 | * the "License"; You may not use this file except in compliance with the |
11 | * 1. Redistributions of source code must retain the above copyright notice, |
- | |
12 | * this list of conditions and the following disclaimer. |
- | |
13 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
- | |
14 | * this list of conditions and the following disclaimer in the documentation |
- | |
15 | * and/or other materials provided with the distribution. |
14 | * License. You may obtain a copy of the License at: |
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 |
15 | * opensource.org/licenses/BSD-3-Clause |
18 | * without specific prior written permission. |
- | |
19 | * |
- | |
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 |
- | |
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 |
- | |
24 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
- | |
25 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
- | |
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, |
- | |
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. |
- | |
30 | * |
16 | * |
31 | ****************************************************************************** |
17 | ****************************************************************************** |
32 | */ |
18 | */ |
- | 19 | /* USER CODE END Header */ |
|
33 | /* Includes ------------------------------------------------------------------*/ |
20 | /* Includes ------------------------------------------------------------------*/ |
34 | #include "stm32l1xx_hal.h" |
21 | #include "main.h" |
35 | 22 | ||
- | 23 | /* Private includes ----------------------------------------------------------*/ |
|
36 | /* USER CODE BEGIN Includes */ |
24 | /* USER CODE BEGIN Includes */ |
37 | #include "serial.h" |
25 | #include "libSerial/serial.h" |
38 | #include "plx.h" |
26 | #include "libPLX/plx.h" |
39 | #include "misc.h" |
27 | #include "misc.h" |
40 | /* USER CODE END Includes */ |
28 | /* USER CODE END Includes */ |
41 | 29 | ||
- | 30 | /* Private typedef -----------------------------------------------------------*/ |
|
- | 31 | /* USER CODE BEGIN PTD */ |
|
- | 32 | ||
- | 33 | /* USER CODE END PTD */ |
|
- | 34 | ||
- | 35 | /* Private define ------------------------------------------------------------*/ |
|
- | 36 | /* USER CODE BEGIN PD */ |
|
- | 37 | /* USER CODE END PD */ |
|
- | 38 | ||
- | 39 | /* Private macro -------------------------------------------------------------*/ |
|
- | 40 | /* USER CODE BEGIN PM */ |
|
- | 41 | ||
- | 42 | /* USER CODE END PM */ |
|
- | 43 | ||
42 | /* Private variables ---------------------------------------------------------*/ |
44 | /* Private variables ---------------------------------------------------------*/ |
43 | ADC_HandleTypeDef hadc; |
45 | ADC_HandleTypeDef hadc; |
44 | DMA_HandleTypeDef hdma_adc; |
46 | DMA_HandleTypeDef hdma_adc; |
45 | 47 | ||
46 | SPI_HandleTypeDef hspi1; |
48 | SPI_HandleTypeDef hspi1; |
47 | 49 | ||
48 | TIM_HandleTypeDef htim2; |
50 | TIM_HandleTypeDef htim2; |
- | 51 | TIM_HandleTypeDef htim3; |
|
49 | TIM_HandleTypeDef htim6; |
52 | TIM_HandleTypeDef htim6; |
50 | 53 | ||
51 | UART_HandleTypeDef huart1; |
54 | UART_HandleTypeDef huart1; |
52 | UART_HandleTypeDef huart2; |
55 | UART_HandleTypeDef huart2; |
53 | 56 | ||
Line 55... | Line 58... | ||
55 | /* Private variables ---------------------------------------------------------*/ |
58 | /* Private variables ---------------------------------------------------------*/ |
56 | 59 | ||
57 | // with a dwell angle of 45 degrees , 4 cylinders and a maximum RPM of 5000 |
60 | // with a dwell angle of 45 degrees , 4 cylinders and a maximum RPM of 5000 |
58 | // freq = 5000/60 * 2 = 166Hz. Because the breaker might bounce , we accept the first pulse longer than 1/300 of a second as being a proper closure . |
61 | // freq = 5000/60 * 2 = 166Hz. Because the breaker might bounce , we accept the first pulse longer than 1/300 of a second as being a proper closure . |
59 | // the TIM2 counter counts in 10uS increments, |
62 | // the TIM2 counter counts in 10uS increments, |
- | 63 | ||
- | 64 | // TODO this is wrong algo. Accept FIRST pulse, skip shorter pulses |
|
60 | #define BREAKER_MIN (RPM_COUNT_RATE/300) |
65 | #define BREAKER_MIN (RPM_COUNT_RATE/300) |
61 | 66 | ||
- | 67 | #define RPM_AVERAGE 4 |
|
- | 68 | ||
62 | // wait for about 1 second to decide whether or not starter is on |
69 | // wait for about 1 second to decide whether or not starter is on |
63 | 70 | ||
64 | #define STARTER_LIMIT 10 |
71 | #define STARTER_LIMIT 10 |
65 | 72 | ||
66 | volatile char TimerFlag = 0; |
73 | volatile char TimerFlag = 0; |
Line 80... | Line 87... | ||
80 | unsigned int RPM_Count_Latch = 0; |
87 | unsigned int RPM_Count_Latch = 0; |
81 | // accumulators |
88 | // accumulators |
82 | unsigned int RPM_Pulsecount = 0; |
89 | unsigned int RPM_Pulsecount = 0; |
83 | unsigned int RPM_FilteredWidth = 0; |
90 | unsigned int RPM_FilteredWidth = 0; |
84 | 91 | ||
- | 92 | // last time we detected end of dwell i.e. ignition pulse |
|
- | 93 | unsigned int last_dwell_end = 0; |
|
- | 94 | unsigned int RPM_Period[RPM_AVERAGE]; |
|
- | 95 | unsigned int RPM_Period_Ptr = 0; |
|
- | 96 | ||
- | 97 | ||
85 | unsigned int Coded_RPM = 0; |
98 | unsigned int Coded_RPM = 0; |
86 | unsigned int Coded_CHT = 0; |
99 | unsigned int Coded_CHT = 0; |
87 | 100 | ||
88 | uint32_t Power_CHT_Timer; |
101 | uint32_t Power_CHT_Timer; |
89 | 102 | ||
Line 91... | Line 104... | ||
91 | 104 | ||
92 | /* USER CODE END PV */ |
105 | /* USER CODE END PV */ |
93 | 106 | ||
94 | /* Private function prototypes -----------------------------------------------*/ |
107 | /* Private function prototypes -----------------------------------------------*/ |
95 | void SystemClock_Config(void); |
108 | void SystemClock_Config(void); |
96 | void Error_Handler(void); |
- | |
97 | static void MX_GPIO_Init(void); |
109 | static void MX_GPIO_Init(void); |
98 | static void MX_DMA_Init(void); |
110 | static void MX_DMA_Init(void); |
99 | static void MX_ADC_Init(void); |
111 | static void MX_ADC_Init(void); |
100 | static void MX_SPI1_Init(void); |
112 | static void MX_SPI1_Init(void); |
101 | static void MX_TIM2_Init(void); |
113 | static void MX_TIM2_Init(void); |
102 | static void MX_TIM6_Init(void); |
114 | static void MX_TIM6_Init(void); |
103 | static void MX_USART2_UART_Init(void); |
- | |
104 | static void MX_USART1_UART_Init(void); |
115 | static void MX_USART1_UART_Init(void); |
105 | - | ||
- | 116 | static void MX_USART2_UART_Init(void); |
|
- | 117 | static void MX_TIM3_Init(void); |
|
106 | /* USER CODE BEGIN PFP */ |
118 | /* USER CODE BEGIN PFP */ |
107 | /* Private function prototypes -----------------------------------------------*/ |
119 | /* Private function prototypes -----------------------------------------------*/ |
108 | 120 | ||
109 | /* USER CODE END PFP */ |
121 | /* USER CODE END PFP */ |
110 | 122 | ||
- | 123 | /* Private user code ---------------------------------------------------------*/ |
|
111 | /* USER CODE BEGIN 0 */ |
124 | /* USER CODE BEGIN 0 */ |
112 | 125 | ||
113 | void plx_sendword(int x) |
126 | void plx_sendword(int x) |
114 | { |
127 | { |
115 | PutCharSerial(&uc1, ((x) >> 6) & 0x3F); |
128 | PutCharSerial(&uc1, ((x) >> 6) & 0x3F); |
Line 137... | Line 150... | ||
137 | void ProcessRPM(int instance) |
150 | void ProcessRPM(int instance) |
138 | { |
151 | { |
139 | // compute the timer values |
152 | // compute the timer values |
140 | // snapshot timers |
153 | // snapshot timers |
141 | unsigned long RPM_Pulsewidth; |
154 | unsigned long RPM_Pulsewidth; |
- | 155 | // current RPM pulse next slot index |
|
142 | unsigned long RPM_Count_Val; |
156 | unsigned long RPM_Count_Val; |
143 | __disable_irq(); // copy the counter value |
157 | __disable_irq(); // copy the counter value |
144 | RPM_Count_Val = RPM_Count; |
158 | RPM_Count_Val = RPM_Count; |
145 | __enable_irq(); |
159 | __enable_irq(); |
146 | // do calculations |
160 | // do calculations |
Line 150... | Line 164... | ||
150 | while (1) |
164 | while (1) |
151 | { |
165 | { |
152 | unsigned int base_time; |
166 | unsigned int base_time; |
153 | unsigned int new_time; |
167 | unsigned int new_time; |
154 | // if we are at N-1, stop. |
168 | // if we are at N-1, stop. |
155 | unsigned int next_count = RPM_Count_Latch + 1; |
169 | unsigned int next_count = (RPM_Count_Latch + 1) % RPM_SAMPLES; |
156 | if (next_count == RPM_SAMPLES) |
- | |
157 | { |
- | |
158 | next_count = 0; |
- | |
159 | } |
- | |
160 | if (next_count == RPM_Count_Val) |
170 | if (next_count == RPM_Count_Val) |
161 | { |
171 | { |
162 | break; |
172 | break; // completed loop |
163 | } |
173 | } |
- | 174 | char pulse_level = RPM_Level[RPM_Count_Latch]; |
|
164 | base_time = RPM_Time[RPM_Count_Latch]; |
175 | base_time = RPM_Time[RPM_Count_Latch]; |
165 | new_time = RPM_Time[next_count]; |
176 | new_time = RPM_Time[next_count]; |
166 | RPM_Count_Latch = next_count; |
177 | RPM_Count_Latch = next_count; |
167 | if (new_time > base_time) |
- | |
168 | { |
- | |
169 | RPM_Pulsewidth = new_time - base_time; // not wrapped |
- | |
170 | } |
- | |
171 | else |
- | |
172 | { |
- | |
173 | RPM_Pulsewidth = new_time - base_time + 65536; // deal with wrapping |
- | |
174 | } |
- | |
175 | 178 | ||
176 | RPM_Diff += RPM_Pulsewidth; |
179 | RPM_Pulsewidth = new_time - base_time; // not wrapped |
- | 180 | ||
177 | // need to check if this is a long pulse. If it is, keep the answer |
181 | // if the pulse was low, |
178 | if (RPM_Pulsewidth > BREAKER_MIN) |
182 | if(pulse_level == 0 && RPM_Pulsewidth > BREAKER_MIN) |
179 | { |
183 | { |
- | 184 | RPM_Diff = new_time - last_dwell_end; |
|
- | 185 | last_dwell_end = new_time; |
|
- | 186 | ||
- | 187 | ||
- | 188 | RPM_Period[RPM_Period_Ptr] = RPM_Diff; |
|
- | 189 | RPM_Period_Ptr = (RPM_Period_Ptr+1) % RPM_AVERAGE; |
|
- | 190 | if(RPM_Pulsecount < RPM_AVERAGE) |
|
180 | RPM_Pulsecount++; // count one pulse |
191 | RPM_Pulsecount++; // count one pulse |
181 | RPM_FilteredWidth += RPM_Diff; // add its width to the accumulator |
- | |
182 | RPM_Diff = 0; // reset accumulator of all the narrow widths |
- | |
183 | } |
192 | } |
184 | } |
193 | } |
185 | 194 | ||
186 | } |
195 | } |
187 | 196 | ||
188 | if (RPM_Pulsecount > 0) |
197 | if (RPM_Pulsecount == RPM_AVERAGE) |
189 | { |
198 | { |
190 | // now have time for N pulses in clocks |
199 | // now have time for N pulses in clocks |
191 | // need to scale by 19.55: one unit is 19.55 RPM |
200 | // need to scale by 19.55: one unit is 19.55 RPM |
192 | // 1Hz is 60 RPM |
201 | // 1Hz is 60 RPM |
- | 202 | int i; |
|
- | 203 | RPM_FilteredWidth = 0; |
|
- | 204 | for (i=0;i<RPM_AVERAGE;i++) |
|
- | 205 | RPM_FilteredWidth += RPM_Period[i]; |
|
- | 206 | ||
- | 207 | ||
193 | float New_RPM = (30.0 / 19.55 * RPM_Pulsecount * RPM_COUNT_RATE) |
208 | float New_RPM = (30.0 / 19.55 * RPM_Pulsecount * RPM_COUNT_RATE) |
194 | / (RPM_FilteredWidth) + 0.5; |
209 | / (RPM_FilteredWidth) + 0.5; |
195 | // increase RPM filtering |
210 | // increase RPM filtering |
196 | Coded_RPM += (New_RPM * Scale - Coded_RPM) / 8; |
211 | Coded_RPM += (New_RPM * Scale - Coded_RPM) / 8; |
197 | 212 | ||
Line 433... | Line 448... | ||
433 | plx_sendword(64 - 15); // make it negative |
448 | plx_sendword(64 - 15); // make it negative |
434 | } |
449 | } |
435 | 450 | ||
436 | /* USER CODE END 0 */ |
451 | /* USER CODE END 0 */ |
437 | 452 | ||
- | 453 | /** |
|
- | 454 | * @brief The application entry point. |
|
- | 455 | * @retval int |
|
- | 456 | */ |
|
438 | int main(void) |
457 | int main(void) |
439 | { |
458 | { |
440 | - | ||
441 | /* USER CODE BEGIN 1 */ |
459 | /* USER CODE BEGIN 1 */ |
442 | 460 | ||
443 | /* USER CODE END 1 */ |
461 | /* USER CODE END 1 */ |
444 | 462 | ||
445 | /* MCU Configuration----------------------------------------------------------*/ |
463 | /* MCU Configuration--------------------------------------------------------*/ |
446 | 464 | ||
447 | /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ |
465 | /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ |
448 | HAL_Init(); |
466 | HAL_Init(); |
449 | 467 | ||
- | 468 | /* USER CODE BEGIN Init */ |
|
- | 469 | ||
- | 470 | /* USER CODE END Init */ |
|
- | 471 | ||
450 | /* Configure the system clock */ |
472 | /* Configure the system clock */ |
451 | SystemClock_Config(); |
473 | SystemClock_Config(); |
452 | 474 | ||
- | 475 | /* USER CODE BEGIN SysInit */ |
|
- | 476 | ||
- | 477 | /* USER CODE END SysInit */ |
|
- | 478 | ||
453 | /* Initialize all configured peripherals */ |
479 | /* Initialize all configured peripherals */ |
454 | MX_GPIO_Init(); |
480 | MX_GPIO_Init(); |
455 | MX_DMA_Init(); |
481 | MX_DMA_Init(); |
456 | MX_ADC_Init(); |
482 | MX_ADC_Init(); |
457 | MX_SPI1_Init(); |
483 | MX_SPI1_Init(); |
458 | MX_TIM2_Init(); |
484 | MX_TIM2_Init(); |
459 | MX_TIM6_Init(); |
485 | MX_TIM6_Init(); |
460 | MX_USART2_UART_Init(); |
- | |
461 | MX_USART1_UART_Init(); |
486 | MX_USART1_UART_Init(); |
462 | - | ||
- | 487 | MX_USART2_UART_Init(); |
|
- | 488 | MX_TIM3_Init(); |
|
463 | /* USER CODE BEGIN 2 */ |
489 | /* USER CODE BEGIN 2 */ |
464 | HAL_MspInit(); |
490 | HAL_MspInit(); |
465 | 491 | ||
466 | // Not using HAL USART code |
492 | // Not using HAL USART code |
467 | __HAL_RCC_USART1_CLK_ENABLE() |
493 | __HAL_RCC_USART1_CLK_ENABLE() |
Line 507... | Line 533... | ||
507 | 533 | ||
508 | /* Infinite loop */ |
534 | /* Infinite loop */ |
509 | /* USER CODE BEGIN WHILE */ |
535 | /* USER CODE BEGIN WHILE */ |
510 | while (1) |
536 | while (1) |
511 | { |
537 | { |
512 | /* USER CODE END WHILE */ |
538 | /* USER CODE END WHILE */ |
513 | 539 | ||
514 | /* USER CODE BEGIN 3 */ |
540 | /* USER CODE BEGIN 3 */ |
515 | 541 | ||
516 | if (HAL_GetTick() > Ticks) |
542 | if (HAL_GetTick() > Ticks) |
517 | { |
543 | { |
518 | Ticks += 100; |
544 | Ticks += 100; |
519 | filter_ADC_samples(); |
545 | filter_ADC_samples(); |
Line 566... | Line 592... | ||
566 | char send = 0; |
592 | char send = 0; |
567 | 593 | ||
568 | // poll the input for a stop bit or timeout |
594 | // poll the input for a stop bit or timeout |
569 | if (PollSerial(&uc1)) |
595 | if (PollSerial(&uc1)) |
570 | { |
596 | { |
- | 597 | resetSerialTimeout(); |
|
571 | c = GetCharSerial(&uc1); |
598 | c = GetCharSerial(&uc1); |
572 | if (c != PLX_Stop) |
599 | if (c != PLX_Stop) |
573 | { |
600 | { |
574 | PutCharSerial(&uc1, c); // echo all but the stop bit |
601 | PutCharSerial(&uc1, c); // echo all but the stop bit |
575 | } |
602 | } |
Line 610... | Line 637... | ||
610 | 637 | ||
611 | PutCharSerial(&uc1, PLX_Stop); |
638 | PutCharSerial(&uc1, PLX_Stop); |
612 | } |
639 | } |
613 | } |
640 | } |
614 | /* USER CODE END 3 */ |
641 | /* USER CODE END 3 */ |
615 | - | ||
616 | } |
642 | } |
617 | 643 | ||
- | 644 | /** |
|
618 | /** System Clock Configuration |
645 | * @brief System Clock Configuration |
- | 646 | * @retval None |
|
619 | */ |
647 | */ |
620 | void SystemClock_Config(void) |
648 | void SystemClock_Config(void) |
621 | { |
649 | { |
- | 650 | RCC_OscInitTypeDef RCC_OscInitStruct = {0}; |
|
- | 651 | RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; |
|
622 | 652 | ||
623 | RCC_OscInitTypeDef RCC_OscInitStruct; |
- | |
624 | RCC_ClkInitTypeDef RCC_ClkInitStruct; |
653 | /** Configure the main internal regulator output voltage |
625 | 654 | */ |
|
626 | __HAL_RCC_PWR_CLK_ENABLE(); |
- | |
627 | - | ||
628 | __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1); |
655 | __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1); |
- | 656 | /** Initializes the RCC Oscillators according to the specified parameters |
|
- | 657 | * in the RCC_OscInitTypeDef structure. |
|
629 | 658 | */ |
|
630 | RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI; |
659 | RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI; |
631 | RCC_OscInitStruct.HSIState = RCC_HSI_ON; |
660 | RCC_OscInitStruct.HSIState = RCC_HSI_ON; |
632 | RCC_OscInitStruct.HSICalibrationValue = 16; |
661 | RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT; |
633 | RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; |
662 | RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; |
634 | RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI; |
663 | RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI; |
635 | RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL6; |
664 | RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL6; |
636 | RCC_OscInitStruct.PLL.PLLDIV = RCC_PLL_DIV3; |
665 | RCC_OscInitStruct.PLL.PLLDIV = RCC_PLL_DIV3; |
637 | if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) |
666 | if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) |
638 | { |
667 | { |
639 | Error_Handler(); |
668 | Error_Handler(); |
640 | } |
669 | } |
- | 670 | /** Initializes the CPU, AHB and APB buses clocks |
|
641 | 671 | */ |
|
642 | RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK |
672 | RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK |
643 | |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2; |
673 | |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2; |
644 | RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; |
674 | RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; |
645 | RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; |
675 | RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; |
646 | RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1; |
676 | RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1; |
647 | RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; |
677 | RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; |
- | 678 | ||
648 | if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK) |
679 | if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK) |
649 | { |
680 | { |
650 | Error_Handler(); |
681 | Error_Handler(); |
651 | } |
682 | } |
652 | - | ||
653 | HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000); |
- | |
654 | - | ||
655 | HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK); |
- | |
656 | - | ||
657 | /* SysTick_IRQn interrupt configuration */ |
- | |
658 | HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0); |
- | |
659 | } |
683 | } |
660 | 684 | ||
- | 685 | /** |
|
661 | /* ADC init function */ |
686 | * @brief ADC Initialization Function |
- | 687 | * @param None |
|
- | 688 | * @retval None |
|
- | 689 | */ |
|
662 | static void MX_ADC_Init(void) |
690 | static void MX_ADC_Init(void) |
663 | { |
691 | { |
664 | 692 | ||
- | 693 | /* USER CODE BEGIN ADC_Init 0 */ |
|
- | 694 | ||
- | 695 | /* USER CODE END ADC_Init 0 */ |
|
- | 696 | ||
665 | ADC_ChannelConfTypeDef sConfig; |
697 | ADC_ChannelConfTypeDef sConfig = {0}; |
666 | 698 | ||
- | 699 | /* USER CODE BEGIN ADC_Init 1 */ |
|
- | 700 | ||
- | 701 | /* USER CODE END ADC_Init 1 */ |
|
667 | /**Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion) |
702 | /** Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion) |
668 | */ |
703 | */ |
669 | hadc.Instance = ADC1; |
704 | hadc.Instance = ADC1; |
670 | hadc.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV1; |
705 | hadc.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV1; |
671 | hadc.Init.Resolution = ADC_RESOLUTION_12B; |
706 | hadc.Init.Resolution = ADC_RESOLUTION_12B; |
672 | hadc.Init.DataAlign = ADC_DATAALIGN_RIGHT; |
707 | hadc.Init.DataAlign = ADC_DATAALIGN_RIGHT; |
673 | hadc.Init.ScanConvMode = ADC_SCAN_ENABLE; |
708 | hadc.Init.ScanConvMode = ADC_SCAN_ENABLE; |
Line 676... | Line 711... | ||
676 | hadc.Init.LowPowerAutoPowerOff = ADC_AUTOPOWEROFF_DISABLE; |
711 | hadc.Init.LowPowerAutoPowerOff = ADC_AUTOPOWEROFF_DISABLE; |
677 | hadc.Init.ChannelsBank = ADC_CHANNELS_BANK_A; |
712 | hadc.Init.ChannelsBank = ADC_CHANNELS_BANK_A; |
678 | hadc.Init.ContinuousConvMode = DISABLE; |
713 | hadc.Init.ContinuousConvMode = DISABLE; |
679 | hadc.Init.NbrOfConversion = 6; |
714 | hadc.Init.NbrOfConversion = 6; |
680 | hadc.Init.DiscontinuousConvMode = DISABLE; |
715 | hadc.Init.DiscontinuousConvMode = DISABLE; |
681 | hadc.Init.ExternalTrigConv = ADC_EXTERNALTRIGCONV_T6_TRGO; |
716 | hadc.Init.ExternalTrigConv = ADC_EXTERNALTRIGCONV_T3_TRGO; |
682 | hadc.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_RISING; |
717 | hadc.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_RISING; |
683 | hadc.Init.DMAContinuousRequests = ENABLE; |
718 | hadc.Init.DMAContinuousRequests = ENABLE; |
684 | if (HAL_ADC_Init(&hadc) != HAL_OK) |
719 | if (HAL_ADC_Init(&hadc) != HAL_OK) |
685 | { |
720 | { |
686 | Error_Handler(); |
721 | Error_Handler(); |
687 | } |
722 | } |
688 | - | ||
689 | /**Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time. |
723 | /** Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time. |
690 | */ |
724 | */ |
691 | sConfig.Channel = ADC_CHANNEL_10; |
725 | sConfig.Channel = ADC_CHANNEL_10; |
692 | sConfig.Rank = 1; |
726 | sConfig.Rank = ADC_REGULAR_RANK_1; |
693 | sConfig.SamplingTime = ADC_SAMPLETIME_384CYCLES; |
727 | sConfig.SamplingTime = ADC_SAMPLETIME_384CYCLES; |
694 | if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK) |
728 | if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK) |
695 | { |
729 | { |
696 | Error_Handler(); |
730 | Error_Handler(); |
697 | } |
731 | } |
698 | - | ||
699 | /**Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time. |
732 | /** Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time. |
700 | */ |
733 | */ |
701 | sConfig.Channel = ADC_CHANNEL_11; |
734 | sConfig.Channel = ADC_CHANNEL_11; |
702 | sConfig.Rank = 2; |
735 | sConfig.Rank = ADC_REGULAR_RANK_2; |
703 | if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK) |
736 | if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK) |
704 | { |
737 | { |
705 | Error_Handler(); |
738 | Error_Handler(); |
706 | } |
739 | } |
707 | - | ||
708 | /**Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time. |
740 | /** Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time. |
709 | */ |
741 | */ |
710 | sConfig.Channel = ADC_CHANNEL_12; |
742 | sConfig.Channel = ADC_CHANNEL_12; |
711 | sConfig.Rank = 3; |
743 | sConfig.Rank = ADC_REGULAR_RANK_3; |
712 | if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK) |
744 | if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK) |
713 | { |
745 | { |
714 | Error_Handler(); |
746 | Error_Handler(); |
715 | } |
747 | } |
716 | - | ||
717 | /**Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time. |
748 | /** Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time. |
718 | */ |
749 | */ |
719 | sConfig.Channel = ADC_CHANNEL_13; |
750 | sConfig.Channel = ADC_CHANNEL_13; |
720 | sConfig.Rank = 4; |
751 | sConfig.Rank = ADC_REGULAR_RANK_4; |
721 | if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK) |
752 | if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK) |
722 | { |
753 | { |
723 | Error_Handler(); |
754 | Error_Handler(); |
724 | } |
755 | } |
725 | - | ||
726 | /**Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time. |
756 | /** Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time. |
727 | */ |
757 | */ |
728 | sConfig.Channel = ADC_CHANNEL_TEMPSENSOR; |
758 | sConfig.Channel = ADC_CHANNEL_TEMPSENSOR; |
729 | sConfig.Rank = 5; |
759 | sConfig.Rank = ADC_REGULAR_RANK_5; |
730 | if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK) |
760 | if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK) |
731 | { |
761 | { |
732 | Error_Handler(); |
762 | Error_Handler(); |
733 | } |
763 | } |
734 | - | ||
735 | /**Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time. |
764 | /** Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time. |
736 | */ |
765 | */ |
737 | sConfig.Channel = ADC_CHANNEL_VREFINT; |
766 | sConfig.Channel = ADC_CHANNEL_VREFINT; |
738 | sConfig.Rank = 6; |
767 | sConfig.Rank = ADC_REGULAR_RANK_6; |
739 | if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK) |
768 | if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK) |
740 | { |
769 | { |
741 | Error_Handler(); |
770 | Error_Handler(); |
742 | } |
771 | } |
- | 772 | /* USER CODE BEGIN ADC_Init 2 */ |
|
- | 773 | ||
- | 774 | /* USER CODE END ADC_Init 2 */ |
|
743 | 775 | ||
744 | } |
776 | } |
745 | 777 | ||
- | 778 | /** |
|
746 | /* SPI1 init function */ |
779 | * @brief SPI1 Initialization Function |
- | 780 | * @param None |
|
- | 781 | * @retval None |
|
- | 782 | */ |
|
747 | static void MX_SPI1_Init(void) |
783 | static void MX_SPI1_Init(void) |
748 | { |
784 | { |
749 | 785 | ||
- | 786 | /* USER CODE BEGIN SPI1_Init 0 */ |
|
- | 787 | ||
- | 788 | /* USER CODE END SPI1_Init 0 */ |
|
- | 789 | ||
- | 790 | /* USER CODE BEGIN SPI1_Init 1 */ |
|
- | 791 | ||
- | 792 | /* USER CODE END SPI1_Init 1 */ |
|
- | 793 | /* SPI1 parameter configuration*/ |
|
750 | hspi1.Instance = SPI1; |
794 | hspi1.Instance = SPI1; |
751 | hspi1.Init.Mode = SPI_MODE_MASTER; |
795 | hspi1.Init.Mode = SPI_MODE_MASTER; |
752 | hspi1.Init.Direction = SPI_DIRECTION_2LINES; |
796 | hspi1.Init.Direction = SPI_DIRECTION_2LINES; |
753 | hspi1.Init.DataSize = SPI_DATASIZE_8BIT; |
797 | hspi1.Init.DataSize = SPI_DATASIZE_8BIT; |
754 | hspi1.Init.CLKPolarity = SPI_POLARITY_LOW; |
798 | hspi1.Init.CLKPolarity = SPI_POLARITY_LOW; |
Line 761... | Line 805... | ||
761 | hspi1.Init.CRCPolynomial = 10; |
805 | hspi1.Init.CRCPolynomial = 10; |
762 | if (HAL_SPI_Init(&hspi1) != HAL_OK) |
806 | if (HAL_SPI_Init(&hspi1) != HAL_OK) |
763 | { |
807 | { |
764 | Error_Handler(); |
808 | Error_Handler(); |
765 | } |
809 | } |
- | 810 | /* USER CODE BEGIN SPI1_Init 2 */ |
|
- | 811 | ||
- | 812 | /* USER CODE END SPI1_Init 2 */ |
|
766 | 813 | ||
767 | } |
814 | } |
768 | 815 | ||
- | 816 | /** |
|
769 | /* TIM2 init function */ |
817 | * @brief TIM2 Initialization Function |
- | 818 | * @param None |
|
- | 819 | * @retval None |
|
- | 820 | */ |
|
770 | static void MX_TIM2_Init(void) |
821 | static void MX_TIM2_Init(void) |
771 | { |
822 | { |
772 | 823 | ||
773 | TIM_ClockConfigTypeDef sClockSourceConfig; |
- | |
774 | TIM_MasterConfigTypeDef sMasterConfig; |
824 | /* USER CODE BEGIN TIM2_Init 0 */ |
- | 825 | ||
775 | TIM_IC_InitTypeDef sConfigIC; |
826 | /* USER CODE END TIM2_Init 0 */ |
776 | 827 | ||
- | 828 | TIM_ClockConfigTypeDef sClockSourceConfig = {0}; |
|
- | 829 | TIM_MasterConfigTypeDef sMasterConfig = {0}; |
|
- | 830 | TIM_IC_InitTypeDef sConfigIC = {0}; |
|
- | 831 | ||
- | 832 | /* USER CODE BEGIN TIM2_Init 1 */ |
|
- | 833 | ||
- | 834 | /* USER CODE END TIM2_Init 1 */ |
|
777 | htim2.Instance = TIM2; |
835 | htim2.Instance = TIM2; |
778 | htim2.Init.Prescaler = 320; |
836 | htim2.Init.Prescaler = 320; |
779 | htim2.Init.CounterMode = TIM_COUNTERMODE_UP; |
837 | htim2.Init.CounterMode = TIM_COUNTERMODE_UP; |
780 | htim2.Init.Period = 65535; |
838 | htim2.Init.Period = 65535; |
781 | htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; |
839 | htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; |
- | 840 | htim2.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; |
|
782 | if (HAL_TIM_Base_Init(&htim2) != HAL_OK) |
841 | if (HAL_TIM_Base_Init(&htim2) != HAL_OK) |
783 | { |
842 | { |
784 | Error_Handler(); |
843 | Error_Handler(); |
785 | } |
844 | } |
786 | - | ||
787 | sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL; |
845 | sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL; |
788 | if (HAL_TIM_ConfigClockSource(&htim2, &sClockSourceConfig) != HAL_OK) |
846 | if (HAL_TIM_ConfigClockSource(&htim2, &sClockSourceConfig) != HAL_OK) |
789 | { |
847 | { |
790 | Error_Handler(); |
848 | Error_Handler(); |
791 | } |
849 | } |
792 | - | ||
793 | if (HAL_TIM_IC_Init(&htim2) != HAL_OK) |
850 | if (HAL_TIM_IC_Init(&htim2) != HAL_OK) |
794 | { |
851 | { |
795 | Error_Handler(); |
852 | Error_Handler(); |
796 | } |
853 | } |
797 | - | ||
798 | sMasterConfig.MasterOutputTrigger = TIM_TRGO_UPDATE; |
854 | sMasterConfig.MasterOutputTrigger = TIM_TRGO_UPDATE; |
799 | sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; |
855 | sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; |
800 | if (HAL_TIMEx_MasterConfigSynchronization(&htim2, &sMasterConfig) != HAL_OK) |
856 | if (HAL_TIMEx_MasterConfigSynchronization(&htim2, &sMasterConfig) != HAL_OK) |
801 | { |
857 | { |
802 | Error_Handler(); |
858 | Error_Handler(); |
803 | } |
859 | } |
804 | - | ||
805 | sConfigIC.ICPolarity = TIM_INPUTCHANNELPOLARITY_RISING; |
860 | sConfigIC.ICPolarity = TIM_INPUTCHANNELPOLARITY_BOTHEDGE; |
806 | sConfigIC.ICSelection = TIM_ICSELECTION_DIRECTTI; |
861 | sConfigIC.ICSelection = TIM_ICSELECTION_DIRECTTI; |
807 | sConfigIC.ICPrescaler = TIM_ICPSC_DIV1; |
862 | sConfigIC.ICPrescaler = TIM_ICPSC_DIV1; |
808 | sConfigIC.ICFilter = 0; |
863 | sConfigIC.ICFilter = 15; |
809 | if (HAL_TIM_IC_ConfigChannel(&htim2, &sConfigIC, TIM_CHANNEL_1) != HAL_OK) |
864 | if (HAL_TIM_IC_ConfigChannel(&htim2, &sConfigIC, TIM_CHANNEL_1) != HAL_OK) |
810 | { |
865 | { |
811 | Error_Handler(); |
866 | Error_Handler(); |
812 | } |
867 | } |
- | 868 | /* USER CODE BEGIN TIM2_Init 2 */ |
|
- | 869 | ||
- | 870 | /* USER CODE END TIM2_Init 2 */ |
|
- | 871 | ||
- | 872 | } |
|
- | 873 | ||
- | 874 | /** |
|
- | 875 | * @brief TIM3 Initialization Function |
|
- | 876 | * @param None |
|
- | 877 | * @retval None |
|
- | 878 | */ |
|
- | 879 | static void MX_TIM3_Init(void) |
|
- | 880 | { |
|
- | 881 | ||
- | 882 | /* USER CODE BEGIN TIM3_Init 0 */ |
|
- | 883 | ||
- | 884 | /* USER CODE END TIM3_Init 0 */ |
|
- | 885 | ||
- | 886 | TIM_ClockConfigTypeDef sClockSourceConfig = {0}; |
|
- | 887 | TIM_MasterConfigTypeDef sMasterConfig = {0}; |
|
- | 888 | ||
- | 889 | /* USER CODE BEGIN TIM3_Init 1 */ |
|
- | 890 | ||
- | 891 | /* USER CODE END TIM3_Init 1 */ |
|
- | 892 | htim3.Instance = TIM3; |
|
- | 893 | htim3.Init.Prescaler = 320; |
|
- | 894 | htim3.Init.CounterMode = TIM_COUNTERMODE_UP; |
|
- | 895 | htim3.Init.Period = 0; |
|
- | 896 | htim3.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; |
|
- | 897 | htim3.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; |
|
- | 898 | if (HAL_TIM_Base_Init(&htim3) != HAL_OK) |
|
- | 899 | { |
|
- | 900 | Error_Handler(); |
|
- | 901 | } |
|
- | 902 | sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL; |
|
- | 903 | if (HAL_TIM_ConfigClockSource(&htim3, &sClockSourceConfig) != HAL_OK) |
|
- | 904 | { |
|
- | 905 | Error_Handler(); |
|
- | 906 | } |
|
- | 907 | if (HAL_TIM_OnePulse_Init(&htim3, TIM_OPMODE_SINGLE) != HAL_OK) |
|
- | 908 | { |
|
- | 909 | Error_Handler(); |
|
- | 910 | } |
|
- | 911 | sMasterConfig.MasterOutputTrigger = TIM_TRGO_OC1REF; |
|
- | 912 | sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; |
|
- | 913 | if (HAL_TIMEx_MasterConfigSynchronization(&htim3, &sMasterConfig) != HAL_OK) |
|
- | 914 | { |
|
- | 915 | Error_Handler(); |
|
- | 916 | } |
|
- | 917 | /* USER CODE BEGIN TIM3_Init 2 */ |
|
- | 918 | ||
- | 919 | /* USER CODE END TIM3_Init 2 */ |
|
813 | 920 | ||
814 | } |
921 | } |
815 | 922 | ||
- | 923 | /** |
|
816 | /* TIM6 init function */ |
924 | * @brief TIM6 Initialization Function |
- | 925 | * @param None |
|
- | 926 | * @retval None |
|
- | 927 | */ |
|
817 | static void MX_TIM6_Init(void) |
928 | static void MX_TIM6_Init(void) |
818 | { |
929 | { |
819 | 930 | ||
- | 931 | /* USER CODE BEGIN TIM6_Init 0 */ |
|
- | 932 | ||
820 | TIM_MasterConfigTypeDef sMasterConfig; |
933 | /* USER CODE END TIM6_Init 0 */ |
821 | 934 | ||
- | 935 | TIM_MasterConfigTypeDef sMasterConfig = {0}; |
|
- | 936 | ||
- | 937 | /* USER CODE BEGIN TIM6_Init 1 */ |
|
- | 938 | ||
- | 939 | /* USER CODE END TIM6_Init 1 */ |
|
822 | htim6.Instance = TIM6; |
940 | htim6.Instance = TIM6; |
823 | htim6.Init.Prescaler = 320; |
941 | htim6.Init.Prescaler = 320; |
824 | htim6.Init.CounterMode = TIM_COUNTERMODE_UP; |
942 | htim6.Init.CounterMode = TIM_COUNTERMODE_UP; |
825 | htim6.Init.Period = 9999; |
943 | htim6.Init.Period = 9999; |
- | 944 | htim6.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; |
|
826 | if (HAL_TIM_Base_Init(&htim6) != HAL_OK) |
945 | if (HAL_TIM_Base_Init(&htim6) != HAL_OK) |
827 | { |
946 | { |
828 | Error_Handler(); |
947 | Error_Handler(); |
829 | } |
948 | } |
830 | - | ||
831 | sMasterConfig.MasterOutputTrigger = TIM_TRGO_UPDATE; |
949 | sMasterConfig.MasterOutputTrigger = TIM_TRGO_UPDATE; |
832 | sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; |
950 | sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; |
833 | if (HAL_TIMEx_MasterConfigSynchronization(&htim6, &sMasterConfig) != HAL_OK) |
951 | if (HAL_TIMEx_MasterConfigSynchronization(&htim6, &sMasterConfig) != HAL_OK) |
834 | { |
952 | { |
835 | Error_Handler(); |
953 | Error_Handler(); |
836 | } |
954 | } |
- | 955 | /* USER CODE BEGIN TIM6_Init 2 */ |
|
- | 956 | ||
- | 957 | /* USER CODE END TIM6_Init 2 */ |
|
837 | 958 | ||
838 | } |
959 | } |
839 | 960 | ||
- | 961 | /** |
|
840 | /* USART1 init function */ |
962 | * @brief USART1 Initialization Function |
- | 963 | * @param None |
|
- | 964 | * @retval None |
|
- | 965 | */ |
|
841 | static void MX_USART1_UART_Init(void) |
966 | static void MX_USART1_UART_Init(void) |
842 | { |
967 | { |
843 | 968 | ||
- | 969 | /* USER CODE BEGIN USART1_Init 0 */ |
|
- | 970 | ||
- | 971 | /* USER CODE END USART1_Init 0 */ |
|
- | 972 | ||
- | 973 | /* USER CODE BEGIN USART1_Init 1 */ |
|
- | 974 | ||
- | 975 | /* USER CODE END USART1_Init 1 */ |
|
844 | huart1.Instance = USART1; |
976 | huart1.Instance = USART1; |
845 | huart1.Init.BaudRate = 19200; |
977 | huart1.Init.BaudRate = 19200; |
846 | huart1.Init.WordLength = UART_WORDLENGTH_8B; |
978 | huart1.Init.WordLength = UART_WORDLENGTH_8B; |
847 | huart1.Init.StopBits = UART_STOPBITS_1; |
979 | huart1.Init.StopBits = UART_STOPBITS_1; |
848 | huart1.Init.Parity = UART_PARITY_NONE; |
980 | huart1.Init.Parity = UART_PARITY_NONE; |
Line 851... | Line 983... | ||
851 | huart1.Init.OverSampling = UART_OVERSAMPLING_16; |
983 | huart1.Init.OverSampling = UART_OVERSAMPLING_16; |
852 | if (HAL_UART_Init(&huart1) != HAL_OK) |
984 | if (HAL_UART_Init(&huart1) != HAL_OK) |
853 | { |
985 | { |
854 | Error_Handler(); |
986 | Error_Handler(); |
855 | } |
987 | } |
- | 988 | /* USER CODE BEGIN USART1_Init 2 */ |
|
- | 989 | ||
- | 990 | /* USER CODE END USART1_Init 2 */ |
|
856 | 991 | ||
857 | } |
992 | } |
858 | 993 | ||
- | 994 | /** |
|
859 | /* USART2 init function */ |
995 | * @brief USART2 Initialization Function |
- | 996 | * @param None |
|
- | 997 | * @retval None |
|
- | 998 | */ |
|
860 | static void MX_USART2_UART_Init(void) |
999 | static void MX_USART2_UART_Init(void) |
861 | { |
1000 | { |
862 | 1001 | ||
- | 1002 | /* USER CODE BEGIN USART2_Init 0 */ |
|
- | 1003 | ||
- | 1004 | /* USER CODE END USART2_Init 0 */ |
|
- | 1005 | ||
- | 1006 | /* USER CODE BEGIN USART2_Init 1 */ |
|
- | 1007 | ||
- | 1008 | /* USER CODE END USART2_Init 1 */ |
|
863 | huart2.Instance = USART2; |
1009 | huart2.Instance = USART2; |
864 | huart2.Init.BaudRate = 115200; |
1010 | huart2.Init.BaudRate = 115200; |
865 | huart2.Init.WordLength = UART_WORDLENGTH_8B; |
1011 | huart2.Init.WordLength = UART_WORDLENGTH_8B; |
866 | huart2.Init.StopBits = UART_STOPBITS_1; |
1012 | huart2.Init.StopBits = UART_STOPBITS_1; |
867 | huart2.Init.Parity = UART_PARITY_NONE; |
1013 | huart2.Init.Parity = UART_PARITY_NONE; |
Line 870... | Line 1016... | ||
870 | huart2.Init.OverSampling = UART_OVERSAMPLING_16; |
1016 | huart2.Init.OverSampling = UART_OVERSAMPLING_16; |
871 | if (HAL_UART_Init(&huart2) != HAL_OK) |
1017 | if (HAL_UART_Init(&huart2) != HAL_OK) |
872 | { |
1018 | { |
873 | Error_Handler(); |
1019 | Error_Handler(); |
874 | } |
1020 | } |
- | 1021 | /* USER CODE BEGIN USART2_Init 2 */ |
|
- | 1022 | ||
- | 1023 | /* USER CODE END USART2_Init 2 */ |
|
875 | 1024 | ||
876 | } |
1025 | } |
877 | 1026 | ||
878 | /** |
1027 | /** |
879 | * Enable DMA controller clock |
1028 | * Enable DMA controller clock |
880 | */ |
1029 | */ |
881 | static void MX_DMA_Init(void) |
1030 | static void MX_DMA_Init(void) |
882 | { |
1031 | { |
- | 1032 | ||
883 | /* DMA controller clock enable */ |
1033 | /* DMA controller clock enable */ |
884 | __HAL_RCC_DMA1_CLK_ENABLE(); |
1034 | __HAL_RCC_DMA1_CLK_ENABLE(); |
885 | 1035 | ||
886 | /* DMA interrupt init */ |
1036 | /* DMA interrupt init */ |
887 | /* DMA1_Channel1_IRQn interrupt configuration */ |
1037 | /* DMA1_Channel1_IRQn interrupt configuration */ |
888 | HAL_NVIC_SetPriority(DMA1_Channel1_IRQn, 0, 0); |
1038 | HAL_NVIC_SetPriority(DMA1_Channel1_IRQn, 0, 0); |
889 | HAL_NVIC_EnableIRQ(DMA1_Channel1_IRQn); |
1039 | HAL_NVIC_EnableIRQ(DMA1_Channel1_IRQn); |
890 | 1040 | ||
891 | } |
1041 | } |
892 | 1042 | ||
893 | /** Configure pins as |
1043 | /** |
894 | * Analog |
1044 | * @brief GPIO Initialization Function |
895 | * Input |
1045 | * @param None |
896 | * Output |
- | |
897 | * EVENT_OUT |
- | |
898 | * EXTI |
1046 | * @retval None |
899 | * Free pins are configured automatically as Analog (this feature is enabled through |
- | |
900 | * the Code Generation settings) |
- | |
901 | */ |
1047 | */ |
902 | static void MX_GPIO_Init(void) |
1048 | static void MX_GPIO_Init(void) |
903 | { |
1049 | { |
904 | - | ||
905 | GPIO_InitTypeDef GPIO_InitStruct; |
1050 | GPIO_InitTypeDef GPIO_InitStruct = {0}; |
906 | 1051 | ||
907 | /* GPIO Ports Clock Enable */ |
1052 | /* GPIO Ports Clock Enable */ |
908 | __HAL_RCC_GPIOC_CLK_ENABLE(); |
1053 | __HAL_RCC_GPIOC_CLK_ENABLE(); |
909 | __HAL_RCC_GPIOH_CLK_ENABLE(); |
1054 | __HAL_RCC_GPIOH_CLK_ENABLE(); |
910 | __HAL_RCC_GPIOA_CLK_ENABLE(); |
1055 | __HAL_RCC_GPIOA_CLK_ENABLE(); |
911 | __HAL_RCC_GPIOB_CLK_ENABLE(); |
1056 | __HAL_RCC_GPIOB_CLK_ENABLE(); |
912 | __HAL_RCC_GPIOD_CLK_ENABLE(); |
1057 | __HAL_RCC_GPIOD_CLK_ENABLE(); |
913 | 1058 | ||
- | 1059 | /*Configure GPIO pin Output Level */ |
|
- | 1060 | HAL_GPIO_WritePin(LED_Blink_GPIO_Port, LED_Blink_Pin, GPIO_PIN_RESET); |
|
- | 1061 | ||
- | 1062 | /*Configure GPIO pin Output Level */ |
|
- | 1063 | HAL_GPIO_WritePin(SPI_NSS1_GPIO_Port, SPI_NSS1_Pin, GPIO_PIN_SET); |
|
- | 1064 | ||
- | 1065 | /*Configure GPIO pin Output Level */ |
|
- | 1066 | HAL_GPIO_WritePin(SPI_CD_GPIO_Port, SPI_CD_Pin, GPIO_PIN_RESET); |
|
- | 1067 | ||
- | 1068 | /*Configure GPIO pin Output Level */ |
|
- | 1069 | HAL_GPIO_WritePin(GPIOB, SPI_RESET_Pin|SPI_NS_Temp2_Pin|ENA_AUX_5V_Pin, GPIO_PIN_RESET); |
|
- | 1070 | ||
- | 1071 | /*Configure GPIO pin Output Level */ |
|
- | 1072 | HAL_GPIO_WritePin(SPI_NS_Temp_GPIO_Port, SPI_NS_Temp_Pin, GPIO_PIN_SET); |
|
- | 1073 | ||
914 | /*Configure GPIO pins : PC13 PC14 PC15 PC6 |
1074 | /*Configure GPIO pins : PC13 PC14 PC15 PC6 |
915 | PC7 PC8 PC9 PC11 |
1075 | PC7 PC8 PC9 PC11 |
916 | PC12 */ |
1076 | PC12 */ |
917 | GPIO_InitStruct.Pin = GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15|GPIO_PIN_6 |
1077 | GPIO_InitStruct.Pin = GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15|GPIO_PIN_6 |
918 | |GPIO_PIN_7|GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_11 |
1078 | |GPIO_PIN_7|GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_11 |
919 | |GPIO_PIN_12; |
1079 | |GPIO_PIN_12; |
920 | GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; |
1080 | GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; |
921 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
1081 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
922 | HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); |
1082 | HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); |
923 | 1083 | ||
Line 925... | Line 1085... | ||
925 | GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1; |
1085 | GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1; |
926 | GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; |
1086 | GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; |
927 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
1087 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
928 | HAL_GPIO_Init(GPIOH, &GPIO_InitStruct); |
1088 | HAL_GPIO_Init(GPIOH, &GPIO_InitStruct); |
929 | 1089 | ||
930 | /*Configure GPIO pins : PA0 PA1 PA8 PA11 |
1090 | /*Configure GPIO pins : PA0 PA1 PA8 PA11 |
931 | PA12 */ |
1091 | PA12 */ |
932 | GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_8|GPIO_PIN_11 |
1092 | GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_8|GPIO_PIN_11 |
933 | |GPIO_PIN_12; |
1093 | |GPIO_PIN_12; |
934 | GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; |
1094 | GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; |
935 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
1095 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
936 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
1096 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
937 | 1097 | ||
Line 940... | Line 1100... | ||
940 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; |
1100 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; |
941 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
1101 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
942 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; |
1102 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; |
943 | HAL_GPIO_Init(LED_Blink_GPIO_Port, &GPIO_InitStruct); |
1103 | HAL_GPIO_Init(LED_Blink_GPIO_Port, &GPIO_InitStruct); |
944 | 1104 | ||
945 | /*Configure GPIO pins : SPI_NSS1_Pin SPI1CD_Pin */ |
1105 | /*Configure GPIO pins : SPI_NSS1_Pin SPI_CD_Pin */ |
946 | GPIO_InitStruct.Pin = SPI_NSS1_Pin|SPI1CD_Pin; |
1106 | GPIO_InitStruct.Pin = SPI_NSS1_Pin|SPI_CD_Pin; |
947 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; |
1107 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; |
948 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
1108 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
949 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; |
1109 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; |
950 | HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); |
1110 | HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); |
951 | 1111 | ||
Line 954... | Line 1114... | ||
954 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; |
1114 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; |
955 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
1115 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
956 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; |
1116 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; |
957 | HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); |
1117 | HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); |
958 | 1118 | ||
959 | /*Configure GPIO pins : PB11 PB12 PB13 PB14 |
1119 | /*Configure GPIO pins : PB11 PB12 PB13 PB14 |
960 | PB15 PB3 PB4 PB5 |
1120 | PB15 PB3 PB4 PB5 |
961 | PB6 PB7 PB8 PB9 */ |
1121 | PB6 PB7 PB8 PB9 */ |
962 | GPIO_InitStruct.Pin = GPIO_PIN_11|GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14 |
1122 | GPIO_InitStruct.Pin = GPIO_PIN_11|GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14 |
963 | |GPIO_PIN_15|GPIO_PIN_3|GPIO_PIN_4|GPIO_PIN_5 |
1123 | |GPIO_PIN_15|GPIO_PIN_3|GPIO_PIN_4|GPIO_PIN_5 |
964 | |GPIO_PIN_6|GPIO_PIN_7|GPIO_PIN_8|GPIO_PIN_9; |
1124 | |GPIO_PIN_6|GPIO_PIN_7|GPIO_PIN_8|GPIO_PIN_9; |
965 | GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; |
1125 | GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; |
966 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
1126 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
967 | HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); |
1127 | HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); |
968 | 1128 | ||
Line 976... | Line 1136... | ||
976 | GPIO_InitStruct.Pin = GPIO_PIN_2; |
1136 | GPIO_InitStruct.Pin = GPIO_PIN_2; |
977 | GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; |
1137 | GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; |
978 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
1138 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
979 | HAL_GPIO_Init(GPIOD, &GPIO_InitStruct); |
1139 | HAL_GPIO_Init(GPIOD, &GPIO_InitStruct); |
980 | 1140 | ||
981 | /*Configure GPIO pin Output Level */ |
- | |
982 | HAL_GPIO_WritePin(LED_Blink_GPIO_Port, LED_Blink_Pin, GPIO_PIN_RESET); |
- | |
983 | - | ||
984 | /*Configure GPIO pin Output Level */ |
- | |
985 | HAL_GPIO_WritePin(SPI_NSS1_GPIO_Port, SPI_NSS1_Pin, GPIO_PIN_SET); |
- | |
986 | - | ||
987 | /*Configure GPIO pin Output Level */ |
- | |
988 | HAL_GPIO_WritePin(SPI1CD_GPIO_Port, SPI1CD_Pin, GPIO_PIN_RESET); |
- | |
989 | - | ||
990 | /*Configure GPIO pin Output Level */ |
- | |
991 | HAL_GPIO_WritePin(GPIOB, SPI_RESET_Pin|SPI_NS_Temp2_Pin|ENA_AUX_5V_Pin, GPIO_PIN_RESET); |
- | |
992 | - | ||
993 | /*Configure GPIO pin Output Level */ |
- | |
994 | HAL_GPIO_WritePin(SPI_NS_Temp_GPIO_Port, SPI_NS_Temp_Pin, GPIO_PIN_SET); |
- | |
995 | - | ||
996 | } |
1141 | } |
997 | 1142 | ||
998 | /* USER CODE BEGIN 4 */ |
1143 | /* USER CODE BEGIN 4 */ |
999 | 1144 | ||
1000 | /* USER CODE END 4 */ |
1145 | /* USER CODE END 4 */ |
1001 | 1146 | ||
1002 | /** |
1147 | /** |
1003 | * @brief This function is executed in case of error occurrence. |
1148 | * @brief This function is executed in case of error occurrence. |
1004 | * @param None |
- | |
1005 | * @retval None |
1149 | * @retval None |
1006 | */ |
1150 | */ |
1007 | void Error_Handler(void) |
1151 | void Error_Handler(void) |
1008 | { |
1152 | { |
1009 | /* USER CODE BEGIN Error_Handler */ |
1153 | /* USER CODE BEGIN Error_Handler_Debug */ |
1010 | /* User can add his own implementation to report the HAL error return state */ |
1154 | /* User can add his own implementation to report the HAL error return state */ |
1011 | while (1) |
- | |
1012 | { |
- | |
1013 | } |
- | |
1014 | /* USER CODE END Error_Handler */ |
- | |
1015 | } |
- | |
1016 | 1155 | ||
1017 | #ifdef USE_FULL_ASSERT |
1156 | /* USER CODE END Error_Handler_Debug */ |
- | 1157 | } |
|
1018 | 1158 | ||
- | 1159 | #ifdef USE_FULL_ASSERT |
|
1019 | /** |
1160 | /** |
1020 | * @brief Reports the name of the source file and the source line number |
1161 | * @brief Reports the name of the source file and the source line number |
1021 | * where the assert_param error has occurred. |
1162 | * where the assert_param error has occurred. |
1022 | * @param file: pointer to the source file name |
1163 | * @param file: pointer to the source file name |
1023 | * @param line: assert_param error line source number |
1164 | * @param line: assert_param error line source number |
1024 | * @retval None |
1165 | * @retval None |
1025 | */ |
1166 | */ |
1026 | void assert_failed(uint8_t* file, uint32_t line) |
1167 | void assert_failed(uint8_t *file, uint32_t line) |
1027 | { |
1168 | { |
1028 | /* USER CODE BEGIN 6 */ |
1169 | /* USER CODE BEGIN 6 */ |
1029 | /* User can add his own implementation to report the file name and line number, |
1170 | /* User can add his own implementation to report the file name and line number, |
1030 | ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ |
1171 | ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ |
1031 | /* USER CODE END 6 */ |
1172 | /* USER CODE END 6 */ |
1032 | - | ||
1033 | } |
1173 | } |
1034 | - | ||
1035 | #endif |
1174 | #endif /* USE_FULL_ASSERT */ |
1036 | - | ||
1037 | /** |
- | |
1038 | * @} |
- | |
1039 | */ |
- | |
1040 | - | ||
1041 | /** |
- | |
1042 | * @} |
- | |
1043 | */ |
- | |
1044 | 1175 | ||
1045 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
1176 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |