2025-07-18 2:04 AM
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.
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
2025-07-18 3:03 AM
Hello @ABach.4
Did you check the example below please:
2025-07-18 5:07 AM
No. Thank you. I'll check them out.