cancel
Showing results for 
Search instead for 
Did you mean: 

[Solved]Problem with Usart Irq

SDall.11
Associate III

Hi at all,

Sometime happens that usart2 irq freeze and HAL_UART_RxCpltCallback isn't called.

From this moment I can send data (I use blocking instruction HAL_UART_Transmit), but don't receive any.

When this happens, HAL_UART_ErrorCallback don't called too.

In this situation, HAL_Receive_IT returns always HAL_BUSY.

I tried to solve calling these instruction when the status is different from HAL_OK:

  __HAL_UART_CLEAR_OREFLAG(huart);

  __HAL_UART_CLEAR_NEFLAG(huart);

  __HAL_UART_CLEAR_FEFLAG(huart);

  __HAL_UART_DISABLE_IT(huart, UART_IT_ERR);

  huart->ErrorCode = HAL_UART_ERROR_NONE;

  Uart2Status = HAL_UART_Receive_IT(huart, (uint8_t *)&ch, 1);

This solution seems to solve for some tries only.

At the moment, when IRQ freeze, to solve the problem, I must to restart device.

The problem is random.

Can you help me?

Thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
SDall.11
Associate III

Hi at all,

I probably solved it.

I had used HAL_UART_Transmit instead of HAL_UART_Transmit_IT.

Now (with HAL_UART_Transmit_IT) it seems to work fine.

Thanks at all for help.

View solution in original post

4 REPLIES 4

Break in debugger to understand where it "freeze"

Interrupt Handlers will reenter (tail-chain) continuously if the cause isn't serviced properly.

Have Error_Handler() and HardFault_Handler() output actionable data.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
SDall.11
Associate III

Hi clive1 and thanks for answer.

Excuse me, but maybe don't understand your answers.

--> Break in debugger to understand where it "freeze"

I can't break, because my device continue to work fine, with the exception of serial reception.

There isn't a point where software go in loop or similar.

I know only that HAL_Receive_IT returns HAL_BUSY and if I place a breakpoint into HAL_UART_RxCpltCallback this callback doesn't called even though I am receiving data.

About Error_Handler() and HardFault_Handler() I don't understand what you told me :(

Sorry!

Guenael Cadier
ST Employee

Dear @SDall.1​ 

If an overrun error is detected, it could prevent further RXNE interrupts to be raised.

Did you implement some specific treatments in the HAL_UART_RxCpltCallback() callback ?

For example, please make sure to not call a long or blocking process in the callback, as the callback is executed within the Interrupt context.

If you execute a Tx operation by calling HAL_UART_Transmit() in HAL_UART_RxCpltCallback(), this means that RX interrupt treatment will last at least longer time than the transmission time. if new characters are received during this time, overrun error might occur ...

Regards

SDall.11
Associate III

Hi at all,

I probably solved it.

I had used HAL_UART_Transmit instead of HAL_UART_Transmit_IT.

Now (with HAL_UART_Transmit_IT) it seems to work fine.

Thanks at all for help.