cancel
Showing results for 
Search instead for 
Did you mean: 

calling hal_delay inside callback (ISR)

valerio2
Associate II
Posted on May 12, 2015 at 16:18

Hi, I'm struggling with this on stm32f429 discovery board with arm cortex M4:

I have a reception task via UART which receive a character per time and put it in a circular buffer cbuff. When some conditions on the received character (i.e. \r has been received) and on the buffer (i.e. cbuff is full) this is printed over a terminal. For some reasons in the function which prints cbuff over the terminal I need to have a delay, so I call HAL_Delay(10). I also use freeRTOS and the calls cascade is

receptionTask()->HAL_UART_Receive_IT()->HAL_UART_RxCpltCallback()->cb_push_back()->HAL_Delay()

wherecb_push_back() is the function that manages cbuf. Withincb_push_back() I call HAL_Delay(10) and everything get stucked. Particularly, in turn HAL_Delay() calls HAL_GetTick() within the while loop (see stm32f4xx_hal.c for reference) and the latter never returns (uwTick is never increased I think). Clearly, at least this is what I guess, it is matter of interrupts priorities. And here comes my troubles: according to freeRTOS.com and Google,SysTick priority must be the lowest possible (in my case 15) and my code fits this requirement. Further, according to UM1725 ''In the default implementation, SysTick timer is the source of time base. It is used to generate interrupts at regular time intervals. Care must be taken if HAL_Delay() is called from a peripheral ISR process, The the SysTick interrupt must have higher priority (numerically lower) than the peripheral interrupt. Otherwise the caller ISR process will be blocked. The function is declared as __weak to be overwritten in case of other implementation in user file.''. So according to my particular case it looks like there is no way I can make it working since I can, at the best, have the UART Rx ISR priority equal to that of SysTick. Am I right or am I missing something? Should I use timers instead? Thank you and regards.
2 REPLIES 2
Posted on May 12, 2015 at 16:45

I need to have a delay

Identifying WHY you need one would be the first step. There are plenty of ways to insert a delay of known time without requiring an interrupt driven counter, or unnecessarily stalling an interrupt routine for 10's of milliseconds. See if you can use an existing free running counter.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
childresss
Associate II
Posted on May 18, 2015 at 18:03

Imprudent things to do in an ISR - delay, execute a long time, call libraries.