Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
9 years, 2 months ago.
Overwrite part of file: mDot on STM32F411
Hi,
I'm working on a project using the emBitz IDE and the mDot library on an STM32F411 mBed platform. I have a task to turn a flat log file into a FIFO file. At full stretch, this file will take up most of the available 2MB.
What I'd like to be able to do is seek to a specific location and overwrite the location. My existing code is as follows:
File Seek and Write Snippet
        // Obviously, mdot.h is included and a global object gMdotPtr points at the library
        mDot::mdot_file file = gMdotPtr->openUserFile(FILE_NAME, mDot::FM_RDWR);
        if (file.fd >= 0) {
            // Write the entry at the required location
            bool result = gMdotPtr->seekUserFile(file, mRecordLocation, SEEK_SET);
            if (result) {
                result = gMdotPtr->writeUserFile(file, (void *)pLogRecord, sizeof(T_LogEntry));
                // Move on to the next location
                mRecordLocation += sizeof(T_LogEntry);
                if (mRecordLocation >= mCurrentSize) {
                    mRecordLocation = 0;
                }
            }
            gMdotPtr->closeUserFile(file);
        }
What I'm seeing is that the file write is failing - at least, it's returning a false value and the file contents are unchanged.
Any ideas?
 
                            
Apologies for the formatting of the code. I'm still getting used to the idiosyncrasies of the posting system. Fixed now.
posted by Geoff Field 21 Aug 2016