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

Serial DFU Flash Erase Fail

Hi

I had implemented a DFU module in esp8266 where I am trying to upgrade nrf over serial (UART Communication).

I had success with Init file write but when I send the command to execute the i got nothing in return, Device got stuck and no response from nrf.

But When I am trying same using nrf connect (BLE DFU) it is working fine, code is returning from flash erase.

SDK version is 14.2


Code snippet is also attached.

    if (    ((page_addr & (p_fs->p_flash_info->erase_unit - 1)) != 0)
        ||  !addr_within_bounds(p_fs, page_addr, (len * p_fs->p_flash_info->erase_unit)))
    {
    
        return NRF_ERROR_INVALID_ADDR;
    }
    print(LL_INFO,"333333\n");
    return (p_fs->p_api)->erase(p_fs, page_addr, len, p_context);

Can anyone suggest what is the possible issue and any solution.
  • HI Vaibhav, 

    Ok, so the address that is passed to nrf_fstorage_erase() is not aligned to  a page boundary. Do you have the call stack when nrf_fstorage_erase returns NRF_ERROR_INVALID_ADDR? What are the input parameters to nrf_fstorage_erase?

    ret_code_t nrf_fstorage_erase(nrf_fstorage_t const * p_fs,
                                  uint32_t               page_addr,
                                  uint32_t               len,
                                  void                 * p_context)
    {
        if (p_fs == NULL)
        {
            return NRF_ERROR_NULL;
        }
    
        if (p_fs->p_api == NULL)
        {
            return NRF_ERROR_INVALID_STATE;
        }
    
        if (len == 0)
        {
            return NRF_ERROR_INVALID_LENGTH;
        }
    
        /* Address must be aligned to a page boundary. */
        if (    ((page_addr & (p_fs->p_flash_info->erase_unit - 1)) != 0)
            ||  !addr_within_bounds(p_fs, page_addr, (len * p_fs->p_flash_info->erase_unit)))
        {
            return NRF_ERROR_INVALID_ADDR;
        }
    
        return (p_fs->p_api)->erase(p_fs, page_addr, len, p_context);
    }

    nrf_fstorage_erase() is called from nrf_dfu_flash_erase(), which is refrerence from the following locations in the bootloader source. 

    • nRF5_SDK_14.2.0_17b948a/components/libraries/bootloader/dfu/nrf_dfu_settings.c ( line 199):err_code = nrf_dfu_flash_erase((uint32_t)m_dfu_settings_buffer, 1, NULL);
    • nRF5_SDK_14.2.0_17b948a/components/libraries/bootloader/dfu/nrf_dfu_utils.c (line 128): ret_val = nrf_dfu_flash_erase(target_addr, split_size / CODE_PAGE_SIZE, NULL);
    • nRF5_SDK_14.2.0_17b948a/examples/dfu/dfu_req_handling/dfu_req_handling.c (line 944):if (nrf_dfu_flash_erase((m_firmware_start_addr + s_dfu_settings.progress.firmware_image_offset)

    If the DFU process halts after the Execute command after the init packet has been transferred, then my bet is that its the nrf_dfu_flash_erase call in the nrf_dfu_settings_write() call after the dfu_handle_prevalidate() call in dfu_handle_signed_command() that is the culprit. Can you set a breakpoint here and see what nrf_dfu_flash_erase() returns?

    Here is the call chain. 

    on_packet_received()->nrf_dfu_req_handler_on_req()->nrf_dfu_command_req()->dfu_handle_signed_command()->nrf_dfu_settings_write()->nrf_dfu_flash_erase()

    Best regards

    Bjørn

  • Hi Bjorn

    nrf_dfu_flash_erase won't return, the code just stuck there until no activity timeout happens and after reset it happens again.

    sd_flash_erase_page is not returning.

  • Can you set a breakpoint in nrf_dfu_flash_init(). Is sd_irq_initialized set to true or false, i.e. is p_api_impl set to &nrf_fstorage_sd or &nrf_fstorage_nvmc ? 

  • Hi 

    After some debugging I am able to resolve the issue

    thanks for your time.

Related