Skip to content

Commit d4da3f5

Browse files
committed
Update stm32_mcu.cpp
1 parent 014ab05 commit d4da3f5

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

src/drivers/hardware_specific/stm32/stm32_mcu.cpp

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -681,23 +681,25 @@ void configure8PWM(void)
681681
__HAL_RCC_TIM1_CLK_ENABLE();
682682
__HAL_RCC_TIM8_CLK_ENABLE();
683683

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);
690693

691694
// 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;
693696
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
694697
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;
700699
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
700+
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
701+
702+
701703

702704
// Set TIM1 and TIM8 dead time values to 50 ns
703705
TIM_MasterConfigTypeDef sMasterConfig = {0};
@@ -747,8 +749,8 @@ void configure8PWM(void)
747749
HAL_TIM_PWM_ConfigChannel(&htim1, &sConfigOC, LL_TIM_CHANNEL_CH3N);
748750

749751
// Configure PWM output on TIM8 channel 1 and additional channel
750-
HAL_TIM_PWM_ConfigChannel(&htim8, &sConfigOC, LL_TIM_CHANNEL_CH2N);
751752
HAL_TIM_PWM_ConfigChannel(&htim8, &sConfigOC, LL_TIM_CHANNEL_CH2);
753+
HAL_TIM_PWM_ConfigChannel(&htim8, &sConfigOC, LL_TIM_CHANNEL_CH2N);
752754

753755
// Start TIM1 and TIM8 PWM outputs
754756
HAL_TIM_PWM_Start(&htim1, LL_TIM_CHANNEL_CH1);
@@ -757,8 +759,8 @@ void configure8PWM(void)
757759
HAL_TIM_PWM_Start(&htim1, LL_TIM_CHANNEL_CH2N);
758760
HAL_TIM_PWM_Start(&htim1, LL_TIM_CHANNEL_CH3);
759761
HAL_TIM_PWM_Start(&htim1, LL_TIM_CHANNEL_CH3N);
760-
HAL_TIM_PWM_Start(&htim8, LL_TIM_CHANNEL_CH2N);
761762
HAL_TIM_PWM_Start(&htim8, LL_TIM_CHANNEL_CH2);
763+
HAL_TIM_PWM_Start(&htim8, LL_TIM_CHANNEL_CH2N);
762764
}
763765

764766

0 commit comments

Comments
 (0)