xTimerStart hangs the application

Hi Experts, I have an application run on freertosv10.1 which creates five timers using xTimerCreate() with different timeout periods. After expiry of each timer the callbacks print a message and again start the timer. Four timers are working perfectly but 5th timer calls the callback once after expiry and hangs after the start of the timer. I’ve run out of ideas on how to debug this issue. Can anyone please help ? ~~~

define PERIODMS ( 1000UL / portTICKRATE_MS)

static TimerHandlet xApp[10] = {NULL}; void timerstart(int p) { switch(p) { case 1: xTimerStart(xApp[1], 0); break; case 2: xTimerStart(xApp[2], 0); break; case 3: xTimerStart(xApp[3], 0); break; case 4: xTimerStart(xApp[4], 0); break; case 5: xTimerStart(xApp[5], 0); break; default: break; } } static void TimerCallback( TimerHandlet xTimer ) { int i=0; i = ( int ) pvTimerGetTimerID( xTimer ); printf(“Inside timer callbackrn”); timerstart(i); } void inittimer(void) { int i; //create timers for(i=1;i<6;i++) { xApp[i] = xTimerCreate(“AppTimer”, (PERIODMS+ (100i)), pdFALSE, (void) i, TimerCallback); } //start timers for(i=1;i<6;i++) timer_start(i); } FreeRTOSConfig.h

define configUSE_TIMERS 1

define configTIMERTASKPRIORITY ( 3 )

define configTIMERQUEUELENGTH 10



xTimerStart hangs the application

One possible issue is that timer callbacks aren’t supposed to block, and depending on how printf is implemented, it might not be suitable for use in a timer callback. If you use a debugger to stop the system, (and have configASSERT defined) does it show you caught on an assert, and if so which one?

xTimerStart hangs the application

Thanks for pointer. You are right.. the problem was due to printf’s in callback routine. Now I can see the timer getting started. Maybe we can document that timer callbacks should not be blocked (as a NOTE) or maybe this is basic thing which I’m not aware of 🙁 Thank you.

xTimerStart hangs the application

See https://www.freertos.org/RTOS-software-timer.html: “Important information on writing timer callback functions Timer callback functions execute in the context of the timer service task. It is therefore essential that timer callback functions never attempt to block. For example, a timer callback function must not call vTaskDelay(), vTaskDelayUntil(), or specify a non zero block time when accessing a queue or a semaphore. ”

xTimerStart hangs the application

thank you