2020-07-03 03:15 AM
I tried to generate a 2-channel PWM on both the STM32F407 and the STM32G474. I was surprised to see that the PWM of both channels started simultanously, while for the F4 there was a delay.
Is this intended behavior? Is there a work-around?
This is from the F4:
This is on the G4:
The relevant code:
uint16_t pwm_chA[] = {
200, 400, 600, 800
};
uint16_t pwm_chB[] = {
200, 400, 600, 800
};
// blame the PCB designer for swapping the channels
#define PWM_CHANNEL_A TIM_CHANNEL_2
#define PWM_CHANNEL_B TIM_CHANNEL_1
void init_pwm()
{
HAL_TIM_PWM_Start_DMA(&htim1, PWM_CHANNEL_A, (uint32_t *)pwm_chA, sizeof(pwm_chA)/sizeof(pwm_chA[0]));
while (htim1.State == HAL_TIM_STATE_BUSY){ /* wait */ }
HAL_TIMEx_PWMN_Start(&htim1, PWM_CHANNEL_A);
HAL_TIM_PWM_Start_DMA(&htim1, PWM_CHANNEL_B, (uint32_t *)pwm_chB, sizeof(pwm_chB)/sizeof(pwm_chB[0]));
while (htim1.State == HAL_TIM_STATE_BUSY){ /* wait */ }
HAL_TIMEx_PWMN_Start(&htim1, PWM_CHANNEL_B);
// Note: the "while busy" is required otherwise the second channel does not start
}