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

nrf_dfu_wait funcion never return

hello,

I use nrf51822 + S130 + SDK12.2 in my product, nrf51822 work at central + peripheral mode,and i use nrf_duf_flash module for my dfu funtion.

The problem is, i use my dongle(as central role) connect my product(as peripheral role) and send dfu commands to it, when my product do not connect a peripheral as central role, it looks like work well, the dfu process is ok, but when my product do connect a peripheral as central role(that means my product has to connection both as central and peripheral), some times the dfu is ok, but some times, program will dead in nrf_flash_wait function,in the loop

while ((m_flags & FLASH_FLAG_OPER) != 0)
{
        (void)sd_app_evt_wait();
}

and never out.

my dfu code like this:

if (nrf_dfu_flash_store((uint32_t *)(IAP_STORE_ADDR + s_tIAPState.write_ptr), (uint32_t  *)data_buf, (data_len >> 2), NULL) != FS_SUCCESS)
{
    tCmdPar.index = IAPERROR_WRITEFLASH;
}
else                                    
{
    if (nrf_dfu_flash_wait() != FS_SUCCESS)
    {
        tCmdPar.index = IAPERROR_WRITEFLASH;
        break;
    }
  
    //other code
}

I also try SDK12.3, the problem is same.

Is this a bug of SDK? How can i fix it, or, if do not use nrf_dfu_flash module, what can i do?

  • As far as I know, you seem to be experiencing a feature, not a bug. sd_app_evt_wait will actually not return. When debugging, your IDE may lose its tracks when this functions is entered, because that function is an "end station". The nRF won't do any more work, unless a timer/interrupt/reset is done.

    Hope that helps.

    Edit: changed to sd_app_evt_wait

  • Thank you first!

    I use SDK12.2, and the nrf_dfu_flash_wait is not an "end station", it is "nrf_dfu_flash_wait" but not "nrf_flash_wait"。 This function wait the FLASH_FLAG_OPER flag in m_flags be cleared, then return.

    I test both debug and free run.

  • I do some test last night, found this problem is not caused by ble connection, it seems like caused by uart isr.

    When i got DFU_START command from ble dongle, i disable the uart, then this problem will not appear, if i do not disable uart, the problem will appear.

    I think, maybe when the uart is enabled, when uart receive data, the ISR is called, and this sometimes make the SWI2 ISR can not be called, then miss fs event, cause FLASH_FLAG_OPER flag never be clear. But the IRQ priority of uart is set to APP_IRQ_PRIORITY_LOWEST, how can it make CPU miss a higher priority IRQ (SWI2 used by softdevice)?

  • You are probably right in that it is a interrupt priority issue. Are you doing flash writes from the UART handler? Have you made sure to declare you flag variables as volatile?

  • I found SD_EVT_IRQn has the lowest interrupt priority, as same as UART interrupt priotiry, and i can not change SD_EVT_IRQn to a higher interrupt priority(if i do so, the system will reset in APP_ERROR_CHECK). I did not operate flash from the UART handler, i recive data from BLE dongle and put them to a app_fifo, in main funcion i get data and write it to flash, so that does not matter to UART handler. The flag variable m_flags is not declare by me, it declare in nrf_dfu_flash.c, which is part of SDK12.3.

    In this case, is it prosible that UART receive data continuous cause SD_EVENT_IRQ ISR can not execute and then miss some event? Or is there has some other reasons?

Related