cancel
Showing results for 
Search instead for 
Did you mean: 

Timer PWM with DMA stops too early on STM32G431

ABach.4
Associate II

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

tim1_mode.png

tim1_conf1.png

tim1_conf2.png

DMA Settings

dma_settings.png

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

h100_dma_uint32t.png

I tried also with Data Width

Half-Word

h100_dma_uint16t.png

Byte

h100_dma_uint8t.png

Without stopping DMA, it's like that:

The last puls recurs:

h100_dma_uint32t_nostop.png

Do you know why it's like that?

Do I need to have a different callback?

Thanks for helping...

Andreas

2 REPLIES 2
Saket_Om
ST Employee

Hello @ABach.4 

Did you check the example below please:

STM32CubeG4/Projects/NUCLEO-G431KB/Examples/TIM/TIM_DMA at master · STMicroelectronics/STM32CubeG4 · GitHub

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.
Saket_Om
ABach.4
Associate II

No. Thank you. I'll check them out.