Reading and Writing to flash on xDot

For the xDot model you should use the nvmRead and nvmWrite functions to save and read from the flash.

The address range specified in the description of the function (0-0x17FF) is the valid range for user data.  Factory settings and session information are held in protected space that cannot be accessed.

You should also make sure the calls return true, indicating the operation succeeded.

Details of these functions are in the mDot.h file:
https://os.mbed.com/teams/MultiTech/code/libxDot-mbed5/docs/aff2c05aacce/mDot_8h_source.html


Below is the information on the nvmRead/nvmWrite functions from the mDot.h file:


///////////////////////////////////////////////////////////////
// EEPROM (Non Volatile Memory) Operation Functions for xDot //
        ///////////////////////////////////////////////////////////////
        
// Write to EEPROM
// addr - address to write to (0 - 0x17FF)
// data - data to write
// size - size of data
// returns true if successful
bool nvmWrite(uint16_t addr, void* data, uint16_t size);



// Read from EEPROM
// addr - address to read from (0 - 0x17FF)
// data - buffer for data
// size - size of buffer
// returns true if successful
bool nvmRead(uint16_t addr, void* data, uint16_t size);




Below is an example of writing to flash using nvmWrite():

bool ret;
char* data = "e";
mDot* dot = NULL;
lora::ChannelPlan* plan = NULL;
plan = new lora::ChannelPlan_US915();
assert(plan);
dot = mDot::getInstance(plan);
assert(dot);
ret = dot->nvmWrite(1, (void*)data, 1);
if (! ret) {
    // error handling
}



Below is an example of reading using nvmRead():

char data1[1];
ret = dot->nvmRead(1, (void*)data1, 1);
if (!ret) {
    // error handling
}