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

Flash corruption caused by power down during writing

Hello,

I'm using nRF52840 chip with nRF5 SDK 15.2.0 ,Mesh SDK 3.1.0 and soft device S140 6.1.1

I'm trying to protect the flash if a shutdown occurs during a write.
Reading in the forum it seems that the POFWARN event does it for me.

I'm trying to configure this event but without success.
I use this code:

nrfx_power_config_t power_config = {.dcdcen = 1};
nrfx_power_init (& power_config);
nrfx_power_pofwarn_config_t pofwarn_config = {.thr = POWER_POFCON_THRESHOLD_V28,
                                                   .handler = power_failure_warn_handler};
nrfx_power_pof_init (& pofwarn_config);
nrfx_power_pof_enable (& pofwarn_config);

If I use this code snippet before enable the softdevice, the nrf_sdh_enable_request() return the NRF_ERROR_SDM_INCORRECT_INTERRUPT_CONFIGURATION error code

If I use this code after enable the softdevice, the program stops when it try to write the POWER->DCDCEN register

What am I doing wrong?

Besides this, what is the best practice to avoid flash corruption it a power off occours during a write operation?

  • How can avoid this issue for the SDK Mesh Flash Writes (for example, during the provisioning and subscribe/publish configuration phase from the provisioner)?

    Usig POFWARN will prevent all flash writes. This is implemented in HW. From product specification:

    If the power failure warning is enabled and the supply voltage is below the threshold, the power-fail comparator will prevent the NVMC from performing write operations to the flash.

  • ok thanks,

    Now I see that, if the power loss occours during a flash erase, the NRF_EVT_POWER_FAILURE_WARNING event inside the SoC raises only after the erase complete.

    The SDH_SOC_OBSERVER has already priority 0.

    Is it possible to catch the NRF_EVT_POWER_FAILURE_WARNING during an erase operation?

  • No, that is not possible.

  • Hi,

    I have the same one problem, when I power up or perform power reset nrf52832 some times I have corrupted flash content.

    Am I right I should add some code delay after powerup and before main code start?

  • Hi,

    Not in general, but it is not a good idea to write to flash immediately after a reset since that could cause the device to go in a loop where it resets, tries to write to flash and get a power failure leading to a reset etc. if the battery is depleted.

1 2 3 4