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

nRF51822 The access to the flash memory cause the program to fail.

Hi, everyone,

I am developing the project on nRF518522 and I must use the flash memory to save the data. The data must be saved while the device is conncted via BT with the master. For this purpose I use the procedure ble_flash_page_write(PG_NUM, p_out_array, p_word_count); where: the variables and constants are defined so:

#define PG_SIZE (NRF_FICR->CODEPAGESIZE)
#define PG_NUM  (BLE_FLASH_PAGE_END - 1)

uint32_t p_out_array[PG_SIZE];

in my case the p_word_count=7;

If I try to pass the code by step by step, the procedure (ble_flash_page_write) passes successfully, but during the running it caus the device to stop working and nothing in the flash is saved.

What is it possible to do?

Parents
  • Hi,

    Did you read the warning in the API documentation for ble_flash_page_write()?

    Warning

    This operation blocks the CPU. DO NOT use while in a connection!

    You will have to erase the pages you want to write before initializing the BLE stack, for instance using ble_flash_page_erase(), and use ble_flash_word_write() to write to flash. You can also check out the FDS library, which can be used for writing data to flash. An example can be found on this GitHub page.

    Best regards,

    Jørgen

  • If the softdevice is blocked from handling the incoming events immeadiately, it will hardfault. When you single step the code when the softdevice is enabled, you will also get a hardfault, as the softdevice will not be able to process the events. The only recovery from the hardfault is a reset.

    Why do you need to perform the erase while in a connection? Can't you do the erase first and store new values in new locations? FDS implements this handling for you, allowing you to update/invalidate records when in a connection, and run garbage collection/flash erase when idle. Which SDK version are you using, and what API documentation/guide are you following? Newer SDK version use the priorities defined in app_irq_priority_t in app_util_platform library.

Reply
  • If the softdevice is blocked from handling the incoming events immeadiately, it will hardfault. When you single step the code when the softdevice is enabled, you will also get a hardfault, as the softdevice will not be able to process the events. The only recovery from the hardfault is a reset.

    Why do you need to perform the erase while in a connection? Can't you do the erase first and store new values in new locations? FDS implements this handling for you, allowing you to update/invalidate records when in a connection, and run garbage collection/flash erase when idle. Which SDK version are you using, and what API documentation/guide are you following? Newer SDK version use the priorities defined in app_irq_priority_t in app_util_platform library.

Children
No Data
Related