# FreeRTOS timer not stopping

**URL:** <https://forums.freertos.org/t/freertos-timer-not-stopping/6277>\
**Category:** Kernel\
**Created:** [November 16, 2016, 1:34pm UTC](https://forums.freertos.org/t/freertos-timer-not-stopping/6277 "2016-11-16T13:34:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [November 16, 2016, 1:34pm UTC](https://forums.freertos.org/t/freertos-timer-not-stopping/6277/1 "2016-11-16T13:34:27Z")

</div>

**[ksoldavin](https://sourceforge.net/u/ksoldavin/)** wrote on [Wednesday, November 16, 2016](https://sourceforge.net/p/freertos/discussion/382005/thread/ef6e3a71/#8190):

I am having an issue with my timer code under FreeRTOS v9.0 using an STM32F4. I am trying to create a one shot timer with a period of 1000mS. The timer is being activated correctly and the callback function is being run, but after it has finished it is repeatedly called again 1000mS later.

My timer is being set up as follows:

```auto
static void SerialTimerCallback( TimerHandle_t pxExpiredTimer );
static TimerHandle_t SerialTimerHandle = NULL;

SerialTimerHandle = xTimerCreate("Video DMA Timer", 1000, pdFALSE, ( void * ) 123, SerialTimerCallback );

static void SerialTimerCallback( TimerHandle_t pxExpiredTimer )
{
	printf("Timer expired\n");
    // Do other stuff
}

```

I have also tried making the timer auto reload and calling the stop timer command in my callback with the same result.

Any suggestions?

Thank you  
Keith

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [November 16, 2016, 3:02pm UTC](https://forums.freertos.org/t/freertos-timer-not-stopping/6277/2 "2016-11-16T15:02:49Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Wednesday, November 16, 2016](https://sourceforge.net/p/freertos/discussion/382005/thread/ef6e3a71/#8190/138c):

I’ve never come across that symptom before. Is anything else using the  
SerialTimerHandle handle in any way? Could it be accidentally reset by  
any other code? Where is xTimerCreate() being called from? Could it be  
accidentally created more than once?

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [November 17, 2016, 11:53am UTC](https://forums.freertos.org/t/freertos-timer-not-stopping/6277/3 "2016-11-17T11:53:31Z")

</div>

**[ksoldavin](https://sourceforge.net/u/ksoldavin/)** wrote on [Thursday, November 17, 2016](https://sourceforge.net/p/freertos/discussion/382005/thread/ef6e3a71/#70a4):

Thank you for responding. The timer is being created in my init code that is efinately only run once. Aside from that I have code that checks if SerialTimerHandle is NULL and only tries to create it if it is. I just looked over my code and the only place the timer is touched is when it is initialized.

Keith

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [November 17, 2016, 3:18pm UTC](https://forums.freertos.org/t/freertos-timer-not-stopping/6277/4 "2016-11-17T15:18:00Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Thursday, November 17, 2016](https://sourceforge.net/p/freertos/discussion/382005/thread/ef6e3a71/#70a4/ca12):

This is very odd, and perhaps it is a simple data corruption that has  
effected the timer’s structure.

Place a break point on the function prvProcessExpiredTimer(), which is  
in FreeRTOS/Source/timers.c. The break point will get hit when your  
timer expires. Step through the function and see what happens - there  
is a line “if( pxTimer-\>uxAutoReload == ( UBaseType\_t ) pdTRUE )” - if  
it goes through there then the timer thinks it is an auto reload timer.  
If that is the case it would indeed seem to have been corrupted - in  
which case restart the application and step through the code that  
creates the timer. pxTimer-\>uxAutoReload should get set to pdFALSE (0)

- does it? If it does then you will have to try and catch the place  
where it gets overwritten - the easiest way of doing that would be to  
put a data watchpoint on the pxTimer-\>uxAutoReload memory address that  
will automatically stop the code when that memory address gets written to.
