# Problem with calling Software Timer functions

**URL:** <https://forums.freertos.org/t/problem-with-calling-software-timer-functions/5143>\
**Category:** Kernel\
**Created:** [August 31, 2014, 6:27pm UTC](https://forums.freertos.org/t/problem-with-calling-software-timer-functions/5143 "2014-08-31T18:27:24Z")\
**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:** [August 31, 2014, 6:27pm UTC](https://forums.freertos.org/t/problem-with-calling-software-timer-functions/5143/1 "2014-08-31T18:27:24Z")

</div>

**[account002](https://sourceforge.net/u/account002/)** wrote on [Sunday, August 31, 2014](https://sourceforge.net/p/freertos/discussion/382005/thread/e3720f77/#6243):

Making a FreeRTOS project for TI Hercules RM48 microcontroller.

Got a problem with Software Timer functions (**xTimerCreate()**, **xTimerReset()**, **xTimerStop()** etc.):  
_calling any of then inside a task causes a PREFETCH exception of the microcontroller._

Calling them inside **main** function is ok.

FreeRTOS v.7.4.0

**Parameters from FreeRTOSConfig.h**

```auto
#define configUSE_TIMERS 1
#define configTIMER_TASK_PRIORITY ( configMAX_PRIORITIES - 2 )
#define configTIMER_QUEUE_LENGTH 10
#define configTIMER_TASK_STACK_DEPTH ( 128 )

```

**The code**

```auto
#include "sys_common.h"
#include "het.h"
#include "gio.h"
#include "FreeRTOS.h"
#include "timers.h"
#include "task.h"

void vTask1(void *pvParameters);

uint32 i = 0;

xTimerHandle xTimer1;

// Timer callback function
void vTimerFunction(xTimerHandle xTimer)
{
	// toggle port bits
	gioToggleBit(hetPORT1, i);
	i++;
	if (i>31)
		i=0;

	// restart timer
	xTimerReset(xTimer1, 0);
}

// Main function
void main(void)
{
	// configure port direction (outputs)
	gioSetDirection(hetPORT1, 0xFFFFFFFF);
	// configure port output pins initial value
	gioSetPort(hetPORT1, 0xFFFFFFFF);

	// creating task
	xTaskCreate(vTask1, (const signed char *)"TimerStart", 1024, NULL, (configMAX_PRIORITIES - 3), NULL);

	vTaskStartScheduler();
	while(1);
}

// Task function
void vTask1(void *pvParameters)
{

	xTimer1 = xTimerCreate((const signed char *)"Timer1", 80 / portTICK_RATE_MS, pdFALSE, (void*) 0, vTimerFunction);
	if (xTimer1 != NULL)
		xTimerReset(xTimer1, 0);

	// task self-destruction
	vTaskDelete( NULL );
}

```

So, calling xTimerCreate causes strange error - prefetch exception.  
Moving block

```auto
	xTimer1 = xTimerCreate((const signed char *)"Timer1", 80 / portTICK_RATE_MS, pdFALSE, (void*) 0, vTimerFunction);
	if (xTimer1 != NULL)
		xTimerReset(xTimer1, 0);

```

into the **main** function (for example, before **vTaskStartScheduler()**) makes code working properly.

_ **What’s wrong?** _  
_ **Any ideas, please…** _

---

<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:** [August 31, 2014, 6:47pm UTC](https://forums.freertos.org/t/problem-with-calling-software-timer-functions/5143/2 "2014-08-31T18:47:36Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Sunday, August 31, 2014](https://sourceforge.net/p/freertos/discussion/382005/thread/e3720f77/#6243/7abc):

> ```
> xTaskCreate(vTask1, (const signed char *)"TimerStart", 1024, NULL, (configMAX_PRIORITIES - 3), NULL);
> 
> ```

I assume without creating the timer you find multiple tasks execute  
correctly?

If so my first suggestion would have been stack overflow, but you have  
given vTask1 a large stack, which I’m almost certain will be fine.  
Worth ensuring stack overflow detection is turned on all the same though.

Your FreeRTOS version is moderately old, and I don’t think a lot of the  
new configASSERT()s were added until V7.6.0, but it is worth ensuring  
that is defined too.

Is the error in xTimerCreate() or xTimerReset()? Can you step through  
whichever function it is and let us know on which line the problem occurs.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [August 31, 2014, 7:42pm UTC](https://forums.freertos.org/t/problem-with-calling-software-timer-functions/5143/3 "2014-08-31T19:42:10Z")

</div>

**[account002](https://sourceforge.net/u/account002/)** wrote on [Sunday, August 31, 2014](https://sourceforge.net/p/freertos/discussion/382005/thread/e3720f77/#f7a7):

Thank you for response.

Actually the original project includes multiple tasks execution, queues, semaphores - everything works excelent.  
After I tried to use Software Timers and got the described error, I wrote a simple version of project, which is shown above.

vTask1 really has a large stack, furthermore in the given project it does nothing, just tries to create timer…  
But I’ll still try to check out everything about stack and configASSERT(). Actually, need to read some documentation before…

When I try to call xTimerCreate, the error is quite strange.  
It’s not “inside” the function.  
Using Assemly Step Into while calling xTimerCreate shows, that prefetch exception occures directly after uP tries to execute instruction **BL xTimerCreate** … (look at the attached screenshot)…

---

<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:** [August 31, 2014, 7:57pm UTC](https://forums.freertos.org/t/problem-with-calling-software-timer-functions/5143/4 "2014-08-31T19:57:50Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Sunday, August 31, 2014](https://sourceforge.net/p/freertos/discussion/382005/thread/e3720f77/#f7a7/3cfa):

I have never seen such an error. In this case I think you need to look  
at the address at which xTimerCreate() is located to see if it is a  
valid address in the hope of finding out why a simple branch instruction  
causes an abort. Could it be an instruction set change problem if the  
timers code is build to pure ARM code? If the address of the function  
looks valid then you will have to try and debug the abort from within  
the abort handler to determine why the abort occurred.

Regards.
