cancel
Showing results for 
Search instead for 
Did you mean: 

how to implement a high prio timer interrupt in parallel or as freertos thread with ~100 ns accuracy

dieter 123
Associate III
Posted on June 16, 2017 at 22:43

Hi

basically I am using freertos in my project and I need a highest prio timer interrupt driven task which needs to be executed in a granularity of 100 ns. (every n* 100 nsec like 100ns, 1500ns,....)

In Cube MX I sat up a timer interrupt(TIM5), but cube will not allow me to have an interrupt lower than level 5. CUBE MX comes with a warrning: 

''''preemption priotity of interrupts should be >=5 if their handlers call system functions. see FREERTOS LIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY parameter''''

So how can I have a timer interrupt with this granularity when using freertos?

#timer-interrupt #stm32-freertos
6 REPLIES 6
Posted on June 16, 2017 at 23:46

What's the actual interrupt rate, you're unlikely to be able to sustain something over a few hundred KHz.

If you need to latch something on a 10 MHz clock, consider DMA

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on June 17, 2017 at 09:54

the interruprate is 10 khz. Actually the interrupt is used to trigger dma

Posted on June 17, 2017 at 15:21

Edge placement is going to work a lot better in hardware.

If you have TIM2 (32-bit on several STM32) in maximal mode, clocking at 10 MHz, you can use the channel compare to place an interrupt or DMA trigger along the timeline.

Yes, I'd likely keep the interrupt out of the scope of the full RTOS, to reduce the latency, but you'd have to tread carefully as to what functions you could call, or events you could precipitate.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
dieter 123
Associate III
Posted on June 17, 2017 at 23:43

thanks for the info about tim2. The problem is I need to do more than just starting a dma. Still the question remains how can I have a timer interrupt which has a higher prio than freertos?

Or actually could I also setup a freertos thread with prio realtime and use vTaskDelay?

In this case how many cycles is needed for a freertos context switch?

Manfred Dietrich
Associate II
Posted on June 18, 2017 at 00:40

As Long as your irq handler doesn't call RTOS functions, there is no restrictions on preemption priority.

In your Cube-Project go to Configuration -> NVIC Configuration -> Uncheck Use FreeRTOS functions at the line of tim2 irq.

Posted on June 18, 2017 at 00:31

Not using FreeRTOS, can't speculate.

At the end of the day you control the NVIC, both the priority grouping and priority/preemption levels, have your IRQHandler *NOT* call into the RTOS task management and you'll be at 12 cycles in, 12 cycles out.

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