Hi,
I try to store some variables into the flash memory using the fstorage library provided by nordic. From the example I got the following implementations for testing:
#define ADDR_TEST_START 0x4F000
#define ADDR_TEST_FINISH 0x5F000
...
NRF_FSTORAGE_DEF(nrf_fstorage_t fstorage) =
{
/* Set a handler for fstorage events. */
.evt_handler = fstorage_evt_handler,
/* These below are the boundaries of the flash space assigned to this instance of fstorage.
* You must set these manually, even at runtime, before nrf_fstorage_init() is called.
* The function nrf5_flash_end_addr_get() can be used to retrieve the last address on the
* last page of flash available to write data. */
.start_addr = ADDR_TEST_START,
.end_addr = ADDR_TEST_FINISH,
};
...
/* Test */
nrf_fstorage_api_t * p_fs_api;
p_fs_api = &nrf_fstorage_sd;
ret_code_t rc = nrf_fstorage_init(&fstorage, p_fs_api, NULL);
__LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "ret code init: %d\n",rc);
rc = nrf5_flash_end_addr_get();
__LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "ret code end addr: %d\n",rc);
rc = nrf_fstorage_erase(&fstorage, fstorage.start_addr, 8, NULL);
__LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "ret code erease addr: %d\n",rc);
uint8_t data[8] = {1,2,3,4,5,6,7,8};
uint8_t data2[8] = {0};
rc = nrf_fstorage_write(&fstorage, ADDR_TEST_START, &data, 8, NULL);
__LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "ret code write: %d\n",rc);
wait_for_flash_ready(&fstorage);
rc = nrf_fstorage_read(&fstorage, ADDR_TEST_START, &data2, 8);
__LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "ret code read: %d\n",rc);
wait_for_flash_ready(&fstorage);
for(uint8_t i = 0; i < 8; i++)
{
__LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Data2 %d: %d\n",i,data2[i]);
}
I always get the error code 16 back, which means invalid address. So what am I doing wrong here? How do I get valid addresses, that are aligned with pages?