cancel
Showing results for 
Search instead for 
Did you mean: 

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

nikwest
Associate II

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.

6 REPLIES 6
KnarfB
Principal III

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
Associate II

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
Associate II

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

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
Associate II

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 II

void HAL_TIM_PeriodElapsedHalfCpltCallback(TIM_HandleTypeDef *htim)

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