Timer PWM with DMA stops too early on STM32G431
Hi there,
I would like to control WS2812B LEDs with a PWM timer and DMA.
There are various tutorials on this, but they have not helped me and I am now asking you. Because it requires slightly different configurations depending on the model (F3, F4, G4, G0), I'm a bit overwhelmed.
I start a DMA transfer, wait for the last pulse with an interrupt and stop the DMA transfer. So far so good in theory. I still have problems with the implementation.
Even the simplest DMA example without WS2812B protocol does not work for me.
- Clock SYSCLK/HCLK: 170 MHz
- TIM1 CH4 configured
- Prescaler: 170-1 => 1 MHZ
- Counter Preiod: 100-1 => 10 kHz
- DMA
- Memory -> Peripheral
- Data Width: Word (32 bit)
- 6 PWM pulses (= 600 us) should be sent out
TIM1 Mode + Configuration



DMA Settings

Source:
TIM_HandleTypeDef htim1;
DMA_HandleTypeDef hdma_tim1_ch4; /* never used?! */
uint32_t data[] = {
30,
80,
20,
60,
10,
50
};
void HAL_TIM_PWM_PulseFinishedCallback(TIM_HandleTypeDef *htim)
{
HAL_TIM_PWM_Stop_DMA(&htim1, TIM_CHANNEL_4);
}
int main(void)
{
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
MX_DMA_Init();
MX_TIM1_Init();
HAL_TIM_PWM_Start_DMA(&htim1, TIM_CHANNEL_4, (uint32_t *) data, 6);
while (1) {
/* */
}
}The result is here:
After 4 pulses, the 5th pulse starts but didn't finish

I tried also with Data Width
Half-Word

Byte

Without stopping DMA, it's like that:
The last puls recurs:

Do you know why it's like that?
Do I need to have a different callback?
Thanks for helping...
Andreas
