Q:

Atmel UC3A0512 FAT API problems after defining FREERTOS_USED symbol

I'am using FAT API provided by ASF to read data from the flash, 
The FAT API uses a global variable fs_g_status to help debugging the problems, but it seems that  fs_g_status takes 
meaningless values:
Possible values for fs_g_status :
#define  FS_ERR_HW               (FAIL+0)    //!< Hardware driver error
#define  FS_ERR_NO_FORMAT        (FAIL+1)    //!< The selected drive isn't formated
#define  FS_ERR_NO_PART          (FAIL+2)    //!< The selected partition doesn't existed
#define  FS_ERR_NO_SUPPORT_PART  (FAIL+3)    //!< The selected partition isn't supported
#define  FS_ERR_TOO_FILE_OPEN    (FAIL+4)    //!< The navigation have already opened a file
#define  FS_ERR_END_OF_DRIVE     (FAIL+5)    //!< There are not other driver
#define  FS_ERR_BAD_POS          (FAIL+6)    //!< The position is over the file
#define  FS_ERR_FS               (FAIL+7)    //!< File system error
#define  FS_ERR_NO_FIND          (FAIL+8)    //!< File no found
#define  FS_ERR_ENTRY_EMPTY      (FAIL+9)    //!< File entry empty
#define  FS_ERR_ENTRY_BAD        (FAIL+10)   //!< File entry bad
#define  FS_ERR_ENTRY_BADTYPE    (FAIL+11)   //!< File entry type don't corresponding
#define  FS_ERR_NO_DIR           (FAIL+12)   //!< The selected file isn't a directory
#define  FS_ERR_NO_MOUNT         (FAIL+13)   //!< The partition isn't mounted
#define  FS_ERR_NO_FILE_SEL      (FAIL+14)   //!< There are no selected file
#define  FS_NO_LAST_LFN_ENTRY    (FAIL+15)   //!< The file entry isn't the last long file entry

#define  FS_ERR_ID_FILE          (FAIL+17)   //!< The file identifier is bad
#define  FS_ERR_NO_FILE          (FAIL+18)   //!< The selected file entry isn't a file
#define  FS_LUN_WP               (FAIL+19)   //!< Drive is in read only mode
#define  FS_ERR_READ_ONLY        (FAIL+20)   //!< File is on read access only
#define  FS_ERR_NAME_INCORRECT   (FAIL+21)   //!< The name don't corresponding at the filter name
//...

with 
#define FAIL      1

This is the function i use to read data from flash
int read_Flash_Data()
{
  /* initialize FSACCESS mutex and navigators */
  if (b_fsaccess_init())
  { 
    usart_write_line((&AVR32_USART0), " b_fsaccess_init return true \r\n");   
  }
  //fs_g_status = 0x00 OK

  /* Try to init data flash */
  if (at45dbx_mem_check())
  {
    /* display message */
    usart_write_line((&AVR32_USART0), " at45dbx_mem_check return true \r\n");
}
else
{
    /* display error message */
    usart_write_line((&AVR32_USART0),"  at45dbx_mem_check return false\r\n");
    return (-1);
}
//fs_g_status = 0x00 OK

if (nav_drive_set(LUN_ID_1) == false)
{
    usart_write_line((&AVR32_USART0)," nav_drive_set return false \r\n");
    return (-1);
}
//fs_g_status = 0x01 ==> Hardware driver error NOK , but the nav_drive_set(LUN_ID_1) return true !!!!

if( !nav_partition_mount() ) 
{
    usart_write_line((&AVR32_USART0),"nav_partition_mount return false \r\n");
    return (-1);
}
//fs_g_status = 0x04 ==> The navigation have already opened a file, but the nav_partition_mount() return true !!!!

if ((ret = open(ACTUAL_CONFIG_FILE_PATH, O_RDONLY)) < 0)
{
    usart_write_line((&AVR32_USART0),"Opening file failed \r\n");
    return (-1);
}
//fs_g_status = 0x10 ==16(decimal) open return true !!!!
//...
}

I think that this is not logic, fs_g_status should only be set if the functions return false.
OK let's say that there is minor problems and major ones that lead the functions to fail and the comments are not good enough.
Now this function is used in a freeRTOS task and i have to define the symbol FREERTOS_USED in the compilation to protect flash in concurent access, in the description above the symbol wasn't defined.
and now nav_partition_mount() return false and fs_g_status = 0x01.
Does anyone encounter the problem i can't seem to find ways  to debug the problem, any suggestion is welcome.

A:

You forgot to initialize the ctrl_access_semphr, 
you have to use the function ctrl_access_init defined in ctrl_access.c. 
#ifdef FREERTOS_USED

bool ctrl_access_init(void)
{
 // If the handle to the protecting semaphore is not valid,
 if (!ctrl_access_semphr)
 {
   // try to create the semaphore.
   vSemaphoreCreateBinary(ctrl_access_semphr);

   // If the semaphore could not be created, there is no backup solution.
   if (!ctrl_access_semphr) return false;
  }

 return true;
}
#endif

Your function should look like :
int read_Flash_Data()
{
  /* initialize FSACCESS mutex and navigators */
  if (b_fsaccess_init())
  {   
    usart_write_line((&AVR32_USART0), " b_fsaccess_init return true \r\n");   
  }

  /* initialize ctrl_access semaphore */
  if (ctrl_access_init())
  {
    usart_write_line((&AVR32_USART0), " ctrl_access_init return true \r\n");
  }
  //......

