This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

RTOS/OMAP-L138: Destroyed data - SYS/BIOS - OMAPL138 - FatFs

Part Number: OMAP-L138
Other Parts Discussed in Thread: OMAPL138

Tool/software: TI-RTOS

I used FatFs in my project with Sys/BIOS. I have a problem, because when I writting data to SD card I sometimes lost some data (sometimes all). When I push card to PC I don't see any files but it is partially occupied. In ffconfig.h I have FS_REENTRANT = 0 (maybe here is problem?). I tested different cards. 

My short code is below.

...
FATFS_init();
...
FATFS_open(0U, NULL, &fatfsHandle);
...
for (j=0; j<20; j++){
	sprintf(fname, "aa_%i.txt", j);
	
	fresult = f_open(&MyFile, fname, FA_OPEN_ALWAYS | FA_WRITE);
	
	for(i = 0; i < 10; i++){
		f_lseek(&MyFile, f_size(&MyFile));
		fresult = f_write(&MyFile, tab_string, ile_byte, (void *)&wbytes);
		if(fresult == FR_OK){	
		//...
		}
		else{
		//...
		}
	}
	fresult = f_close(&MyFile);
}
...
Task_sleep(20000); //I'm pulling out the card
  • Hi,

    Which Processor SDK RTOS version are you using?

    Best Regards,
    Yordan
  • I am using:
    -> processor_sdk_rtos_omapl138_5_01_00_11
    -> bios_6_73_00_12
    -> pdk_omapl138_1_0_6
  • Hello,

    We have an MMCSD FatFs example in Processor SDK. Can you take a look at it for reference? There may be something you have missed.

    You can create the example by following the instructions here:
    software-dl.ti.com/.../index_device_drv.html

    Documentation on MMCSD can be found here:
    software-dl.ti.com/.../index_device_drv.html
  • My code is similar and I have not missed anything.
    I noticed that when I use threads in which are while(1) loop + task_sleep(X) I have a problem with write date to sd card.
    After some time, the data is damaged (different time each time).
    Loops are empty, it does not change anything
    e.g content other task:
    while (1)
    {
    Task_sleep (5);
    }
    When I deleted all task (or while(1) loops) the problem does not occur.
    The task to write data to the SD card has the highest priority.

    Where is the problem?
  • In the ffconfig.h header I defined FF_FS_REENTRANT = 1 and my handlers function added to the project:

    /*
     * Copyright (c) 2012, Texas Instruments Incorporated
     * All rights reserved.
     *
     * Redistribution and use in source and binary forms, with or without
     * modification, are permitted provided that the following conditions
     * are met:
     *
     * *  Redistributions of source code must retain the above copyright
     *    notice, this list of conditions and the following disclaimer.
     *
     * *  Redistributions in binary form must reproduce the above copyright
     *    notice, this list of conditions and the following disclaimer in the
     *    documentation and/or other materials provided with the distribution.
     *
     * *  Neither the name of Texas Instruments Incorporated nor the names of
     *    its contributors may be used to endorse or promote products derived
     *    from this software without specific prior written permission.
     *
     * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
     * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
     * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
     * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
     * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     */
    /*
     * ======== syncsysbios.c ========
     *
     * Synchronization support for FatFS using SYS/BIOS
     */
    
    #include <xdc/std.h>
    #include <ti/sysbios/knl/Semaphore.h>
    
    #include "ff.h"
    
    typedef int BOOL;
    
    #if FF_FS_REENTRANT
    
    /*------------------------------------------------------------------------
     * Create a Synchronization Object for a Volume
     * This function is called in f_mount function to create a new
       synchronization object, such as semaphore and mutex. When a FALSE is
      returned, the f_mount function fails with FR_INT_ERR.
      returns: TRUE: Function succeeded, FALSE:Could not create due to any error
    */
    
    BOOL ff_cre_syncobj (
            BYTE vol,        /* Corresponding logical drive being processed */
            FF_SYNC_t* sobj    /* Pointer to return the created sync object */
    )
    {
        int ret;
    
        *sobj = Semaphore_create(1, NULL, NULL);
        ret = (*sobj != NULL) ? TRUE : FALSE;
    
        return ret;
    }
    
    
    
    /*------------------------------------------------------------------------*/
    /* Delete a Synchronization Object                                        */
    /*------------------------------------------------------------------------*/
    /* This function is called in f_mount function to delete a synchronization
    /  object that created with ff_cre_syncobj function. When a FALSE is
    /  returned, the f_mount function fails with FR_INT_ERR.
    /  returns: TRUE: Function succeeded, FALSE: Could not delete due to any error
    */
    
    BOOL ff_del_syncobj (
            FF_SYNC_t sobj  /* Sync object tied to the logical drive to be deleted */
    )
    {
        Semaphore_delete((Semaphore_Handle *)&sobj);
    
        return TRUE;
    }
    
    
    
    /*------------------------------------------------------------------------*/
    /* Request Grant to Access the Volume                                     */
    /*------------------------------------------------------------------------*/
    /* This function is called on entering file functions to lock the volume.
    /  When a FALSE is returned, the file function fails with FR_TIMEOUT.
    /
    /  returns:  TRUE: Got a grant to access the volume, FALSE: Could not get a
    /            grant
    */
    
    BOOL ff_req_grant (
            FF_SYNC_t sobj        /* Sync object to wait */
    )
    {
        return Semaphore_pend((Semaphore_Handle)sobj, FF_FS_TIMEOUT);
    }
    
    
    
    /*------------------------------------------------------------------------*/
    /* Release Grant to Access the Volume                                     */
    /*------------------------------------------------------------------------*/
    /* This function is called on leaving file functions to unlock the volume.
    */
    
    void ff_rel_grant (
            FF_SYNC_t sobj        /* Sync object to be signaled */
    )
    {
        Semaphore_post((Semaphore_Handle)sobj);
    }
    
    
    #endif
    

  • For those that come across this thread, this discussion was continued here: https://e2e.ti.com/support/processors/f/791/t/777118