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

I have a question with flash writing of nRF 52.

I have a question with flash writing of nRF 52.
Once written, you can not write it for the second time. It will not cause an error, but is there any way?
Write the source code below.


-----------------------------------------------------------------

NRF_FSTORAGE_DEF (nrf_fstorage_t fstorage) =
 {
        / * Set a handler for fstorage events. * /
        .evt_handler = fstorage_evt_handler,

        / * These below are the boundaries of the flash space assigned to this instance of fstorage.
     * You must set these manually, even at runtime, before nrf_fstorage_init () is called.
     * The function nrf5_flash_end_addr_get () can be used to retrieve the last address on the
     * last page of flash available to write data. * /
        .start_addr = 0x76000,
        .end_addr = 0x76 FFF,
};

#define GSM_APN_SETTING_SIZE 0x40
#define GSM_APN_SETTING_OFFSET 0x110

flash_update (gsm_apn_config, GSM_APN_SETTING_SIZE, GSM_APN_SETTING_OFFSET, true);

void flash_update (const uint8_t * p_dest, uint32_t size, uint32_t offset, bool isString)
{
    ret_code_t rc;

    rc = nrf_fstorage_write (& fstorage, fstorage.start_addr + offset, p_dest, size, NULL);
    APP_ERROR_CHECK (rc);
}

  • Hi,

    You can write to the same address more than once, but there are some limitations. When you erase a page, all memory cells (holding one bit) are set to '1', and writing can flip any bit from '1' to '0'. However Neighboring memory cells are also affected by the write, so there is a limit of how many writes you can do before you risk corrupting these neighboring bits.

    The product specification lists the limitations. For the nRF52832, the NVMC chapter in the PS states that the same block in the Flash can only be written nWRITE number of times before an erase must be performed, where nWRITE is 181. For the nRF52832, the NVMC chapter in the PS states that a 32 bit word can only be written nWRITE number of times before an erase must be performed. In this case, nWRITE is 2.

    This limitation is not enforced by fstorage or SoftDevice, so you must handle it yourself if you do low-level flash access. However, this is taken care of if  you use the FDS file system.

Related