This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Flash memory utilization

Dear Nordic Support Team,

I am trying to write some information in the flash memory without success. In the ble_flash.h file, it is specified that the pages 0-127 are reserved to the soft device. So, I can use the next page to store my data, am I right?

Can you tell me why the following code crash ?

uint32_t page = 128;

uint8_t word_count = 1;
uint32_t data_array[2]={0};

err_code = ble_flash_page_write(page,(uint32_t *) &data_array,1);
APP_ERROR_CHECK(err_code);
														
err_code = ble_flash_page_read(page, (uint32_t *) & data_array, &word_count);
APP_ERROR_CHECK(err_code);
Parents
  • This code most likely crashes because you are trying to overwrite the application code. There isn't a separate data flash in the nRF51822, so when you write to flash, you write to the same flash that the actual program runs from. You should therefore be careful not to erase or write to pages where there is program code, as the comment in ble_flash.h tells you.

    The softdevice occupies pages 0-79 (not 127 anymore, this is actually a bug in ble_flash.h) which translates to address 0 to 0x13FFF, while the application can use pages 79-255, address 0x14000 to 0x39FFF. However, this latter part will be shared between actual application code and data storage. It is a strict requirement that the code of the application starts at address 0x14000, and how far up it will go is simply a matter of how big it is.

    For data storage you should therefore make sure to use the upper pages. If you look at the bond manager, it uses pages 254 and 255, so I'd recommend you to use for example page 253 for other application storage needs.

    Also remember that any flash writing or erasing locks the CPU, so you need to be careful if you try to do this while in a BLE connection. Have a look at this question for details on this.

  • Thanks for your reply. So, to write 1 page, I need to use something like "NRF_FICR->CODESIZE-4"?

Reply Children
No Data
Related