Skip to main content
Associate III
August 22, 2024
Solved

HAL_Delay in uart receive interrupt

  • August 22, 2024
  • 2 replies
  • 1368 views

Hi

 

When HAL_Delay goes into uart interrupt, the program stops.

Is there a way to work it out?

 

I tried to use NVIC, but I don't know how to set it up.

 

Please advise. Thank you.

 

Here is my uart interrupt service routine.

 

void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)

{

if(huart == &huart1)

{

uart_receivebuffer[uartidx++] = rx_buf;

 

if(rx_buf == 0x03)

{

 

HAL_Delay(100);

 

UartReceive();

}

 

HAL_UART_Receive_IT(&huart1, &rx_buf, 1);

 

 

}

}

Best answer by TDK

HAL_Delay needs SysTicks to keep firing to work.

Make your SysTick interrupt higher priority (numerically lower) than your UART interrupt priority. Like this:

TDK_0-1724290935847.png

 

It's generally frowned upon to have blocking code, or code that takes a long time to complete, within an interrupt handler, but that is a separate issue.

2 replies

TDK
TDKBest answer
Super User
August 22, 2024

HAL_Delay needs SysTicks to keep firing to work.

Make your SysTick interrupt higher priority (numerically lower) than your UART interrupt priority. Like this:

TDK_0-1724290935847.png

 

It's generally frowned upon to have blocking code, or code that takes a long time to complete, within an interrupt handler, but that is a separate issue.

"If you feel a post has answered your question, please click ""Accept as Solution""."
giwonKIMAuthor
Associate III
August 22, 2024

Now it works!!

 

Really really thank you.

gbm
Principal
August 22, 2024

Nope, it doesn't. It's impossible to do anything practical (like implement any comm protocol) with any Delay() called from a UART ISR.

My STM32 stuff on github - compact USB device stack and more: https://github.com/gbm-ii/gbmUSBdevice