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

nRF52832 FLASH write issue

I want to write a piece of big data to flash.
Every time I write 112 word length, I write it many times.
Every time I write, the address is shifted back 112.
Before I write, I need to erase the pages that need to be written.
However, I find that only the first time I write successfully, but later I write unsuccessfully.
The API I use is sd_flash_write, what's the reason? thank you!

Parents
  • #define START_ERASE_PAGE            86

    #define OTA_DATA_START_ADDRESS      0x56000

    uint8_t *tag_ota_write_addr = (uint8_t *)(OTA_DATA_START_ADDRESS);

    void tag_ota_erase(uint8 page)
    {
        NRF_LOG_INFO("tag_ota_erase \n");

        for(int i = 0; i < page; i++)
        {
            sd_flash_page_erase(START_ERASE_PAGE + i);
            NRF_LOG_INFO("tag_ota_erase page : %d\n",START_ERASE_PAGE+i);
            nrf_delay_ms(100);
        }
    }

    At the time of initialization, 10 pages have been erased.

    using

    tag_ota_erase(10);

  • Okay,...So the write words in next address should be empty. It's right. But I suggest that the wait ready function not to apply delay. You may refer the example code \nRF5_SDK_17.0.2_d674dde\examples\peripheral\flash_fstorage

    wait_for_flash_ready();

    It's the function check for NV timing.

  • Among the APIs used, wait ready function is used

    uint32_t sd_flash_write(uint32_t * const p_dst, uint32_t const * const p_src, uint32_t size)
    {
        if (size > FLASH_WRITE_MAX_LENGTH)
        {
            return NRF_ERROR_INVALID_LENGTH;
        }

        if (!addr_is_in_FLASH(p_dst))
        {
            return NRF_ERROR_INVALID_ADDR;
        }

        nrf_nvmc_write_words((uint32_t) p_dst, p_src, size);
        m_flash_op_handler(true);
        return NRF_SUCCESS;
    }

    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();
    }

  • You may refer the example flash_fstorage. Your problems can be solved.

Reply Children
No Data
Related