Rev 45 | Rev 47 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 45 | Rev 46 | ||
|---|---|---|---|
| Line 50... | Line 50... | ||
| 50 | #define ADC_TEMP_CHAN 6 |
50 | #define ADC_TEMP_CHAN 6 |
| 51 | 51 | ||
| 52 | // with a dwell angle of 45 degrees , 4 cylinders and a maximum RPM of 5000 |
52 | // with a dwell angle of 45 degrees , 4 cylinders and a maximum RPM of 5000 |
| 53 | // freq = 5000/60 * 2 = 166Hz. |
53 | // freq = 5000/60 * 2 = 166Hz. |
| 54 | // the TIM2 counter counts in 10uS increments, |
54 | // the TIM2 counter counts in 10uS increments, |
| 55 | // TODO this is wrong algo. Accept FIRST pulse, skip shorter pulses |
- | |
| 56 | // Accept the first pulse with over 1ms (1/1000 sec) duration as the closure |
55 | // Need to accumulate low level for a 400th of a second before accepting it as a pulse |
| 57 | #define BREAKER_MIN (RPM_COUNT_RATE / 1000) |
56 | #define ACCUM_MAX (RPM_COUNT_RATE / 500) |
| 58 | 57 | ||
| 59 | #define RPM_AVERAGE 4 |
58 | #define RPM_AVERAGE 4 |
| 60 | 59 | ||
| 61 | // wait for about 1 second to decide whether or not starter is on |
60 | // wait for about 1 second to decide whether or not starter is on |
| 62 | 61 | ||
| 63 | #define STARTER_LIMIT 10 |
62 | #define STARTER_LIMIT 10 |
| 64 | 63 | ||
| 65 | /* USER CODE END PM */ |
64 | /* USER CODE END PM */ |
| 66 | 65 | ||
| 67 | /* Private variables ---------------------------------------------------------*/ |
66 | /* Private variables ---------------------------------------------------------*/ |
| 68 | ADC_HandleTypeDef hadc1; |
67 | ADC_HandleTypeDef hadc1; |
| 69 | DMA_HandleTypeDef hdma_adc1; |
68 | DMA_HandleTypeDef hdma_adc1; |
| 70 | 69 | ||
| 71 | CAN_HandleTypeDef hcan; |
70 | CAN_HandleTypeDef hcan; |
| 72 | 71 | ||
| 73 | SPI_HandleTypeDef hspi1; |
72 | SPI_HandleTypeDef hspi1; |
| Line 177... | Line 176... | ||
| 177 | // compute the timer values |
176 | // compute the timer values |
| 178 | // snapshot timers |
177 | // snapshot timers |
| 179 | unsigned short RPM_Pulsewidth; |
178 | unsigned short RPM_Pulsewidth; |
| 180 | // current RPM pulse next slot index |
179 | // current RPM pulse next slot index |
| 181 | unsigned short RPM_Count_Val; |
180 | unsigned short RPM_Count_Val; |
| - | 181 | ||
| - | 182 | // accumulator for pulse widths |
|
| - | 183 | unsigned short RPM_Accumulator = ACCUM_MAX; |
|
| - | 184 | // Next state of pulse high/low |
|
| - | 185 | unsigned char RPM_State = 1; |
|
| - | 186 | // Current state of pulse high/low |
|
| - | 187 | unsigned char RPM_State_Curr = 1; |
|
| - | 188 | ||
| 182 | __disable_irq(); // copy the counter value |
189 | __disable_irq(); // copy the counter value |
| 183 | RPM_Count_Val = RPM_Count; |
190 | RPM_Count_Val = RPM_Count; |
| 184 | __enable_irq(); |
191 | __enable_irq(); |
| 185 | // do calculations |
192 | // do calculations |
| - | 193 | ||
| 186 | // if there is only one entry, cannot get difference |
194 | // if there is only one entry, cannot get difference |
| 187 | if (RPM_Count_Latch != RPM_Count_Val) |
195 | if (RPM_Count_Latch != RPM_Count_Val) |
| 188 | { |
196 | { |
| 189 | while (1) |
197 | while (1) |
| 190 | { |
198 | { |
| Line 200... | Line 208... | ||
| 200 | base_time = RPM_Time[RPM_Count_Latch]; |
208 | base_time = RPM_Time[RPM_Count_Latch]; |
| 201 | new_time = RPM_Time[next_count]; |
209 | new_time = RPM_Time[next_count]; |
| 202 | RPM_Count_Latch = next_count; |
210 | RPM_Count_Latch = next_count; |
| 203 | 211 | ||
| 204 | RPM_Pulsewidth = new_time - base_time; // not wrapped |
212 | RPM_Pulsewidth = new_time - base_time; // not wrapped |
| 205 | - | ||
| - | 213 | RPM_State_Curr = RPM_State; |
|
| 206 | // if the pulse was low, |
214 | // Count up/down |
| 207 | if (pulse_level == 0 && RPM_Pulsewidth > BREAKER_MIN) |
215 | if (pulse_level == 0) |
| 208 | { |
216 | { |
| - | 217 | int next = RPM_Accumulator - RPM_Pulsewidth; |
|
| - | 218 | if (next < 0) // going to cross zero |
|
| - | 219 | { |
|
| - | 220 | RPM_State = 0; |
|
| - | 221 | RPM_Accumulator = 0; |
|
| - | 222 | } |
|
| - | 223 | else |
|
| - | 224 | { |
|
| - | 225 | RPM_Accumulator = next; |
|
| - | 226 | } |
|
| - | 227 | } |
|
| - | 228 | else |
|
| - | 229 | { |
|
| - | 230 | int next = RPM_Accumulator + RPM_Pulsewidth; |
|
| - | 231 | if (next > ACCUM_MAX) |
|
| - | 232 | { |
|
| - | 233 | RPM_State = 1; |
|
| - | 234 | RPM_Accumulator = ACCUM_MAX; |
|
| - | 235 | } |
|
| - | 236 | else |
|
| - | 237 | { |
|
| - | 238 | RPM_Accumulator = next; |
|
| - | 239 | } |
|
| - | 240 | } |
|
| 209 | 241 | ||
| - | 242 | // low pulse has reached at least minimum width, count it. |
|
| - | 243 | if ((RPM_State == 0) && (RPM_State_Curr = 1)) |
|
| - | 244 | { |
|
| 210 | RPM_Diff = new_time - last_dwell_end; |
245 | RPM_Diff = new_time - last_dwell_end; |
| 211 | 246 | ||
| 212 | RPM_Period[RPM_Period_Ptr] = RPM_Diff; |
247 | RPM_Period[RPM_Period_Ptr] = RPM_Diff; |
| 213 | RPM_Period_Ptr = (RPM_Period_Ptr + 1) % RPM_AVERAGE; |
248 | RPM_Period_Ptr = (RPM_Period_Ptr + 1) % RPM_AVERAGE; |
| 214 | if (RPM_Pulsecount < RPM_AVERAGE) |
249 | if (RPM_Pulsecount < RPM_AVERAGE) |
| Line 417... | Line 452... | ||
| 417 | } |
452 | } |
| 418 | 453 | ||
| 419 | /* USER CODE END 0 */ |
454 | /* USER CODE END 0 */ |
| 420 | 455 | ||
| 421 | /** |
456 | /** |
| 422 | * @brief The application entry point. |
457 | * @brief The application entry point. |
| 423 | * @retval int |
458 | * @retval int |
| 424 | */ |
459 | */ |
| 425 | int main(void) |
460 | int main(void) |
| 426 | { |
461 | { |
| 427 | /* USER CODE BEGIN 1 */ |
462 | /* USER CODE BEGIN 1 */ |
| 428 | 463 | ||
| 429 | /* USER CODE END 1 */ |
464 | /* USER CODE END 1 */ |
| Line 601... | Line 636... | ||
| 601 | 636 | ||
| 602 | /* USER CODE END 3 */ |
637 | /* USER CODE END 3 */ |
| 603 | } |
638 | } |
| 604 | 639 | ||
| 605 | /** |
640 | /** |
| 606 | * @brief System Clock Configuration |
641 | * @brief System Clock Configuration |
| 607 | * @retval None |
642 | * @retval None |
| 608 | */ |
643 | */ |
| 609 | void SystemClock_Config(void) |
644 | void SystemClock_Config(void) |
| 610 | { |
645 | { |
| 611 | RCC_OscInitTypeDef RCC_OscInitStruct = {0}; |
646 | RCC_OscInitTypeDef RCC_OscInitStruct = {0}; |
| 612 | RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; |
647 | RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; |
| 613 | RCC_PeriphCLKInitTypeDef PeriphClkInit = {0}; |
648 | RCC_PeriphCLKInitTypeDef PeriphClkInit = {0}; |
| 614 | 649 | ||
| 615 | /** Initializes the RCC Oscillators according to the specified parameters |
650 | /** Initializes the RCC Oscillators according to the specified parameters |
| 616 | * in the RCC_OscInitTypeDef structure. |
651 | * in the RCC_OscInitTypeDef structure. |
| 617 | */ |
652 | */ |
| 618 | RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; |
653 | RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; |
| 619 | RCC_OscInitStruct.HSEState = RCC_HSE_ON; |
654 | RCC_OscInitStruct.HSEState = RCC_HSE_ON; |
| 620 | RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1; |
655 | RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1; |
| 621 | RCC_OscInitStruct.HSIState = RCC_HSI_ON; |
656 | RCC_OscInitStruct.HSIState = RCC_HSI_ON; |
| 622 | RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; |
657 | RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; |
| Line 626... | Line 661... | ||
| 626 | { |
661 | { |
| 627 | Error_Handler(); |
662 | Error_Handler(); |
| 628 | } |
663 | } |
| 629 | 664 | ||
| 630 | /** Initializes the CPU, AHB and APB buses clocks |
665 | /** Initializes the CPU, AHB and APB buses clocks |
| 631 | */ |
666 | */ |
| 632 | RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK |
667 | RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2; |
| 633 | |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2; |
- | |
| 634 | RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; |
668 | RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; |
| 635 | RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; |
669 | RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; |
| 636 | RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2; |
670 | RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2; |
| 637 | RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; |
671 | RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; |
| 638 | 672 | ||
| Line 647... | Line 681... | ||
| 647 | Error_Handler(); |
681 | Error_Handler(); |
| 648 | } |
682 | } |
| 649 | } |
683 | } |
| 650 | 684 | ||
| 651 | /** |
685 | /** |
| 652 | * @brief ADC1 Initialization Function |
686 | * @brief ADC1 Initialization Function |
| 653 | * @param None |
687 | * @param None |
| 654 | * @retval None |
688 | * @retval None |
| 655 | */ |
689 | */ |
| 656 | static void MX_ADC1_Init(void) |
690 | static void MX_ADC1_Init(void) |
| 657 | { |
691 | { |
| 658 | 692 | ||
| 659 | /* USER CODE BEGIN ADC1_Init 0 */ |
693 | /* USER CODE BEGIN ADC1_Init 0 */ |
| 660 | 694 | ||
| Line 665... | Line 699... | ||
| 665 | /* USER CODE BEGIN ADC1_Init 1 */ |
699 | /* USER CODE BEGIN ADC1_Init 1 */ |
| 666 | 700 | ||
| 667 | /* USER CODE END ADC1_Init 1 */ |
701 | /* USER CODE END ADC1_Init 1 */ |
| 668 | 702 | ||
| 669 | /** Common config |
703 | /** Common config |
| 670 | */ |
704 | */ |
| 671 | hadc1.Instance = ADC1; |
705 | hadc1.Instance = ADC1; |
| 672 | hadc1.Init.ScanConvMode = ADC_SCAN_ENABLE; |
706 | hadc1.Init.ScanConvMode = ADC_SCAN_ENABLE; |
| 673 | hadc1.Init.ContinuousConvMode = DISABLE; |
707 | hadc1.Init.ContinuousConvMode = DISABLE; |
| 674 | hadc1.Init.DiscontinuousConvMode = DISABLE; |
708 | hadc1.Init.DiscontinuousConvMode = DISABLE; |
| 675 | hadc1.Init.ExternalTrigConv = ADC_EXTERNALTRIGCONV_T3_TRGO; |
709 | hadc1.Init.ExternalTrigConv = ADC_EXTERNALTRIGCONV_T3_TRGO; |
| Line 679... | Line 713... | ||
| 679 | { |
713 | { |
| 680 | Error_Handler(); |
714 | Error_Handler(); |
| 681 | } |
715 | } |
| 682 | 716 | ||
| 683 | /** Configure Regular Channel |
717 | /** Configure Regular Channel |
| 684 | */ |
718 | */ |
| 685 | sConfig.Channel = ADC_CHANNEL_0; |
719 | sConfig.Channel = ADC_CHANNEL_0; |
| 686 | sConfig.Rank = ADC_REGULAR_RANK_1; |
720 | sConfig.Rank = ADC_REGULAR_RANK_1; |
| 687 | sConfig.SamplingTime = ADC_SAMPLETIME_71CYCLES_5; |
721 | sConfig.SamplingTime = ADC_SAMPLETIME_71CYCLES_5; |
| 688 | if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK) |
722 | if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK) |
| 689 | { |
723 | { |
| 690 | Error_Handler(); |
724 | Error_Handler(); |
| 691 | } |
725 | } |
| 692 | 726 | ||
| 693 | /** Configure Regular Channel |
727 | /** Configure Regular Channel |
| 694 | */ |
728 | */ |
| 695 | sConfig.Channel = ADC_CHANNEL_1; |
729 | sConfig.Channel = ADC_CHANNEL_1; |
| 696 | sConfig.Rank = ADC_REGULAR_RANK_2; |
730 | sConfig.Rank = ADC_REGULAR_RANK_2; |
| 697 | if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK) |
731 | if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK) |
| 698 | { |
732 | { |
| 699 | Error_Handler(); |
733 | Error_Handler(); |
| 700 | } |
734 | } |
| 701 | 735 | ||
| 702 | /** Configure Regular Channel |
736 | /** Configure Regular Channel |
| 703 | */ |
737 | */ |
| 704 | sConfig.Channel = ADC_CHANNEL_2; |
738 | sConfig.Channel = ADC_CHANNEL_2; |
| 705 | sConfig.Rank = ADC_REGULAR_RANK_3; |
739 | sConfig.Rank = ADC_REGULAR_RANK_3; |
| 706 | if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK) |
740 | if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK) |
| 707 | { |
741 | { |
| 708 | Error_Handler(); |
742 | Error_Handler(); |
| 709 | } |
743 | } |
| 710 | 744 | ||
| 711 | /** Configure Regular Channel |
745 | /** Configure Regular Channel |
| 712 | */ |
746 | */ |
| 713 | sConfig.Channel = ADC_CHANNEL_3; |
747 | sConfig.Channel = ADC_CHANNEL_3; |
| 714 | sConfig.Rank = ADC_REGULAR_RANK_4; |
748 | sConfig.Rank = ADC_REGULAR_RANK_4; |
| 715 | if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK) |
749 | if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK) |
| 716 | { |
750 | { |
| 717 | Error_Handler(); |
751 | Error_Handler(); |
| 718 | } |
752 | } |
| 719 | 753 | ||
| 720 | /** Configure Regular Channel |
754 | /** Configure Regular Channel |
| 721 | */ |
755 | */ |
| 722 | sConfig.Channel = ADC_CHANNEL_4; |
756 | sConfig.Channel = ADC_CHANNEL_4; |
| 723 | sConfig.Rank = ADC_REGULAR_RANK_5; |
757 | sConfig.Rank = ADC_REGULAR_RANK_5; |
| 724 | if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK) |
758 | if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK) |
| 725 | { |
759 | { |
| 726 | Error_Handler(); |
760 | Error_Handler(); |
| 727 | } |
761 | } |
| 728 | 762 | ||
| 729 | /** Configure Regular Channel |
763 | /** Configure Regular Channel |
| 730 | */ |
764 | */ |
| 731 | sConfig.Channel = ADC_CHANNEL_VREFINT; |
765 | sConfig.Channel = ADC_CHANNEL_VREFINT; |
| 732 | sConfig.Rank = ADC_REGULAR_RANK_6; |
766 | sConfig.Rank = ADC_REGULAR_RANK_6; |
| 733 | if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK) |
767 | if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK) |
| 734 | { |
768 | { |
| 735 | Error_Handler(); |
769 | Error_Handler(); |
| 736 | } |
770 | } |
| 737 | 771 | ||
| 738 | /** Configure Regular Channel |
772 | /** Configure Regular Channel |
| 739 | */ |
773 | */ |
| 740 | sConfig.Channel = ADC_CHANNEL_TEMPSENSOR; |
774 | sConfig.Channel = ADC_CHANNEL_TEMPSENSOR; |
| 741 | sConfig.Rank = ADC_REGULAR_RANK_7; |
775 | sConfig.Rank = ADC_REGULAR_RANK_7; |
| 742 | if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK) |
776 | if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK) |
| 743 | { |
777 | { |
| 744 | Error_Handler(); |
778 | Error_Handler(); |
| 745 | } |
779 | } |
| 746 | /* USER CODE BEGIN ADC1_Init 2 */ |
780 | /* USER CODE BEGIN ADC1_Init 2 */ |
| 747 | 781 | ||
| 748 | /* USER CODE END ADC1_Init 2 */ |
782 | /* USER CODE END ADC1_Init 2 */ |
| 749 | - | ||
| 750 | } |
783 | } |
| 751 | 784 | ||
| 752 | /** |
785 | /** |
| 753 | * @brief CAN Initialization Function |
786 | * @brief CAN Initialization Function |
| 754 | * @param None |
787 | * @param None |
| 755 | * @retval None |
788 | * @retval None |
| 756 | */ |
789 | */ |
| 757 | static void MX_CAN_Init(void) |
790 | static void MX_CAN_Init(void) |
| 758 | { |
791 | { |
| 759 | 792 | ||
| 760 | /* USER CODE BEGIN CAN_Init 0 */ |
793 | /* USER CODE BEGIN CAN_Init 0 */ |
| 761 | 794 | ||
| Line 781... | Line 814... | ||
| 781 | Error_Handler(); |
814 | Error_Handler(); |
| 782 | } |
815 | } |
| 783 | /* USER CODE BEGIN CAN_Init 2 */ |
816 | /* USER CODE BEGIN CAN_Init 2 */ |
| 784 | 817 | ||
| 785 | /* USER CODE END CAN_Init 2 */ |
818 | /* USER CODE END CAN_Init 2 */ |
| 786 | - | ||
| 787 | } |
819 | } |
| 788 | 820 | ||
| 789 | /** |
821 | /** |
| 790 | * @brief SPI1 Initialization Function |
822 | * @brief SPI1 Initialization Function |
| 791 | * @param None |
823 | * @param None |
| 792 | * @retval None |
824 | * @retval None |
| 793 | */ |
825 | */ |
| 794 | static void MX_SPI1_Init(void) |
826 | static void MX_SPI1_Init(void) |
| 795 | { |
827 | { |
| 796 | 828 | ||
| 797 | /* USER CODE BEGIN SPI1_Init 0 */ |
829 | /* USER CODE BEGIN SPI1_Init 0 */ |
| 798 | 830 | ||
| Line 819... | Line 851... | ||
| 819 | Error_Handler(); |
851 | Error_Handler(); |
| 820 | } |
852 | } |
| 821 | /* USER CODE BEGIN SPI1_Init 2 */ |
853 | /* USER CODE BEGIN SPI1_Init 2 */ |
| 822 | 854 | ||
| 823 | /* USER CODE END SPI1_Init 2 */ |
855 | /* USER CODE END SPI1_Init 2 */ |
| 824 | - | ||
| 825 | } |
856 | } |
| 826 | 857 | ||
| 827 | /** |
858 | /** |
| 828 | * @brief TIM2 Initialization Function |
859 | * @brief TIM2 Initialization Function |
| 829 | * @param None |
860 | * @param None |
| 830 | * @retval None |
861 | * @retval None |
| 831 | */ |
862 | */ |
| 832 | static void MX_TIM2_Init(void) |
863 | static void MX_TIM2_Init(void) |
| 833 | { |
864 | { |
| 834 | 865 | ||
| 835 | /* USER CODE BEGIN TIM2_Init 0 */ |
866 | /* USER CODE BEGIN TIM2_Init 0 */ |
| 836 | 867 | ||
| Line 884... | Line 915... | ||
| 884 | Error_Handler(); |
915 | Error_Handler(); |
| 885 | } |
916 | } |
| 886 | /* USER CODE BEGIN TIM2_Init 2 */ |
917 | /* USER CODE BEGIN TIM2_Init 2 */ |
| 887 | 918 | ||
| 888 | /* USER CODE END TIM2_Init 2 */ |
919 | /* USER CODE END TIM2_Init 2 */ |
| 889 | - | ||
| 890 | } |
920 | } |
| 891 | 921 | ||
| 892 | /** |
922 | /** |
| 893 | * @brief TIM3 Initialization Function |
923 | * @brief TIM3 Initialization Function |
| 894 | * @param None |
924 | * @param None |
| 895 | * @retval None |
925 | * @retval None |
| 896 | */ |
926 | */ |
| 897 | static void MX_TIM3_Init(void) |
927 | static void MX_TIM3_Init(void) |
| 898 | { |
928 | { |
| 899 | 929 | ||
| 900 | /* USER CODE BEGIN TIM3_Init 0 */ |
930 | /* USER CODE BEGIN TIM3_Init 0 */ |
| 901 | 931 | ||
| Line 946... | Line 976... | ||
| 946 | Error_Handler(); |
976 | Error_Handler(); |
| 947 | } |
977 | } |
| 948 | /* USER CODE BEGIN TIM3_Init 2 */ |
978 | /* USER CODE BEGIN TIM3_Init 2 */ |
| 949 | 979 | ||
| 950 | /* USER CODE END TIM3_Init 2 */ |
980 | /* USER CODE END TIM3_Init 2 */ |
| 951 | - | ||
| 952 | } |
981 | } |
| 953 | 982 | ||
| 954 | /** |
983 | /** |
| 955 | * @brief TIM4 Initialization Function |
984 | * @brief TIM4 Initialization Function |
| 956 | * @param None |
985 | * @param None |
| 957 | * @retval None |
986 | * @retval None |
| 958 | */ |
987 | */ |
| 959 | static void MX_TIM4_Init(void) |
988 | static void MX_TIM4_Init(void) |
| 960 | { |
989 | { |
| 961 | 990 | ||
| 962 | /* USER CODE BEGIN TIM4_Init 0 */ |
991 | /* USER CODE BEGIN TIM4_Init 0 */ |
| 963 | 992 | ||
| Line 991... | Line 1020... | ||
| 991 | Error_Handler(); |
1020 | Error_Handler(); |
| 992 | } |
1021 | } |
| 993 | /* USER CODE BEGIN TIM4_Init 2 */ |
1022 | /* USER CODE BEGIN TIM4_Init 2 */ |
| 994 | 1023 | ||
| 995 | /* USER CODE END TIM4_Init 2 */ |
1024 | /* USER CODE END TIM4_Init 2 */ |
| 996 | - | ||
| 997 | } |
1025 | } |
| 998 | 1026 | ||
| 999 | /** |
1027 | /** |
| 1000 | * @brief USART1 Initialization Function |
1028 | * @brief USART1 Initialization Function |
| 1001 | * @param None |
1029 | * @param None |
| 1002 | * @retval None |
1030 | * @retval None |
| 1003 | */ |
1031 | */ |
| 1004 | static void MX_USART1_UART_Init(void) |
1032 | static void MX_USART1_UART_Init(void) |
| 1005 | { |
1033 | { |
| 1006 | 1034 | ||
| 1007 | /* USER CODE BEGIN USART1_Init 0 */ |
1035 | /* USER CODE BEGIN USART1_Init 0 */ |
| 1008 | 1036 | ||
| Line 1024... | Line 1052... | ||
| 1024 | Error_Handler(); |
1052 | Error_Handler(); |
| 1025 | } |
1053 | } |
| 1026 | /* USER CODE BEGIN USART1_Init 2 */ |
1054 | /* USER CODE BEGIN USART1_Init 2 */ |
| 1027 | 1055 | ||
| 1028 | /* USER CODE END USART1_Init 2 */ |
1056 | /* USER CODE END USART1_Init 2 */ |
| 1029 | - | ||
| 1030 | } |
1057 | } |
| 1031 | 1058 | ||
| 1032 | /** |
1059 | /** |
| 1033 | * Enable DMA controller clock |
1060 | * Enable DMA controller clock |
| 1034 | */ |
1061 | */ |
| 1035 | static void MX_DMA_Init(void) |
1062 | static void MX_DMA_Init(void) |
| 1036 | { |
1063 | { |
| 1037 | 1064 | ||
| 1038 | /* DMA controller clock enable */ |
1065 | /* DMA controller clock enable */ |
| 1039 | __HAL_RCC_DMA1_CLK_ENABLE(); |
1066 | __HAL_RCC_DMA1_CLK_ENABLE(); |
| 1040 | 1067 | ||
| 1041 | /* DMA interrupt init */ |
1068 | /* DMA interrupt init */ |
| 1042 | /* DMA1_Channel1_IRQn interrupt configuration */ |
1069 | /* DMA1_Channel1_IRQn interrupt configuration */ |
| 1043 | HAL_NVIC_SetPriority(DMA1_Channel1_IRQn, 0, 0); |
1070 | HAL_NVIC_SetPriority(DMA1_Channel1_IRQn, 0, 0); |
| 1044 | HAL_NVIC_EnableIRQ(DMA1_Channel1_IRQn); |
1071 | HAL_NVIC_EnableIRQ(DMA1_Channel1_IRQn); |
| 1045 | - | ||
| 1046 | } |
1072 | } |
| 1047 | 1073 | ||
| 1048 | /** |
1074 | /** |
| 1049 | * @brief GPIO Initialization Function |
1075 | * @brief GPIO Initialization Function |
| 1050 | * @param None |
1076 | * @param None |
| 1051 | * @retval None |
1077 | * @retval None |
| 1052 | */ |
1078 | */ |
| 1053 | static void MX_GPIO_Init(void) |
1079 | static void MX_GPIO_Init(void) |
| 1054 | { |
1080 | { |
| 1055 | GPIO_InitTypeDef GPIO_InitStruct = {0}; |
1081 | GPIO_InitTypeDef GPIO_InitStruct = {0}; |
| 1056 | 1082 | ||
| 1057 | /* GPIO Ports Clock Enable */ |
1083 | /* GPIO Ports Clock Enable */ |
| Line 1062... | Line 1088... | ||
| 1062 | 1088 | ||
| 1063 | /*Configure GPIO pin Output Level */ |
1089 | /*Configure GPIO pin Output Level */ |
| 1064 | HAL_GPIO_WritePin(LED_Blink_GPIO_Port, LED_Blink_Pin, GPIO_PIN_RESET); |
1090 | HAL_GPIO_WritePin(LED_Blink_GPIO_Port, LED_Blink_Pin, GPIO_PIN_RESET); |
| 1065 | 1091 | ||
| 1066 | /*Configure GPIO pin Output Level */ |
1092 | /*Configure GPIO pin Output Level */ |
| 1067 | HAL_GPIO_WritePin(GPIOB, SPI_CS_Clk_Pin|SPI_CS_D_Pin|ENA_AUX_5V_Pin, GPIO_PIN_RESET); |
1093 | HAL_GPIO_WritePin(GPIOB, SPI_CS_Clk_Pin | SPI_CS_D_Pin | ENA_AUX_5V_Pin, GPIO_PIN_RESET); |
| 1068 | 1094 | ||
| 1069 | /*Configure GPIO pin : LED_Blink_Pin */ |
1095 | /*Configure GPIO pin : LED_Blink_Pin */ |
| 1070 | GPIO_InitStruct.Pin = LED_Blink_Pin; |
1096 | GPIO_InitStruct.Pin = LED_Blink_Pin; |
| 1071 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; |
1097 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; |
| 1072 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
1098 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
| 1073 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; |
1099 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; |
| 1074 | HAL_GPIO_Init(LED_Blink_GPIO_Port, &GPIO_InitStruct); |
1100 | HAL_GPIO_Init(LED_Blink_GPIO_Port, &GPIO_InitStruct); |
| 1075 | 1101 | ||
| 1076 | /*Configure GPIO pins : SPI_CS_Clk_Pin SPI_CS_D_Pin ENA_AUX_5V_Pin */ |
1102 | /*Configure GPIO pins : SPI_CS_Clk_Pin SPI_CS_D_Pin ENA_AUX_5V_Pin */ |
| 1077 | GPIO_InitStruct.Pin = SPI_CS_Clk_Pin|SPI_CS_D_Pin|ENA_AUX_5V_Pin; |
1103 | GPIO_InitStruct.Pin = SPI_CS_Clk_Pin | SPI_CS_D_Pin | ENA_AUX_5V_Pin; |
| 1078 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; |
1104 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; |
| 1079 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
1105 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
| 1080 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; |
1106 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; |
| 1081 | HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); |
1107 | HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); |
| 1082 | 1108 | ||
| 1083 | /*Configure GPIO pin : STARTER_ON_Pin */ |
1109 | /*Configure GPIO pin : STARTER_ON_Pin */ |
| 1084 | GPIO_InitStruct.Pin = STARTER_ON_Pin; |
1110 | GPIO_InitStruct.Pin = STARTER_ON_Pin; |
| 1085 | GPIO_InitStruct.Mode = GPIO_MODE_INPUT; |
1111 | GPIO_InitStruct.Mode = GPIO_MODE_INPUT; |
| 1086 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
1112 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
| 1087 | HAL_GPIO_Init(STARTER_ON_GPIO_Port, &GPIO_InitStruct); |
1113 | HAL_GPIO_Init(STARTER_ON_GPIO_Port, &GPIO_InitStruct); |
| 1088 | - | ||
| 1089 | } |
1114 | } |
| 1090 | 1115 | ||
| 1091 | /* USER CODE BEGIN 4 */ |
1116 | /* USER CODE BEGIN 4 */ |
| 1092 | 1117 | ||
| 1093 | /* USER CODE END 4 */ |
1118 | /* USER CODE END 4 */ |
| 1094 | 1119 | ||
| 1095 | /** |
1120 | /** |
| 1096 | * @brief This function is executed in case of error occurrence. |
1121 | * @brief This function is executed in case of error occurrence. |
| 1097 | * @retval None |
1122 | * @retval None |
| 1098 | */ |
1123 | */ |
| 1099 | void Error_Handler(void) |
1124 | void Error_Handler(void) |
| 1100 | { |
1125 | { |
| 1101 | /* USER CODE BEGIN Error_Handler_Debug */ |
1126 | /* USER CODE BEGIN Error_Handler_Debug */ |
| 1102 | /* User can add his own implementation to report the HAL error return state */ |
1127 | /* User can add his own implementation to report the HAL error return state */ |
| 1103 | 1128 | ||
| 1104 | /* USER CODE END Error_Handler_Debug */ |
1129 | /* USER CODE END Error_Handler_Debug */ |
| 1105 | } |
1130 | } |
| 1106 | 1131 | ||
| 1107 | #ifdef USE_FULL_ASSERT |
1132 | #ifdef USE_FULL_ASSERT |
| 1108 | /** |
1133 | /** |
| 1109 | * @brief Reports the name of the source file and the source line number |
1134 | * @brief Reports the name of the source file and the source line number |
| 1110 | * where the assert_param error has occurred. |
1135 | * where the assert_param error has occurred. |
| 1111 | * @param file: pointer to the source file name |
1136 | * @param file: pointer to the source file name |
| 1112 | * @param line: assert_param error line source number |
1137 | * @param line: assert_param error line source number |
| 1113 | * @retval None |
1138 | * @retval None |
| 1114 | */ |
1139 | */ |
| 1115 | void assert_failed(uint8_t *file, uint32_t line) |
1140 | void assert_failed(uint8_t *file, uint32_t line) |
| 1116 | { |
1141 | { |
| 1117 | /* USER CODE BEGIN 6 */ |
1142 | /* USER CODE BEGIN 6 */ |
| 1118 | /* User can add his own implementation to report the file name and line number, |
1143 | /* User can add his own implementation to report the file name and line number, |
| 1119 | tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ |
1144 | tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ |