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
~~~~
define configUSE_TIMERS 1
define configTIMERTASKPRIORITY ( configMAX_PRIORITIES – 2 )
define configTIMERQUEUELENGTH 10
define configTIMERTASKSTACK_DEPTH ( 128 )
~~~~
The code
~~~~
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
~~~~
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…