Hello,
I'm on nrf52DK PCA10040, SDK15.2
I'm sure it's quite basic, but I don't get it. I just need to write actually two uint32_t value in flash memory (so FLASH_DATA_LENGHT =2). For it, I use the last page of my device:
void flash_init()
{
ret_code_t rc;
nrf_fstorage_api_t * p_fs_api;
p_fs_api = &nrf_fstorage_sd;
fstorage.start_addr=nrf5_flash_end_addr_get()-PSTORAGE_FLASH_PAGE_SIZE ;
fstorage.end_addr=nrf5_flash_end_addr_get();
rc = nrf_fstorage_init(&fstorage, p_fs_api, NULL);
APP_ERROR_CHECK(rc);
}
then I made a write_function:
void flash_save()
{
ret_code_t rc = nrf_fstorage_erase(&fstorage, fstorage.start_addr, 1, NULL); //just one page to erase
if (rc != NRF_SUCCESS)
{
NRF_LOG_INFO("nrf_fstorage_erase() returned: %s",
nrf_strerror_get(rc));
}
wait_for_flash_ready(&fstorage);
nrf_fstorage_write(&fstorage,fstorage.start_addr, flash_data, FLASH_DATA_LENGHT*sizeof(uint32_t), NULL);
wait_for_flash_ready(&fstorage);
}
I don't think it's necessary to wait for flash to be ready, mainly for the flash erase, but anyway.
And at last, to be exhaustive, I made a read function
void flash_load()
{
nrf_fstorage_read(&fstorage,fstorage.start_addr, flash_data, FLASH_DATA_LENGHT*sizeof(uint32_t));
}
Ok, so I guess, it's everything for now. My problem, is nrf_fstorage_erase seems to not erase the flash page. I still only can read the very first value I wrote on the board (and it's working very well). nrf_fstorage_erase returns a great NRF_SUCCESS. But When I read the flash memroy after a write operation, it's still the very first value I wrote. So no error, just not working.
By the way, I'm using softdevice, but I really don't think it interferes, and my test are with no connected device (it still very normally advertising).