cancel
Showing results for 
Search instead for 
Did you mean: 

How to add my own code in usart_if.c file

pho3nix
Associate III

Hello,

I am trying to put the Lorawan keys (DEVEUI,APPEUI, APPKEY) from a serial terminal using uart communication for end node application. I am using uart interrupts for this. There is cubemx generated usart_if.c file which contains HAL_UART_RxCpltCallback() already. This is the code snippet:

 

void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)

{

/* USER CODE BEGIN HAL_UART_RxCpltCallback_1 */



/* USER CODE END HAL_UART_RxCpltCallback_1 */

if (huart->Instance == USART2)

{

if ((NULL != RxCpltCallback) && (HAL_UART_ERROR_NONE == huart->ErrorCode))

{

RxCpltCallback(&charRx, 1, 0);

}

HAL_UART_Receive_IT(huart, &charRx, 1);

}

/* USER CODE BEGIN HAL_UART_RxCpltCallback_2 */



/* USER CODE END HAL_UART_RxCpltCallback_2 */

}

 

 

How to modify this with my code so that I can receive a command from serial terminal and proceed accordingly. 

Thank you.

1 REPLY 1
Techn
Senior III

hal_uart.c has _weak void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart), but it has attribute as _weak

as weak, so you have to implement your version such as setting a flag or copy the data etc..

avoid time consuming activities since it is an interrupt.

 

 

_weak void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)

{

/* Prevent unused argument(s) compilation warning */

UNUSED(huart);

 

/* NOTE : This function should not be modified, when the callback is needed,

the HAL_UART_RxCpltCallback can be implemented in the user file.

*/

}

If you feel a post has answered your question, please click "Accept as Solution".