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

DFU buttonless entry method fails to erase flash

Hello,

This is a DFU custom project...the core problem is that I cannot erase the bootloader settings page from the chip.

While trying to use a slightly modified version of the BLE DFU buttonless code, I am running into a problem where the flash won't allow an erase. The chip is the nRF52 QFAB variant (256kb flash), and the memory map was altered per this discussion, so the erase is starting at 0x0003F000 (or trying to).

I call this function when a BLE sourced message comes in:

void BLEComms_enter_bootloader( void )
{
		// initialise flash dfu settings module
		nrf_dfu_flash_init(true);
		// get current settings from flash (otherwise the current app will be lost, 
		// regardless of the upgrade outcome, even if the upgrade does not take place
		// because we will lose the app CRC)
		nrf_dfu_settings_init();
			
		s_dfu_settings.enter_buttonless_dfu = true;

		(void) nrf_dfu_settings_write(flash_callback);		
}

The code that the error occurs in is the "nrf_dfu_settings_write" function, and is shown here:

fs_ret_t nrf_dfu_flash_erase(uint32_t const * p_dest, uint32_t num_pages, dfu_flash_callback_t callback)
{
    fs_ret_t ret_val = FS_SUCCESS;
    NRF_LOG_INFO("Erasing: 0x%08x, num: %d\r\n", (uint32_t)p_dest, num_pages);

    if ((m_flags & FLASH_FLAG_SD_ENABLED) != 0)
    {
        // Check if there is a pending error
        if ((m_flags & FLASH_FLAG_FAILURE_SINCE_LAST) != 0)
        {
            NRF_LOG_INFO("Erase: Failure since last\r\n");
            return FS_ERR_FAILURE_SINCE_LAST;
        }

        m_flags |= FLASH_FLAG_OPER;
        ret_val = fs_erase(&fs_dfu_config, p_dest, num_pages, (void*)callback);

        if (ret_val != FS_SUCCESS)
        {
            NRF_LOG_INFO("Erase failed: %d\r\n", ret_val);
            m_flags &= ~FLASH_FLAG_OPER;
            return ret_val;
        }...

The failure occurs after the fs_erase call. The ret_val from the fs_erase is FS_ERR_NOT_INITIALIZED (using Keil to set a breakpoint allows me to see this).

After enabling the log function, the following is output from that routine:

INFO:running nrf_dfu_settings_init
INFO:Erasing old settings at: 0x0003f000
DFU:INFO:Erasing: 0x0003f000, num: 1
DFU:INFO:Erase failed: 1
ERROR:Erasing from flash memory failed.

This code is successful in a different application, and was ported over to a slightly different app that was created originally using SDK 11 (we are now using SDK 12), so there may be a conflict that isn't apparent.

The chip has been recovered with nrfprog options to ensure nothing is locked in flash.

A search of the Nordic forum doesn't show any matches for the FS_ERR_NOT_INITIALIZED error.

I'm not that familiar with the flash operations (previously we used pstorage). Can anyone suggest some areas to consider?

Thank you...

Related