Flash storage wrong values

Hello,

i want to store some date in the flash of my processor. i've read we'd have to use fstorage if we use bluetooth and a softdevice in our firmware.

i've left some space in the flash to store my data there:

FLASH_PH_START=0x0
FLASH_PH_SIZE=0x80000
RAM_PH_START=0x20000000
RAM_PH_SIZE=0x10000
FLASH_START=0x26000
FLASH_SIZE=0x59ED8
RAM_START=0x20002be0
RAM_SIZE=0xd448

FLASH_START + FLASH_SIZE = 0x7FED8

therefore i've defined the following:

#define FLASH_START_ADDRESS 0x7FED8
#define FLASH_END_ADDRESS   0x80000

static void fstorage_evt_handler(nrf_fstorage_evt_t * p_evt);
NRF_FSTORAGE_DEF(nrf_fstorage_t fstorage) =
{
    .evt_handler = fstorage_evt_handler,
    .start_addr = FLASH_START_ADDRESS,
    .end_addr   = FLASH_END_ADDRESS,
};

uint32_t ec;
ec = nrf_fstorage_init(&fstorage, &nrf_fstorage_sd, NULL);

doesn't return any error code

first strange behavior is that i can't erase the flash storage. i always receive NRF_ERROR_INVALID_ADDR; but i can read and write to the same address.

  uint16_t configPageBytes = (uint16_t)sizeof(_config);
  configPageBytes += (uint16_t)sizeof(_config) % 4;

  while(nrf_fstorage_is_busy(&fstorage));
  res =nrf_fstorage_erase(&fstorage, fstorage.start_addr, configPageBytes/4, NULL);
  while(nrf_fstorage_is_busy(&fstorage));


at least i can write some initial configuration to my flash storage. but if i receive data via bluetooth, data is messed up and wrong in the flash.

what am i doing wrong?

Update: i found out that i have to set my flash size to 0x1000 or multiple. i can erase the flash page now. now i can initially write to the flash page but if i want to update date, i erase the page and want to write new data received via bluetooth. data is not written to the flash. the write function returns success and no error code, but if i inspect the memory section it is empty.

Related