Flash management with operative system

Hello,

we are using nrf52840 with nrf5 sdk for thread and Zigbee v4.2.0.

We have been experiencing flash memory issues for a while now: https://devzone.nordicsemi.com/f/nordic-q-a/110247/issue-with-zigbee-flash-area

I believe that we are not managing correctly multiple access to flash memory.

To erase a section we use nrf_nvmc_page_erase() and to write we call nrf_nvmc_write_words() but I saw that also Zigbee stack is doing the same. This can result in one task disabling write access (and enabling erase) while the other one is trying to write, for instance.

Do you agree with this? Is there another API we should use?

void nrf_nvmc_page_erase(uint32_t address)
{
    // Enable erase.
    NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Een;
    __ISB();
    __DSB();

    // Erase the page
    NRF_NVMC->ERASEPAGE = address;
    wait_for_flash_ready();

    NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Ren;
    __ISB();
    __DSB();
}

void nrf_nvmc_write_words(uint32_t address, const uint32_t * src, uint32_t num_words)
{
    uint32_t i;

    // Enable write.
    NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Wen;
    __ISB();
    __DSB();

    for (i = 0; i < num_words; i++)
    {
        ((uint32_t*)address)[i] = src[i];
        wait_for_flash_ready();
    }

    NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Ren;
    __ISB();
    __DSB();
}

Best regards,

Laura

Parents Reply Children
No Data
Related