using mDot Lib's writeUserFile not saving data to flash.

Home Forums mDot/xDot using mDot Lib's writeUserFile not saving data to flash.

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #14300
    Ajay K
    Participant

    I am trying to create a file and save data to the flash using the code below. However no data is being saved. I think the file is created successfully because I get a valid non-negative file handle. However the writeUserFile returns a negative value indicating I am guessing no data was saved to the file. Not sure if I am using the API incorrectly?

    mDot::mdot_file file = pDot->openUserFile("test.dat", mDot::FM_CREAT);
    if(file.fd >= 0) {
        uint16_t testData = 1000;
        int nBytesWrittern = pDot->writeUserFile(file, &testData, sizeof(uint16_t));
        printf("Bytes Written :%d\n",nBytesWrittern);
        pDot->closeUserFile(file);
    }
    else {
        printf("Invalid File Handle while creating the file.\n");
    }

    Thanks,
    Ajay.

    #14314
    Ajay K
    Participant

    Any Ideas as to why the writeUserFile API call is failing? I have set the log level to tracel_level for the mdot. However I don’t see any trace logs to see what the underlying issue may be for the write failures.

    I was hoping to resolve this issue quickly, as I need to test the mdot under deep sleep mode and when it wakes up to be able to read this file that I saved before the mdot going into deep sleep mode.

    Thanks,
    Ajay.

    #14316
    Jason Reiss
    Keymaster

    Can you provide debug output?

    #14318
    Ajay K
    Participant

    Hi Jason,

    I set the log level to trace_level and there were no trace debug outputs generated for the writeUserFile call. However I tried using another API call appendUserFile which is mentioned below and it worked fine. However I am assuming in this API call the file will be opened and closed every time I call this API correct? If so I am not sure if its efficient to open and close the file repeatedly and so I was using the writeUserFile API Call described earlier in this forum thread.

    bool appendUserFile(const char* file, void* data, uint32_t size);

    In reality I would be writing out a vector containing structs with fixed size containing data that needs to be stored and reloaded after a deep sleep.

    Thanks,
    Ajay.

    #14320
    Jason Reiss
    Keymaster

    The file should be opened for writing.

    mDot::mdot_file file = dot->openUserFile(“test.dat”, mDot::FM_CREAT | mDot::FM_WRONLY);

    #14323
    Ajay K
    Participant

    Thanks Jason, that worked. By the way mDot::FM_CREAT does it create files always or if it exists, the file is overwritten?

    #14324
    Mike Fiore
    Blocked

    Ajay,

    FM_CREAT creates the file if it does not exist, but I don’t think it overwrites an existing file.

    I think the files default to read-only when you open them, so you have to explicitly state that you want to write when you open it.

    Cheers,

    Mike

    #14329
    Steeve Zissou
    Participant

    I have the same kind of issue with writing fie on flash memory.
    @Ajay, could you provide an update on your solution?
    Thanks!

    #14330
    Steeve Zissou
    Participant

    Ok, now it seems that I can write data into a file stored in the flash memory.
    Can I access such a file with my PC?
    If this is not doable how can mDot write to data to a file that is accessible with my PC?
    thanks,

    #14334
    Jason Reiss
    Keymaster

    The bootloader is part of the mDot platform and can be accessed by sending to the debug serial port just after reseting the device.

    User files in the flash memory are saved with a ‘u_’ prefix prepended to the supplied name through libmDot api. Also if a file is uploaded with the prefix it should show in the libmDot file list.

    bootloader :>
    bootloader :> help
    Available commands:
    help: display this message
    boot: start user application
    upgrade : upgrade to new firmware transferred over serial
    transfer : transfer new firmware over serial, but don’t flash it
    recv simple : read file into the filesystem over serial
    recv ymodem [filename]: read file into the filesystem over serial
    send
    : send file from the filesystem over serial
    flash: flash new firmware that has already been transferred
    reset: perform a soft reset of the system
    delete
    : delete the specififed file from the filesystem
    erase: erase entire 2MB external flash – BE SURE YOU WANT TO DO THIS!

Viewing 10 posts - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.