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

Related