Watchdog timer and DFU mode

Hi, We have an application created with SDK17 and softdevice s140. We are using the watchdog timer with a timeout of 10 minutes:

void init_watchdog(void)
{
#if defined(WATCHDOG) && (WATCHDOG)
    // Initialize the watchdog
    nrfx_wdt_config_t config = NRFX_WDT_DEAFULT_CONFIG;
    /* default, set in app.config:
    NRFX_WDT_ENABLED                                1
    NRFX_WDT_CONFIG_BEHAVIOUR                       1       // 1 = Run in SLEEP, Pause in HALT, 8 = Pause in SLEEP, Run in HALT, 9 = Run in SLEEP and HALT, 0 = Pause in SLEEP and HALT
    NRFX_WDT_CONFIG_RELOAD_VALUE                    2000    // in msec
    NRFX_WDT_CONFIG_NO_IRQ                          0       // 0 = Include WDT IRQ handling, 1 = Remove WDT IRQ handling
    NRFX_WDT_CONFIG_IRQ_PRIORITY                    6
    */
    config.reload_value = 10UL * 60000UL;       // 10 minutes before it fires to enable DFU handling (MS2US(10)
    APP_ERROR_CHECK( nrfx_wdt_init(&config, wdt_event_handler) );
    APP_ERROR_CHECK( nrfx_wdt_channel_alloc(&_watchdog_channel_id) );
    nrfx_wdt_enable();
    watchdog_mask = WDOG_IS_RUNNING;
#endif
}

This works fine, but as soon as we enter DFU mode, the system is reset after about 2 seconds, while the DFU mode is still running.
Disabling the watchdog in the main application will 'solve' this issue, so as far as I can see, the reset while in DFU mode is caused by the watchdog timer.

In the bootloader I see code like nrf_bootloader_wdt_feed():

void nrf_bootloader_wdt_feed(void)
{
    if (nrf_wdt_started())
    {
        wdt_feed();
    }
}

Is there any reason why the timeout of 10 minutes is ignored and switched to a lower value (default 2 seconds?)
Do I need to set anything in the bootloader to keep the watchdog timer triggered?

Parents
  • Hello,

    Can you please check in your bootloader (you probably need to use the debug bootloader project to be able to see the logs, or actually debug without optimizations enabled), and see what value the
    wdt_ticks = nrf_wdt_reload_value_get() 

    gives. 

    Please note that these ticks are given in 32kHz units. So 10 minutes should be 32768 * 60 * 10 = 19 660 800 = 0x012c0000

    If it is in fact 2 seconds, it will say 32768*2 = 65536 = 0x10000

    I am not sure about your application, where you set 10*60000 = 600000. Are you actually seeing 10 minutes? I would expect it to be closer to 18 seconds.

    Best regards,

    Edvin

Reply
  • Hello,

    Can you please check in your bootloader (you probably need to use the debug bootloader project to be able to see the logs, or actually debug without optimizations enabled), and see what value the
    wdt_ticks = nrf_wdt_reload_value_get() 

    gives. 

    Please note that these ticks are given in 32kHz units. So 10 minutes should be 32768 * 60 * 10 = 19 660 800 = 0x012c0000

    If it is in fact 2 seconds, it will say 32768*2 = 65536 = 0x10000

    I am not sure about your application, where you set 10*60000 = 600000. Are you actually seeing 10 minutes? I would expect it to be closer to 18 seconds.

    Best regards,

    Edvin

Children
  • Hi Edvin
    Thanks for your reply.
    The first step I took was to be sure to fill in the right value for the WD reload. In the spec's I read:  
    timeout [s] = ( CRV + 1 ) / 32768.

    void init_watchdog(void)
    {
    #if defined(WATCHDOG) && (WATCHDOG)
        // Initialize the watchdog
        nrfx_wdt_config_t config = NRFX_WDT_DEAFULT_CONFIG;   
        APP_ERROR_CHECK( nrfx_wdt_init(&config, wdt_event_handler) );
        APP_ERROR_CHECK( nrfx_wdt_channel_alloc(&_watchdog_channel_id) );
        nrfx_wdt_enable();
        watchdog_mask = WDOG_IS_RUNNING;
    #endif
    }

    In NRFX_WDT_DEAFULT_CONFIG macro,  there is .reload_value  = NRFX_WDT_CONFIG_RELOAD_VALUE
    When setting NRFX_WDT_CONFIG_RELOAD_VALUE = 6553, I see a timeout of about 6 second. 

    From nrf_wdt_reload_value_get() (in the main application) I got reload value = 214728, resulting in 6,5 seconds timeout.
    So for some reason it looks like the NRFX_WDT_CONFIG_RELOAD_VALUE is in msec, not timerticks in my application?

    Keeping this as it is (6.5 sec), the DFU seems to work and also the watchdog will reset the application when in an infinite loop.

    I think one of the problems was/is that the wdog timer can not be re-initialized after a soft reset, like re-starting the application in Segger Studio. So testing the different values can only be done after a pin-reset of power down.

  • Hello,

    Sorry for the late reply. Due to low staffing because of public holidays in Norway, we expect some more delays in our response.

    I didn't get time to test this today. The WDT can't be changed without a proper reset (probably a power cycle. I don't remember the details). Were you trying to use different watchdog timeouts in the application and the bootloader, or was it the same?

    Best regards,

    Edvin

  • Hi Edvin,

    No, in the application we use one timeout value only. However, during testing we tried different values to see the differences.

  • Is it possible to upload an application (including bootloader) that can replicate what you are seeing on a DK? This would help reducing the amount of time it takes to reproduce what you are seeing, and look into issues/solutions for this problem.

    Best regards,

    Edvin

Related