AnsweredAssumed Answered

MFS on USB flash drive - sector not found error

Question asked by gorakk on Apr 1, 2014
Latest reply on Jul 9, 2015 by gorakk

I am working on a project that is using a USB flash drive.  It saves data to a file one character at a time. 


The system will run fine for some amount of time, writing characters to the flash drive.  At some point though, the write() will result in an MFS_SECTOR_NOT_FOUND error.


I have a test running where a 1000 character string is written to the file on the flash drive every 5 seconds. Different drives will fail after different a number of writes.  Some drives will go for several hours before there is an error and others will fail after a couple of minutes.  Each drive is fairly consistent with how long it will run before it fails.


Below is the code that handles the write.  The file is opened before calling this function.  After all characters are written the file is closed.


void addCharacterToFile( char *c )
    uint32_t error = MFS_NO_ERROR;

    if ( filePointer != NULL )
        write( filePointer, c, 1 );
        error = _io_ferror( filePointer );  
        if ( MFS_SECTOR_NOT_FOUND == error )
            printf( "sector not found\n" );
        else if ( MFS_NO_ERROR != error )
            printf( "mfs error\n" );


Could writing the string to the file one character at a time be part of the problem?  The ability to save data to a flash drive is a change to an existing system - it previously sent this data to a serial port and the code outputs the data one character at a time.  If anyone thinks it would help - I could buffer up some arbitrary number of characters before writing to the flash drive.


Using CodeWarrior 10.5, MQX 4.0, MFS, USB host