rbonacina wrote on Wednesday, September 30, 2009:
Hello,
I am a newbie in ARM and FreeRTOS.
I am trying to execute a simple program that uses FreeRTOS.
The program has 2 tasks coordinated with a binary semaphore.
Each task takes the semaphore, assigns a variable and then releases the semaphore.
My starting point is given by the STM32F103 demos for IAR and Keil. I simplified them, added my tasks and configured to run in simulation mode (I don’t have a physical target yet).
Here is the code added in main.c
int main( void )
{
#ifdef DEBUG
debug();
#endif
prvSetupHardware();
taskCode = 0;
vSemaphoreCreateBinary(xSemaphore);
xTaskCreate(vFirstPrintTask, "First_Task", 128, NULL,
mainPRINT_PRIORITY, NULL);
xTaskCreate(vSecondPrintTask, "Second_Task", 128, NULL,
mainPRINT_PRIORITY, NULL);
/* Start the scheduler. */
vTaskStartScheduler();
/* Will only get here if there was not enough heap space to
create the idle task. */
return 0;
}
static void vFirstPrintTask(void *pvParameters)
{
if (xSemaphoreTake(xSemaphore, portMAX_DELAY) != NULL)
{
taskCode = 1;
if (xSemaphoreGive(xSemaphore) != pdTRUE)
{
//printf("Semaphore not released by task 1.\n");
}
}
}
static void vSecondPrintTask(void *pvParameters)
{
if (xSemaphoreTake(xSemaphore, portMAX_DELAY) != NULL)
{
taskCode = 2;
if (xSemaphoreGive(xSemaphore) != pdTRUE)
{
//printf("Semaphore not released by task 2.\n");
}
}
}
When I run the program, the semaphore and the tasks are created, then I can see that the second task is executed once. When exiting from this task, the last assembly instruction executed is POP {r4,pc}, then the PC becomes 0x00000000 and a hard fault is generated. The usage fault register has the INVSTATE bit set.
This happens with both IAR and Keil IDEs.
What am I doing wrong?
Could it be possible to add to FreeRTOS a demo like this, in order to make it possible to run it in evaluation IDEs (32K code limited) and in simulation mode?
Thanks,
Roberto