Freertos timer thread runs continously

Hi,

I am porting a legacy code to freertos. I have ser the timer task to higher priority than the other tasks. The system runs normally for sometime. After about 55 minutes, the timer task runs continuously and blocks the other tasks. What could be causing timer task to run continuously?

Hi, what chip/port are you using? Would you be able to share a sample code that reproduces this?

Hi, stm32. Its a legacy code with 10 plus tasks and multiple modules which use timers. Hence it is not possible.to share a sample code.
The timer thread runs as expected for long time and then this behavior starts. What can ppssinly cause such a behavior?

The suspect is most probably not the code in timers.c, but the code that you want it to execute.

A thousand things can go wrong, one of them being a dead-lock: a high-priority task is waiting for some condition that never occurs.

Maybe it is running out of resources, and so the planned path can not be taken. Does it use many peripherals / drivers?

Think well about the consequences when the timer-task has a higher priority… things may not go as expected.

What you can do is add logging end/or put breakpoints in the code: see what it is actually doing.

When possible: start less than 10 tasks and see if the problem still occurs.

Thanks for your reply. I,ll add some debug logs and try to narrow down the issue.

I was able to find out the issue. In one of the timer callbacks, the timer period was reconfigured and this was causing an infinite loop inside the timer task in the function prvReloadTimer. As the parameter timeNow is received as a parameter for this function and not re-read, the while loop never exits. I am planning to use a notify from the callback and then update the timer period in the main thread. Please let me know your comments.

The callback you see inside prvReloadTimer() occurs only if the auto-reload timer has fallen behind. (The normal callback is in prvProcessExpiredTimer().) In the debugger, can you see how your timer fell so far behind?

Did your call to xTimerChangePeriod() include a nonzero xTicksToWait parameter?

My earlier reply was a bit too early as the issue was not actually fixed. I think the issue was that a static timer was created with same parameters in duplicate from two places. This timer was set to expire after an hour and the duplicate entries in pxcurrenttimerlist created an infinite loop inside the for loop inside vListInsert as pxIterator and pxIterator next were the same. I didnt find this earlier as the timer was created from a thirdparty library .

Thank you for reporting back.