PWM DMA stops after 2 pulses when preload is disabled, (does not when compare register preload is enabled)
I am experimenting with PWM DMA on STM32F407VET6. The code creates pulses of increasing width.
If I enable the output compare preload, the number of pulses is 2 instead of 6.
The first pulse at startup is the default setting from the configuration in MX and not the first DMA value. This makes sense as preload of output compare means to load when timer = 0 (if I am not mistaken).
To make sure PWM values are not one off, I disabled the preload of the output compare register. In that case I get only 2 pulses and pulse generation stops? Why do I get only 2 pulses in that case?
void HAL_TIM_PWM_PulseFinishedCallback(TIM_HandleTypeDef *htim)
{
HAL_TIM_PWM_Stop_DMA(&htim2, TIM_CHANNEL_1);
printf("HAL_TIM_PWM_PulseFinishedCallback: Transfer completed\n");
}
/........................../
Main loop extract:
for (int i=0; i<6;i++)
pwmData[i] = 1+5*i;
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
uint8_t i = sizeof(pwmData)/sizeof(uint32_t);
printf("Sending data %d pulses\n",i);
HAL_TIM_PWM_Start_DMA(&htim2, TIM_CHANNEL_1,(uint32_t *) pwmData, 6);
HAL_Delay(1000);
}
Edit: It seems that the transfer complete interrupt is coming to early in the case without preload.
