Trying to read/write into a file but it is failing

I am using the BC660K and checking the examples from the SDK: example_fs.cto open/read/write/close a file.

Basically, what I am doing is to log into this file some trace messages of the firmware being developed.
And, upon a restart, I can read this file and see where it stopped to write, for example.

So far, over my debug messages, I can see that it is working well up to this:
1 - Open file (mode is QL_READ_WRITE_CREATE_ALWAYS)
2 - Write into the file (func is returning the number of bytes written)
3 - Close the file
4 - Restart the module
5 - Open the file (mode is QL_READ_WRITE_CREATE_ALWAYS)
6 - Read the file <== here it is failing

I do not know why the read operation is happening.
Also checked on the example_fs.c and it does a seek right after opening the file, and right before reading it.
I just did the same, but with no success, the read operation returns zero data read.

Here is the snippet where it is returning no data read:

    Ql_FS_Read(fp, buf, 200, &read);

    if (read == 0)
    {
        debugPrint("ERROR reading, %s:%d, %s", __func__, __LINE__, buf);
        return false;
    }

Just found the problem, below is the solution:

In step 5, I changed the mode to QL_READ_ONLY, and then the file could be read successfully.

Yes, you are great, thanks for sharing

1 Like