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

How to always Write to FLASH

There is my function for writing to flash.

It works when NRF52832 start from reset, if works when the NRF52832 gets data over BLE but it does not works after "power down and up".

It is strange, CPU works on Super Capacitor when the main power fall down, but when power wakes up flash erase works when start after some delay (about 100ms).

Problem is with waiting for flash ready, cpu stucks there. In another one implementation of writing flash processor doesn't stuck but writing has no effect. 

NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Wen;
while (NRF_NVMC->READY == NVMC_READY_READY_Busy);  <<<<< HERE PROCESSOR STUCK

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
config_t* set_default_config(void)
{
erase_config_flash();
memset(&m_config.calendar,0x00, sizeof(m_config.calendar));
m_config.mode=MODE_DEFAULT;
m_config.button_mode=SHORT_MODE;
m_config.calendar.RTCtime=1546300800; // 01-01-2019
write_config_to_flash();
return(&m_config);
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

  • Sounds like the supply voltage is being too low. Can you share the schematic? Do you have the correct value on all the decoupling capacitors?

  • Now im working witj DEV KIT nRF52. Previous problem disappeared.

    Now FlashErase doesn't work each time I use it.

    It means that at the beginning when the device starts, FlashErase works, but later during the work of the device no longer.

    My code for erasing:

    what is the cause of the problem?

  • Hi Bartosz

    Sorry about the late reply, but Ketil has been busy lately and I just now got to this case. 

    First off. What SDK version are you using? What example (if any) is your application based on, and do you use the SoftDevice or not?

    If you're using SDK version 14.0 or newer, you should check out the nrf_fstorage_erase function in nrf_fstorage.h within the SDK, to see how that function works.

    If you're using an older SDK version you should check out the fs_erase function in fstorage.h

    Best regards,

    Simon

  • This is my SDK: nRF5_SDK_15.2.0_9412b96

    Yes, I'm using SoftDevice 132.

    For now I can switch off SoftDevice before erasing, because after that NRF52832 goes to NVIC_SystemReset() and it works fine. I have also few situation when i can't switch off the SoftDevice but now it is ok and this "ok" or "no ok" looks like SoftDevice propability dependend.

  • BartoszT said:
    but now it is ok and this "ok" or "no ok" looks like SoftDevice propability dependend.

     What does this mean? And why would you need to disable (switch off) the SoftDevice, do you mean going to deep sleep to save power?

    Best regards,

    Simon