Making a HALCoGen (v.04.00.00) FreeRTOS project for 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.
Parameters from FreeRTOSConfig.h
#define configUSE_TIMERS 1
#define configTIMER_TASK_PRIORITY ( configMAX_PRIORITIES - 2 )
#define configTIMER_QUEUE_LENGTH 10
#define configTIMER_TASK_STACK_DEPTH ( 128 )
The Code
#include " #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) {
// timer creation
xTimer1 = xTimerCreate((const signed char *)"Timer1", 80 / portTICK_RATE_MS, pdFALSE, (void*) 0, vTimerFunction);
// reset timer
if (xTimer1 != NULL)
xTimerReset(xTimer1, 0);
// task self-destruction
vTaskDelete( NULL );
}
Using Assemly Step Into while calling xTimerCreate shows, that prefetch exception occures directly after uC tries to execute instruction BL xTimerCreate (look at the screenshot).
So, calling xTimerCreate causes 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.
P.S. Othe FreeRTOS modules - tasks execution, queues, semaphores - work excelent. Except software timers.
The complete CCS project is attached.
What's wrong?
