FreeRTOS Support Archive
The FreeRTOS support forum is used to obtain active support directly from Real
Time Engineers Ltd. In return for using our top quality software and services for
free, we request you play fair and do your bit to help others too! Sign up
to receive notifications of new support topics then help where you can.
This is a read only archive of threads posted to the FreeRTOS support forum.
The archive is updated every week, so will not always contain the very latest posts.
Use these archive pages to search previous posts. Use the Live FreeRTOS Forum
link to reply to a post, or start a new support thread.
[FreeRTOS Home] [Live FreeRTOS Forum] [FAQ] [Archive Top] [September 2009 Threads] Cortex-M3 simulation problem.Posted by Roberto Bonacina on 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
RE: Cortex-M3 simulation problem.Posted by Richard Damon on September 30, 2009 functions that implement tasks should not return, and normally have built int them an infinite loop like a while(1){} or for(;;){} loop. your tasks execute the code once and then return which will cause a crash.
It might be nice if FreeRTOS directed tasks that returned to a routine to handle this, but it currently doesn't and returning from a task function will just crash.
RE: Cortex-M3 simulation problem.Posted by Richard on September 30, 2009 If you wish to terminate a task it is necessary to delete it. The follow structure works:
void vATask( void ) { for( ;; ) { /* Do some work here. */
if( some situation arises ) { break; } }
/* Task must be deleted before the end of the function is reached. */ vTaskDelete( NULL ); }
regards.
p.s. I wrote the code in a text editor, indented it all, then pasted it into this text box, and it is appearing correctly in the preview pane at least.
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.
|