Registering a User callback for USART on STM32L4S5ZI
Hi,
I have got confused in knowing how to actually register a User call back function for Transfer complete event in UART. I am using DMA.
To give an idea on what I am doing, below re the lines that I have added in my code.
void TxComplete_Callback(struct __UART_HandleTypeDef *huart); //declaration of user callback fun
huart1.TxCpltCallback = TxComplete_Callback; // assigning it to transfer complete event callback of the uart instance
void TxComplete_Callback(struct __UART_HandleTypeDef *huart) {
} // function definition which is currently not fullMy question is whether the argument for the callback function has to be compulsorily (struct __UART_HandleTypeDef *huart)? because in UART_DMATransmitCplt() function it knows that the event received is DMA Transfer Complete and so it checks if huart->TxCpltCallback is populated or else it executes the weak function as can be see below
#if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
/*Call registered Tx complete callback*/
huart->TxCpltCallback(huart);
#else
/*Call legacy weak Tx complete callback*/
HAL_UART_TxCpltCallback(huart);
#endif /* USE_HAL_UART_REGISTER_CALLBACKS */So the doubt I have is if this is how a callback function can be assigned, then what does the HAL_UART_RegisterCallback() function help me to do?
And will the changes that I have made work and whenever the DMA transfer complete event occurs, my custom function TxComplete_Callback will be called and executed? Can I similarly add a RxComplete_Callback function?
Please help me in these confusions. I have set USE_HAL_UART_REGISTER_CALLBACKS to 1 to enable the callbacks.
Thanks!!
