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

Buttonless Secure DFU with WDT needs DFU twice

I use nrf51822xxAC,SDK 12.2,Buttonless Secure DFU and WDT in application.

I added NRF_WDT->RR[0] = WDT_RR_RR_Reload; to the wait_for_event loop in the DFU to pet the dog.

But it needs to DFU twice to let the chip run into application.

The same question in this link.

Could anyone help me?

Parents
  • Hi Kamisen,

    Seems that I found the problem, it was with wait_for_event(). Inside that function we call sd_app_evt_wait(); This call won't return if you don't have any application event or receive Softdevice event. If you replace that function with simply __WFI(), then we can be sure the CPU wake up and do WDT feeding every time we have a BLE activity. This worked for me :

    static void wait_for_event()
    {
        // Transport is waiting for event?
        while(true)
        {
    	     NRF_WDT->RR[0] = WDT_RR_RR_Reload;
            // Can't be emptied like this because of lack of static variables
            __WFI();
    
            app_sched_execute();
        }
    }
    

    A better way of doing this is to setup a timer with a timeout smaller than 2 seconds to feed the dog.

Reply
  • Hi Kamisen,

    Seems that I found the problem, it was with wait_for_event(). Inside that function we call sd_app_evt_wait(); This call won't return if you don't have any application event or receive Softdevice event. If you replace that function with simply __WFI(), then we can be sure the CPU wake up and do WDT feeding every time we have a BLE activity. This worked for me :

    static void wait_for_event()
    {
        // Transport is waiting for event?
        while(true)
        {
    	     NRF_WDT->RR[0] = WDT_RR_RR_Reload;
            // Can't be emptied like this because of lack of static variables
            __WFI();
    
            app_sched_execute();
        }
    }
    

    A better way of doing this is to setup a timer with a timeout smaller than 2 seconds to feed the dog.

Children
No Data
Related