This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

fstorage: writting and then reading 'wrong' data?

Env: nrf52, sdk15, ubuntu, SES


Hi
First steps on fstorage. As I just need to store and read an array of some bytes I have chosen fstorage

...

NRF_FSTORAGE_DEF(nrf_fstorage_t fstorage) =
{
    .evt_handler = fstorage_evt_handler,
    .start_addr = 0x3e000,
    .end_addr   = 0x3ffff,
};

...
printf("fstorage example started.\n");

nrf_fstorage_api_t * p_fs_api;

printf("SoftDevice is present.\n");
printf("Initializing nrf_fstorage_sd implementation...\n");

p_fs_api = &nrf_fstorage_sd;
uint32_t rc = nrf_fstorage_init(&fstorage, p_fs_api, NULL);
APP_ERROR_CHECK(rc);
print_flash_info(&fstorage);


(void) nrf5_flash_end_addr_get();


m_data          = 0xFFFFFFFF;
const uint32_t m_data_read  ;

printf("Writing \"%x\" to flash.\n", m_data);
rc = nrf_fstorage_write(&fstorage, 0x3e000, &m_data, sizeof(m_data), NULL);
APP_ERROR_CHECK(rc);

wait_for_flash_ready(&fstorage);
printf("Done.");

rc = nrf_fstorage_read(&fstorage, 0x3e000, &m_data_read,sizeof(m_data_read));
APP_ERROR_CHECK(rc);
printf("Reading \"%x\" from flash.\n", m_data_read);

and I got this as output:


fstorage example started.
SoftDevice is present.
Initializing nrf_fstorage_sd implementation...
Writing "ffffffff" to flash.
Done.Reading "746f6e20" from flash.
Template example started.

It was written ffffffff but read 746f6e20

Another doubt: How Do we know if the flash is being written for the first time or not? I want to write it if it was not written yet.

Thanks a lot

Alex

Parents Reply Children
  • I tried to read without writing in the same iteration but got the same output.

    I have just an array to write so I am going to try to erase the page always before writing the array and find out if the problem is that. It could be that reason as I never erase page and I have tested with different contents for array

    Thanks

  • Well of course you're going to get the same output if you read twice the same address without writing in between. What did you expect?

  • Same output, I meant this:

    fstorage example started.
    SoftDevice is present.
    Initializing nrf_fstorage_sd implementation...
    Done.Reading "746f6e20" from flash.
    Template example started.

    which means that even if I just read, the value read is not ffffffff (last written). That could be justified by: as I never did an erase, and tried to write lots of things i could never get the expected vaue (ffffffff) because of the reason pointed by Jorgen.

    Now If I erase and then if I write ffffffff and can read ffffffff! :-)

    Solved!

    I was missing that flash property about "A flash write operation can only change bits from 1 to 0, to change a 0 to a 1 requires a erase operation,"

    Thanks to all

    Alex

Related