stm32microcontrolleruartinterruption

Using HAL_GetTick in a interruption


Im working on a STM32F411CEU6 using STM32CubeIDE, Im making a library that works whit UART interruption, inside the UART interruption Im using the HAL_GetTick function to keep track of time, when I use this function outside the interruption It work properly, but when I try to use it inside the interruption the uwTick halt.

I understand that uwTick is a global variable that is incremented on interruption, my first guess was that the UART interruption had greater priority over the System tick timer interruption (I'm guessing that this interruption is the one that trigger the uwTick increment), but the System tick timer interruption has a higher interruption in the pinout configuration UI.

What is going on?

Should I change my approach and use a timer (reading the counter inside)?

additional information:

-Im triggering the interruption whit the HAL_UART_Receive_IT(&huartx, &USART_receive[0], 1), where USART_receive is a receive buffer

-The function that use the HAL_GetTick function is being call in the void USART1_IRQHandler(void) handler after the HAL_UART_IRQHandler(&huart1) function

Thanks in advance!


Solution

  • A higher interrupt priority is represented by a lower number and vice-versa. Maybe you need to switch the priorities around to do what you want.

    However, please note:

    It is conventional for systick to be one of the lowest priority interrupts in the system, with only pendsv/svcall lower.

    It is generally considered a bad idea to try to delay within an interrupt, especially for several milliseconds. It is probably better to set a flag or something in the interrupt and let your main context carry out the delayed action.