cancel
Showing results for 
Search instead for 
Did you mean: 

PWM+DMA behavior differes on STM32F407 compared to STM32G474

AShri.1
Associate II

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:

0693W000001s6UOQAY.png

This is on the G4:0693W000001s6QXQAY.png

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
}

0 REPLIES 0