I'm trying to get some data written and read from flash memory using the fstorage library as explained in the examples provided with the sdk.
I write to flash and get the callback saying that the bytes were written and try to read them back with garbage returned, not sure what i'm missing. I also try to read the memory using the memory viewer in segger embedded studio which is also showing nothing being modified.
I've attached the code for reference just trying to write a 32 bit integer value as i failed to get it to work with anything so i went back to exactly what the example had.
Can someone provide some insights on how to get this working?
#include <string.h> #include "flash_module.h" #include "nrf.h" #include "app_error.h" #include "nrf_fstorage_sd.h" #include "nrf_log.h" static nrf_fstorage_api_t * p_fs_api; static void fstorage_evt_handler(nrf_fstorage_evt_t * p_evt); __ALIGN(4) static uint32_t mac = 0xBADC0FFE; 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 = 0x3e000, .end_addr = 0x3ffff, }; static void fstorage_evt_handler(nrf_fstorage_evt_t * p_evt) { if (p_evt->result != NRF_SUCCESS) { NRF_LOG_INFO("--> Event received: ERROR while executing an fstorage operation."); return; } switch (p_evt->id) { case NRF_FSTORAGE_EVT_WRITE_RESULT: { NRF_LOG_INFO("--> Event received: wrote %d bytes at address 0x%x.", p_evt->len, p_evt->addr); } break; case NRF_FSTORAGE_EVT_ERASE_RESULT: { NRF_LOG_INFO("--> Event received: erased %d page from address 0x%x.", p_evt->len, p_evt->addr); } break; case NRF_FSTORAGE_EVT_READ_RESULT: { NRF_LOG_INFO("--> Event received: read %d bytes at address 0x%x.", p_evt->len, p_evt->addr); } break; default: break; } } void flash_setup(){ ret_code_t err_code; p_fs_api = &nrf_fstorage_sd; err_code = nrf_fstorage_init(&fstorage, p_fs_api, NULL); APP_ERROR_CHECK(err_code); } void flash_write_bytes(uint8_t array[]){ ret_code_t err_code; err_code = nrf_fstorage_write(&fstorage, 0x3e000, &mac, sizeof(mac), NULL); APP_ERROR_CHECK(err_code); } uint32_t *flash_read_bytes() { uint8_t array[256] = {0}; ret_code_t err_code; err_code = nrf_fstorage_read(&fstorage, 0x3e000, array, sizeof(array)); APP_ERROR_CHECK(err_code); return array; }