# Timer callback function is not executing

**URL:** <https://forums.freertos.org/t/timer-callback-function-is-not-executing/8522>\
**Category:** Kernel\
**Created:** [December 31, 2019, 9:07am UTC](https://forums.freertos.org/t/timer-callback-function-is-not-executing/8522 "2019-12-31T09:07:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mansoor](https://avatars.discourse-cdn.com/v4/letter/m/8797f3/32.png) [@mansoor](https://forums.freertos.org/u/mansoor)\
**Post date:** [December 31, 2019, 9:07am UTC](https://forums.freertos.org/t/timer-callback-function-is-not-executing/8522/1 "2019-12-31T09:07:01Z")

</div>

Hi,  
I am testing softwareTimer APIs . i copies example code from the freeRTOS manuel 10.0.0 where Timer is creating and starting after which callback fuction is not executing  
I am not creating other tasks in the project. this is just to test the timer APIs.  
The platform i am using SYNOPSYS MetaWare IDE ARCem9D processor.

- The code is as follows

static void vTimerCallback( TimerHandle\_t xTimer )  
{  
printf(“timer callback is created\n”);  
}  
int main(void)  
{  
TimerHandle\_t xTimers = NULL;

```
 xTimers = xTimerCreate( /* Just a text name, not used by the RTOS kernel. */
		                 "Timer",
						 /* The timer period in ticks, must be greater than 0. */
						 10,
						 /* The timers will auto-reload themselves when they expire. */
						 pdFAIL,
						 /* The ID is used to store a count of the number of times the timer has expired, which is initialized to 0. */
						 ( void * ) 0,
						 /* Each timer calls the same callback when it expires. */
						 vTimerCallback );

 if( xTimers == NULL )
 {
	 printf("/* The timer was not created. */\n ");
 }
 else
 {
	 printf("timer is created\n");

	 /* Start the timer.No block time is specified, and even if one was it would be ignored because the RTOS scheduler has not yet been started. */
	 if( xTimerStart( xTimers, 1 ) == pdPASS)
	 {
		 printf("timer is started\n");
	 }
 }
vTaskStartScheduler();

```

}

OUTPUT:  
timer is created  
timer is started

if timer is starting, after timer expires the callback functions should execute may i know what is the problem and why it is not executing.  
I think if timer is creating it means that the configurations are correct?

---

<div class="post-metadata">

**Author:** ![richard-damon](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/richard-damon/32/38_2.png) [@richard-damon](https://forums.freertos.org/u/richard-damon)\
**Post date:** [December 31, 2019, 3:08pm UTC](https://forums.freertos.org/t/timer-callback-function-is-not-executing/8522/3 "2019-12-31T15:08:46Z")

</div>

I see two possible issues that might be at work.

First, your printf implementation may not be compatible with FreeRTOS, especially if it is based on ‘semi-hosting’.

Second, it is possible that you project is setup wrong and the tick interrupt isn’t being installed right, or the system is halting on an assertion.

The first test would be to after starting the program and letting it run a bit, stop it with the debugger and see where the program is running, to make sure is IS still running. Also check the tick counter to see that it has been incrementing.

---

<div class="post-metadata">

**Author:** ![mansoor](https://avatars.discourse-cdn.com/v4/letter/m/8797f3/32.png) [@mansoor](https://forums.freertos.org/u/mansoor)\
**Post date:** [January 2, 2020, 8:58am UTC](https://forums.freertos.org/t/timer-callback-function-is-not-executing/8522/4 "2020-01-02T08:58:02Z")

</div>

Hi sir,  
Thanks for the Reply

Sir printf implementation may not be compatible with FreeRTOS means, we are not suppose to use printf inside the call Back function?

 ![Screenshot of debugging](https://d2v6vdsk2p900z.cloudfront.net/original/1X/a73363b4c45ac16fb948979056fc350a031a19a7.png)

I have tested the program and attached the screenshot in step-by-step debugging process xtimerStart is entering to TickType\_t xTaskGetTickCount( void ) after which, coming out of this function xtimerStart enters into xTimerGenericCommand() function after coming out of this vTaskStartScheduler(); will execute and terminates.

xTickCount is not incrementing.

“tick interrupt isn’t being installed right”??  
how will we get to know this and how to install this and tick counter is not incrementing means how to make tick interrupt work??

in my previous query related to message buffer functionality with vTaskDelay() it is not working, without which it is working fine for this also i got a reply that tick interrupt is not working.

please kindly let me know how to work on tick interrupt.

For the attachment of the project Zip file new user not allowed for this process.

Thanks and Regards  
Mansoor Basha

---

<div class="post-metadata">

**Author:** ![richard-damon](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/richard-damon/32/38_2.png) [@richard-damon](https://forums.freertos.org/u/richard-damon)\
**Post date:** [January 2, 2020, 1:03pm UTC](https://forums.freertos.org/t/timer-callback-function-is-not-executing/8522/5 "2020-01-02T13:03:20Z")

</div>

Since xTickCount is 0, either the system crashed (or hasn’t started) before the first tick or the tick interrupt isn’t enabled. Since this call is from main, you probably haven’t started FreeRTOS yet.

As for printf, the issue is that for many systems, the inbuilt printf function may use features that give FreeRTOS issues, like using a ‘semi-hosting’ driver that ‘takes over’ the machine to send characters to the debugger.

You say that vTaskStartScheduler() termintates? Is it getting an out of memory error, if so that would explain nothing starting. It will need to create the Idle and TImer tasks, and if it can’t get the memory for those it will just stop and die.
