cancel
Showing results for 
Search instead for 
Did you mean: 

Need help understanding HAL_DMA_RegisterCallback function

Christopher Pappas
Senior II
Posted on August 13, 2016 at 17:00

HAL_DMA_RegisterCallback(DMA_HandleTypeDef *hdma, HAL_DMA_CallbackIDTypeDef CallbackID, void (* pCallback)(DMA_HandleTypeDef *_hdma))

These are the parameters I am using in my code:

HAL_DMA_RegisterCallback(&hdma_dac1, HAL_DMA_XFER_HALFCPLT_CB_ID, MyDmaDac1Callback)

Getting errors on this line no matter how many times I try to alter the parameters.

Does a practical real-world code example exist to guide me on the proper syntax for this function? Can anyone offer some assistance?

Thanks,

Christopher

#hal-callback-dma-register
1 ACCEPTED SOLUTION

Accepted Solutions
Amel NASRI
ST Employee
Posted on August 15, 2016 at 16:25

Hipappas.chris,

This callback function is used in all DMA_FLASHToRAM examples available in the Cube package such asSTM32Cube_FW_F4_V1.0\Projects\STM32F4-Discovery\Examples\DMA\DMA_FLASHToRAM. It is called this way there:

/*##-5- Select Callbacks functions called after Transfer complete and Transfer error */
<br> HAL_DMA_RegisterCallback(&DmaHandle, HAL_DMA_XFER_CPLT_CB_ID, TransferComplete);<br> HAL_DMA_RegisterCallback(&DmaHandle, HAL_DMA_XFER_ERROR_CB_ID, TransferError);

-Mayla-

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.

View solution in original post

4 REPLIES 4
Amel NASRI
ST Employee
Posted on August 15, 2016 at 16:25

Hipappas.chris,

This callback function is used in all DMA_FLASHToRAM examples available in the Cube package such asSTM32Cube_FW_F4_V1.0\Projects\STM32F4-Discovery\Examples\DMA\DMA_FLASHToRAM. It is called this way there:

/*##-5- Select Callbacks functions called after Transfer complete and Transfer error */
<br> HAL_DMA_RegisterCallback(&DmaHandle, HAL_DMA_XFER_CPLT_CB_ID, TransferComplete);<br> HAL_DMA_RegisterCallback(&DmaHandle, HAL_DMA_XFER_ERROR_CB_ID, TransferError);

-Mayla-

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.

Christopher Pappas
Senior II
Posted on August 16, 2016 at 02:59

Hey Mayla,

Thank you!! I used the example code DMAFlashtoRam from STM32F7 v1.4.0 firmware and that fixed the syntax errors and everything compiles fine now.

Thanks again for taking time to reply!!

Christopher

Christopher Pappas
Senior II
Posted on August 23, 2016 at 20:24

Actually realized that the callbacks are already defined in the HAL peripheral library, so I did not need to define my own callbacks, I just used the names defined in HAL.

fuentesj
Associate
Posted on October 28, 2016 at 04:33

Yes, there are default callbacks, for example:

void I2S_DMATxCplt(DMA_HandleTypeDef *hdma);

According to UM1725, if you want to write your own callback you have to assign the function pointer to a variable member:

void HAL_UART_TxCpltCallback(UART_HandleTypeDef *phuart)

{

}

hppp->DMA_handle->XferCpltCallback = HAL_UART_TxCpltCallback;

Also, you can assign the callback using something like this:

HAL_DMA_RegisterCallback(&hppp, HAL_DMA_XFER_CPLT_CB_ID, HAL_UART_TxCpltCallback);

I tried both, but no luck.  My callback is never executed.  The ISR is working fine, but then it executes the default callback.  Any ideas?

0690X00000605Q4QAI.png