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
  • Remember that doing flash operations locks the CPU. You write in a comment that you do it right before the infinite loop in main, but at this point, the chip is most likely advertising. If it is, the time it takes to erase a page may will cause an assert, and the program will end up in the app_error_handler, which by default does a reset.

    I recommend that you remove the reset from the error handler, and instead uncomment the call to ble_debug_assert_handler(), since this will make it much easier for you to find errors as they happen.

    The only workaround to this problem is to avoid doing flash operations except when not in a connection and not advertising.

  • You can see the size of the application in Keil's output when it's compiling. If you know that you're going to use this page for application data, you could also consider reducing the size of IROM in Keil's project settings, so that you get errors on no remaining space if the application grows into this region. You can see that this is done for all the BLE examples in the SDK.

Reply Children
No Data
Related