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?

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

  • I don't have a specific recommendation, but you should consider this in your particular case. The point is that ending up in a loop with rapid writes to flash is bad, and should be avoided. That is a general thing that is not particular to the nRF.

  • Could POF warning help to block writing during power below threshold?


    // Initialize SoftDevice.
    err_code = sd_softdevice_enable(p_clock_lf_cfg, softdevice_fault_handler);
    if (err_code != NRF_SUCCESS){
     return err_code;
    }
    err_code = sd_power_dcdc_mode_set(NRF_POWER_DCDC_ENABLE);
    APP_ERROR_CHECK(err_code);
    err_code = sd_power_pof_enable(1);
    APP_ERROR_CHECK(err_code);
    err_code = sd_power_pof_threshold_set(NRF_POWER_THRESHOLD_V28);
    APP_ERROR_CHECK(err_code);

  • Hi,

    Yes, flash writing is prevented when there is a POF warning condition. This is a bit odd though since it will look like the flash write operations succeed, but in fact, nothing is written to flash.

  • I found an interesting condition it's happened if I have flashed bootloader

Reply Children
No Data