cancel
Showing results for 
Search instead for 
Did you mean: 

Calling multiple time __HAL_UART_GET_FLAG in UART

DCtech
Associate II

When I try to print on the serial interface with SerialPrint function. 

  void SerialPrint(const char *serial_data, ...)
 
  {
 
   
 
   char uartbuffer[1024];
 
   va_list arg;
 
   va_start(arg, serial_data);
 
   uint16_t len = vsnprintf(uartbuffer, 1024, serial_data, arg);
 
   va_end(arg);
 
   HAL_UART_Transmit(&huart2, (uint8_t *)uartbuffer, strlen(uartbuffer), 100);
 
  }

I am using this function end of the CAN1_Init function like this:

  SerialPrint("CAN1 Initilizing successfull !!")

When I use like that, some reason that is I dont know I get flash registers initilize value not equals "0":

  __HAL_FLASH_GET_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR | FLASH_FLAG_PGSERR);

When I try to analyse this problem I debug in the HAL_UART_Transmit function and I found something. In the HAL_UART_Transmit If the print character size more than 10 In the UART_WaitOnFlagUntilTimeout A mean after coming to this line at least 10 times. 

   while((__HAL_UART_GET_FLAG(huart, Flag) ? SET : RESET) == Status)

I saw the Flash flag set. I am trying to understand why this happening? as if repeatedly calling this __HAL_UART_GET_FLAG function gives flash bits error.

1 REPLY 1
Amel NASRI
ST Employee

Hi @DCtech​ ,

Could you please answer following questions in order to understand more your issue?

1- what are you using as STM32?

2- does it work if you increase the timeout value when calling HAL_UART_Transmit (put 5000 instead of 100)

3- is there any HAL structure not initialized properly? Try to check if flash flags are set before calling HAL_UART_Transmit or not.

4- when you say "If the print character size more than 10", does that mean problem doesn't occur if size is less than 10?

-Amel

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.