Skip to main content
nikwest
Associate
October 21, 2020
Question

Arbitrary waveform generation using timer DMA-burst feature: what is the callback when DMA transfer is complete/half complete?

  • October 21, 2020
  • 6 replies
  • 1913 views

I am expecting there must be a similar callback function like HAL_UART_TxCpltCallback, HAL_UART_TxHalfCpltCallback in case of using UARTs when using DMA-burst for generating arbitrary waveforms with PWM in order to be able to update the memory buffer used for DMA?

I only can find callbacks which get called with every PWM pulse.

This topic has been closed for replies.

6 replies

KnarfB
Super User
October 21, 2020

You can register your own callback functions by using HAL_DMA_RegisterCallback like

HAL_DMA_RegisterCallback( htim3.hdma[TIM_DMA_ID_CC3], HAL_DMA_XFER_HALFCPLT_CB_ID, XferHalfCpltCallback );

where  void XferHalfCpltCallback(DMA_HandleTypeDef * _hdma) is the callback function which you implement.

nikwest
nikwestAuthor
Associate
October 21, 2020

Thank you. I have briefly tried this already, but I'll try again. I was asuming the TIM_PWM code is consuming the DMA callbacks.

nikwest
nikwestAuthor
Associate
October 21, 2020

No, unfortunately your suggestions does not work for me. The callback doesn't get called. Not sure what I am doing wrong here.

KnarfB
Super User
October 22, 2020

You're right. Started your code and set a breakpoint on the native IRQ Handler DMA1_Channel7_IRQHandler which is hit. Stepping further I ended up at the __weak default HAL_TIM_PWM_PulseFinishedHalfCpltCallback. Defining your own HAL_TIM_PWM_PulseFinishedHalfCpltCallback should work.

nikwest
nikwestAuthor
Associate
October 22, 2020

yep, that what was my conclusion, too. But it's called with every pulse and not when DMA transfer is complete or half complete. Or maybe I misinterpreted that.

NRoth.3
Associate
April 14, 2023

void HAL_TIM_PeriodElapsedHalfCpltCallback(TIM_HandleTypeDef *htim)

works great and is called at the end of the DMA Transfers.