Cortex-M3 simulation problem.

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

Cortex-M3 simulation problem.

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.

Cortex-M3 simulation problem.

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.