Soft reset when watchdogs timer timeout

Could I trigger nRF52832 to do soft reset when watchdogs timer timeout?

  • Hi,

    Are you asking about soft reset specifically, or wondering if the nRF52 will do a reset once the watchdog times out?

    regards
    Jared 

  • I have two questions. The first one is watch dog event handler _wdtEventHandler() is not called after watch dog timer timeout. The second question is can I call NVIC_SystemReset() to do soft reset in watch dog event handler _wdtEventHandler().

    The following is testing code.

    int main(void) {

        ...

        wdtInit();

        for (;;) {
            wdtFeed();
            while(1); // force watch dog timer timeout

       }

    }

  • From the following log messages, nrfx_wdt_init() and nrfx_wdt_channel_alloc return NRF_SUCCESS. But why Watchdog event handler isn't called?

    # SEGGER J-Link RTT Viewer V6.32i Terminal Log File
    # Compiled: 15:22:50 on Jul 24 2018
    # Logging started @ 04 Jul 2022 13:55:29
     0> <info> PRS: Function: nrfx_prs_acquire, error code: NRF_SUCCESS.
     0> <warning> UARTE: Function: nrfx_uarte_init, error code: NRF_SUCCESS.
     0> <info> UARTE: Transfer rx_len: 1.
     0> <info> UARTE: Function: nrfx_uarte_rx, error code: NRF_SUCCESS.
     0> <info> app: ========| flash info |========
     0> <info> app: erase unit:   4096 bytes
     0> <info> app: program unit: 4 bytes
     0> <info> app: end address: 0x7FFFF
     0> <info> app: ==============================
     0> <info> SAADC: Function: nrfx_saadc_init, error code: NRF_SUCCESS.
     0> <info> PRS: Function: nrfx_prs_acquire, error code: NRF_SUCCESS.
     0> <warning> UARTE: Function: nrfx_uarte_init, error code: NRF_SUCCESS.
     0> <info> UARTE: Transfer rx_len: 1.
     0> <info> UARTE: Function: nrfx_uarte_rx, error code: NRF_SUCCESS.
     0> <info> app: ========| flash info |========
     0> <info> app: erase unit:   4096 bytes
     0> <info> app: program unit: 4 bytes
     0> <info> app: end address: 0x7FFFF
     0> <info> app: ==============================
     0> <info> SAADC: Function: nrfx_saadc_init, error code: NRF_SUCCESS.
     0> <info> SAADC: Function: nrfx_saadc_channel_init, error code: NRF_SUCCESS.
     0> <info> SAADC: Function: nrfx_saadc_buffer_convert, buffer length: 1, active channels: 1.
     0> <info> SAADC: Function: nrfx_saadc_buffer_convert, error code: NRF_SUCCESS.
     0> SS.
     0> <debug> SAADC: Event: NRF_SAADC_EVENT_END.
     0> <info> app_timer: RTC: initialized.
     0> <info> CLOCK: Function: nrfx_clock_init, error code: NRF_SUCCESS.
     0> <debug> app: NOR_DATA_PERIOD=819
     0>
     0> <debug> app: NOR_RECORD_PERIOD=8192
     0>
     0> <info> WDT: Function: nrfx_wdt_init, error code: NRF_SUCCESS.
     0> <info> WDT: Function: nrfx_wdt_channel_alloc, error code: NRF_SUCCESS.
     0> <info> WDT: Enabled.
     0> <debug> app: Watchdog timer feed
     0>
     0> <error> app: ERROR 4 [NRF_ERROR_NO_MEM] at ..\..\..\..\..\..\com<error> app: End of error report

  • #include "error.h"
    #include "nrf_log.h"
    #include "nrfx_wdt.h"
    #include "wdt.h"
    
    static bool _gWdtInitialized = false;
    static nrfx_wdt_channel_id _gWdtChannelID;
    
    void _wdtReboot(void) {
        NVIC_SystemReset();
    }
    
    /*
     *  WDT events handler.
     */
    static void _wdtEventHandler(void) {
        NRF_LOG_WARNING("Watchdog timer event handler\n");
        //_wdtReboot();
    }
    
    int wdtInit(void) {
        ret_code_t errCode;
        nrfx_wdt_config_t wdtConfig = NRFX_WDT_DEAFULT_CONFIG;
    	errCode = nrfx_wdt_init(&wdtConfig, _wdtEventHandler);
        if (errCode != NRF_SUCCESS) {
    	    NRF_LOG_WARNING("nrfx_wdt_init() failed\n");
            return ERROR_WDT_INITIALIZE_FAIL;
        }
        
    	errCode = nrfx_wdt_channel_alloc(&_gWdtChannelID);
    	if (errCode != NRF_SUCCESS) {
    	    NRF_LOG_WARNING("nrfx_wdt_init() failed\n");
            return ERROR_WDT_INITIALIZE_FAIL;
        }
    
    	nrfx_wdt_enable();
    
        _gWdtInitialized = true;
    
        return 0;
    }
    
    int wdtFeed(void) {
        if (!_gWdtInitialized) {
            return ERROR_WDT_UNINITIALIZED;
        }
    
        //NRF_LOG_DEBUG("Watchdog timer feed\n");
        nrfx_wdt_channel_feed(_gWdtChannelID);
    
        return 0;
    }
    
    5554.wdt.h

  • Hi,

    I have two questions. The first one is watch dog event handler _wdtEventHandler() is not called after watch dog timer timeout. The second question is can I call NVIC_SystemReset() to do soft reset in watch dog event handler _wdtEventHandler().

    The following is testing code.

    It's not the correct way of using the watchdog. The watchdog should do a watchdog reset about two 32 kHz clock cycles after it has been triggered. If the watchdog doesn't trigger then you should check if you have configured it correctly. It would be also nice if you mentioned how you verify whether a watchdog reset has happened or not. 

    Have you seen the watchdog example in the SDK?

    regards

    Jared

Related