I need to count how many miliseconds does it take my interrupt to finish its service. Before I started using FreeRTOS, I just did something like this:

void HAL_GPIO_EXTI_Callback(void)
    uint32_t diff;
    start = HAL_GetTick();
    // do anything
    diff = HAL_GetTick() - start;

But when I started using FreeRTOS, HAL_GetTick value stopped changing, moreover Systick Interrupt do not work, so there is no chance to increase tick value. Any ideas what should I do to bring back Systick Handler working in interrupt or other solution so I will be able to measure time in interrupt?

  • \$\begingroup\$ FreeRTOS may need to manage that interrupt itself. It should provide its own timing facilities; why not use them instead? \$\endgroup\$ – Brian Drummond Aug 18 '15 at 9:55
  • \$\begingroup\$ I tried, but I think as long as it is an interrupt, not a task, it won't work properly. Or I missed something. \$\endgroup\$ – m0drzew Aug 18 '15 at 11:11
  • \$\begingroup\$ I'm not sure how this would work in the context of an RTOS: Have you looked at DWT_CYCCNT? See also: stackoverflow.com/q/11530593 \$\endgroup\$ – Tut Aug 18 '15 at 11:17
  • \$\begingroup\$ I haven't seen it yet. I'll check it out. \$\endgroup\$ – m0drzew Aug 18 '15 at 11:43
  • 1
    \$\begingroup\$ Your interrupt process time is in milliseconds? What are you doing inside an interrupt subroutine? You should use a hardware timer start it at the start of the interrupt subroutine and stop it at the end. You should be able to take measures in microseconds even in nanoseconds if required. \$\endgroup\$ – ECO Aug 18 '15 at 17:19

Milliseconds is way to long to be spending inside an interrupt, especially when you are using an RTOS. If you interrupt service routine is that long that I would strongly recommend deferring the processing to a task.

FreeRTOS uses the SysTick timer itself, as will probably any RTOS that runs on an ARM Cortex-M part. Further, the STM 32 libraries themselves use FreeRTOS, and the STM32 HAL SysTick interrupt handler calls its own timing routines before calling the FreeRTOS SysTick hander - so the SysTick is not available to the application writer. However there are plent of other peripheral timers you can use.


As in FreeRTOS for STM32, in startup file the Systick interrupt handler vector pointer points to the function required by FreeRTOS for its own use i.e. xPortSysTickHandler. Here FreeRTOS configure the ticks required for RTOS itself for run.

Hence, you can't use systick for any other task.

As Richard said, you can use other timer interrupt based routines for the application requirement.

  • 1
    \$\begingroup\$ Doesn't FreeRTOS have an API call that can be used to a monotonic clock for calculation durations? \$\endgroup\$ – jbarlow Jul 28 '16 at 21:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.