Watchdog event handler isn't called

I try to simulate system hang by adding while(1) after calling watch dog feeding function. But watchdog event handler _wdtEventHandler() isn't called.

int main(void) {

    ...

    wdtInit();

    for (;;) {
        wdtFeed();
        while(1);

}

  • wdt.h

    #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;
    }
    
    
    
    //void WDT_IRQHandler(void) {
    //    NRF_LOG_WARNING("Watchdog timer interrupt handler\n");
    //}
    

  • 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

  • I am sure watchdog event handler _wdtEventHandler() is called by checking with LED. But why main() isn't called after calling NVIC_SystemReset().

    int main(void) {
        log_init();
        uart_init();
        _showInfo();

       ...

    }

    static void _showInfo(void) {
        NRF_LOG_INFO("Version %d.%d.%d\n", MAJOR_VER, MINOR_VER, PATCH_VER);
    }

    I only " app: Version 1.0.0" one time in following log messages. It should be two times if main() is called after system reboot.

    0> <info> app: Version 1.0.0
     0>
     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> app_timer: RTC: initialized.
     0> <debug> app: NOR_DATA_PERIOD=819
     0>
     0> <debug> app: NOR_RECORD_PERIOD=8192
     0>
     0> <info> app: bsp_button_longkey_handler 0.
     0> <info> app: POWER_ON.
     0> <info> app: External devices initializing start
     0> <info> app: Reg 0 20
     0> <info> app: Reg 9 A
     0> <info> app: Reg A D
     0> <info> app: Reg 1 B
     0> <info> app: Reg 2 D
     0> <info> app: Reg D F
     0> <info> app: Reg E 13
     0> <info> app: Reg 36 10
     0> <info> app: Reg 37 13
     0> <info> app: Reg 5 11
     0> <info> app: Reg 6 13
     0> <info> app: Reg F 15
     0> <info> app: Reg 10 19
     0> <info> app: Reg 3 16
     0> <info> app: Reg 4 19
     0> <info> app: Reg 7 17
     0> <info> app: Reg 8 19
     0> <info> app: Reg 11 1B
     0> <info> app: Reg 12 1F
     0> <info> app: Reg 43 0
     0> <info> app: Reg 44 0
     0> <info> app: Reg B 1D
     0> <info> app: Reg C 1F
     0> <info> app: Reg 13 21
     0> <info> app: Reg 14 25
     0> <info> app: Reg 1D 3F
     0> <info> app: Reg 64 0
     0> <info> app: Reg 65 27
     0> <info> app: Reg 66 0
     0> <info> app: Reg 67 27
     0> <info> app: Reg 68 0
     0> <info> app: Reg 69 27
     0> <info> app: Reg 52 2C
     0> <info> app: Reg 53 2C
     0> <info> app: Reg 6A 32
     0> <info> app: Reg 6B 38
     0> <info> app: Reg 1E 101
     0> <info> app: Reg 20 3
     0> <info> app: Reg 21 2
     0> <info> app: Reg 22 802084
     0> <info> app: Reg 23 124218
     0> <info> app: Reg 4B F
     0> <info> app: Reg 50 18
     0> <info> app: Reg 31 20
     0> <info> app: Reg 39 5
     0> <info> app: Reg 4E 0
     0> <info> app: Reg 4E 8
     0> <info> app: Reg 45 8
     0> <info> app: Reg 46 13
     0> <info> app: Reg 47 14
     0> <info> app: Reg 48 1F
     0> <info> app: Reg 0 21
     0> <warning> app: nrfx_wdt_init() return 0
     0>
     0> <info> app: External devices initializing finish

  • #include "band_nctu.h"
    #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;
    
        NRF_LOG_WARNING("nrfx_wdt_init() return 0\n");
        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;
    }
    
    6835.wdt.h

  • Hello,

    It sounds like it is working now, but that you are just missing some log messages at the beginning of main()?

Related