@@ -681,23 +681,25 @@ void configure8PWM(void)
681
681
__HAL_RCC_TIM1_CLK_ENABLE ();
682
682
__HAL_RCC_TIM8_CLK_ENABLE ();
683
683
684
- // Configure TIM1 pins for alternate function mode with push-pull output
685
- GPIO_InitStruct.Pin = GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_10 | GPIO_PIN_11 | GPIO_PIN_12 | GPIO_PIN_13;
686
- GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
687
- GPIO_InitStruct.Pull = GPIO_NOPULL;
688
- GPIO_InitStruct.Alternate = GPIO_AF6_TIM1;
689
- HAL_GPIO_Init (GPIOE, &GPIO_InitStruct);
684
+ // Configure GPIO pins for STSPIN32G4 internal FET driver
685
+
686
+ __HAL_RCC_GPIOE_CLK_ENABLE (); // enable GPIO clock
687
+ GPIO_InitStruct.Pin = GPIO_PIN_9 | GPIO_PIN_8 | GPIO_PIN_11 | GPIO_PIN_10 | GPIO_PIN_13 | GPIO_PIN_12;
688
+ GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; // alternate function mode with push-pull output
689
+ GPIO_InitStruct.Pull = GPIO_NOPULL;
690
+ GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
691
+ GPIO_InitStruct.Alternate = GPIO_AF6_TIM1;
692
+ HAL_GPIO_Init (GPIOE, &GPIO_InitStruct);
690
693
691
694
// Configure TIM8 pins for alternate function mode with push-pull output
692
- GPIO_InitStruct.Pin = GPIO_PIN_0;
695
+ GPIO_InitStruct.Pin = GPIO_PIN_14 | GPIO_PIN_0;
693
696
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
694
697
GPIO_InitStruct.Pull = GPIO_NOPULL;
695
- GPIO_InitStruct.Alternate = GPIO_AF3_TIM8;
696
- HAL_GPIO_Init (GPIOB, &GPIO_InitStruct);
697
-
698
- // Configure additional TIM8 pin for PWM output
699
- GPIO_InitStruct.Pin = GPIO_PIN_14;
698
+ GPIO_InitStruct.Alternate = GPIO_AF3_TIM8;
700
699
HAL_GPIO_Init (GPIOA, &GPIO_InitStruct);
700
+ HAL_GPIO_Init (GPIOB, &GPIO_InitStruct);
701
+
702
+
701
703
702
704
// Set TIM1 and TIM8 dead time values to 50 ns
703
705
TIM_MasterConfigTypeDef sMasterConfig = {0 };
@@ -747,8 +749,8 @@ void configure8PWM(void)
747
749
HAL_TIM_PWM_ConfigChannel (&htim1, &sConfigOC , LL_TIM_CHANNEL_CH3N);
748
750
749
751
// Configure PWM output on TIM8 channel 1 and additional channel
750
- HAL_TIM_PWM_ConfigChannel (&htim8, &sConfigOC , LL_TIM_CHANNEL_CH2N);
751
752
HAL_TIM_PWM_ConfigChannel (&htim8, &sConfigOC , LL_TIM_CHANNEL_CH2);
753
+ HAL_TIM_PWM_ConfigChannel (&htim8, &sConfigOC , LL_TIM_CHANNEL_CH2N);
752
754
753
755
// Start TIM1 and TIM8 PWM outputs
754
756
HAL_TIM_PWM_Start (&htim1, LL_TIM_CHANNEL_CH1);
@@ -757,8 +759,8 @@ void configure8PWM(void)
757
759
HAL_TIM_PWM_Start (&htim1, LL_TIM_CHANNEL_CH2N);
758
760
HAL_TIM_PWM_Start (&htim1, LL_TIM_CHANNEL_CH3);
759
761
HAL_TIM_PWM_Start (&htim1, LL_TIM_CHANNEL_CH3N);
760
- HAL_TIM_PWM_Start (&htim8, LL_TIM_CHANNEL_CH2N);
761
762
HAL_TIM_PWM_Start (&htim8, LL_TIM_CHANNEL_CH2);
763
+ HAL_TIM_PWM_Start (&htim8, LL_TIM_CHANNEL_CH2N);
762
764
}
763
765
764
766
0 commit comments