Recommendation for optimization level in Atmel Studio for FreeRTOS+FAT SL

Hello everyone, I am running FreeRTOS v8.2.0 with FreeRTOS+FAT SL on Atmel Cortex M4 SAM4SD16C. I am using Atmel Studio for my project. Recently I have noticed that if I change the optimization level in Atmel Studio to None(-O0) from Optimize(-O1) the FreeRTOS+FAT SL is unable to open a file on SD card. However, If I use Optimize (-O1) the file system can access the file on SD card without any problem. Is there some recommendation for optimization level in Atmel Studio while useg FreeRTOS+FAT SL or FreeRTOS in general? Has anyone experienced this issue before? Please do share. Regards, Owais

Recommendation for optimization level in Atmel Studio for FreeRTOS+FAT SL

Hi Owais, I have never noticed this before. It should work at all optimisation levels, but if there is ever a problem it is normally the other way around – things working with no optimisation but failing at high optimisation. As it is low optimisation that is causing the problem could it be a stack issue? Low optimisation will presumably use more stack. Do you have stack checking turned on? Which driver are you using? SD card driver from the ASF? Can you step through the code to see where it fails? It might be in the FAT code itself, or possibly in the driver. Regards.

Recommendation for optimization level in Atmel Studio for FreeRTOS+FAT SL

Thanks for the response, I am using the FreeRTOS+FAT FS so the file system is designed for RAM but I have modified it to work with SD card by providing read and write low level functions. i am not sure how to do the stack checking if you could please guide me in this regard. Also the problem does not occur while initializing the SD card which is the following part void vInitializeSDCard( void ) { unsigned char ucStatus; //! Initialize the SD card and create the volume //! @code ucStatus = finitvolume( sdinit ); //! @endcode
// It is expected that the volume is not formatted.
if( ucStatus == F_ERR_NOTFORMATTED )
{
    //! Format the created volume with FAT32 FS.
    //! @code
    ucStatus = f_format( F_FAT32_MEDIA );
    //! @endcode
}

if( ucStatus == F_NO_ERROR )
{
    pstring("SD card initialized");
}
else if( ucStatus != F_NO_ERROR )
{
    printf("Error No. %d occurred in SD Card initializationrn", ucStatus);
}
} after this I try to open a file on my SD card which in case of optimization level (-O1) opens successfully whereas in case of optimization set to None(-O0) the following call returns a NULL pxFile = f_open( cFileName, “r” ); I believe there is something I am missing. If so, please do let me know. Regards.

Recommendation for optimization level in Atmel Studio for FreeRTOS+FAT SL

Can you step through the f_open() call to see if it gives a clue as to why it is not happy – that might give a clue as to what went wrong with the initialisation (mounting, formatting, etc.). With optimisation 0 it should be easy to step through. Regards.

Recommendation for optimization level in Atmel Studio for FreeRTOS+FAT SL

Thanks again, One more thing I should mention is that I am accessing the file before the scheduler is started and once I run it on optimization level 1 it is running without any problem until i change the optimization to None and rebuild the project. Note that if i change optimization to None from Level 1 and without rebuilding the solution directly start the project it also runs. That being said i have stepped into the code and found out that the function rc = fn_open( filename, mode ); is returning a 0. Any clue what could be happening? Regards.

Recommendation for optimization level in Atmel Studio for FreeRTOS+FAT SL

If you are accessing the file before the scheduler has started then I think you will need to have FFSTHREAD_AWARE set to 0. Is that the case? Regards.

Recommendation for optimization level in Atmel Studio for FreeRTOS+FAT SL

Yes that is exactly the case I have set the FFSTHREAD_AWARE to 0. Regards.