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);
  • Sorry for the delay, it's just been way too busy lately. However, you don't give a lot of details, so it's a little hard to help you. What exactly is not working, and how does it not work? Don't you see anything changing? What is the flash contents before and after running this snippet? Does it return an error code or does fail in some other way? Are you in a BLE connection when it fails?

    It would be helpful if you could edit your original question and add the complete project you're working with, so that I can test it on my end.

  • Dear Ole Morten,

    Thanks for helping me with this problem. I am just trying to test the read/write flash page feature without success.

    Please, have a look on my answer on this thread above to see my code. Teh code is executed at the end of the main function, just before the infinity loop containing the "sd_app_event_wait" softdevice function.

    At this point, the ble stack is started and I should be able to use ble_flash_page_write function, but I can't. The code crash when I execute the function ble_flash_page_write, therefore, I don't have any error message to give you...

    Go into the function does not help because the debugger stopped on function ble_flash_crc16_compute, but if I set a breakpoint right after, it execute successfully the ble_flash_crc16_compute function.

    I think that it crashes due to a bad memory address. The page I am tring to write is NRF_FICR->CODESIZE - 4;

    Do you have any idea or example which could inspired me?

    Best regards

  • 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.

  • Thanks for the clarification. I moved my code in the BLE disconnect event and it works.

    Last question, at this time, I am using the code "NRF_FICR->CODESIZE - 4" to retrieve a page number to write my data. But, how can I know if I am writting in the application flash pages? Is there a way to know the application size?

  • Thanks for the clarification. I moved my code in the BLE disconnect event and it works.

    Last question, at this time, I am using the code "NRF_FICR->CODESIZE - 4" to retrieve a page number to write my data. But, how can I know if I am writting in the application flash pages? Is there a way to know the application size?

Related