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);
}
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);
}
#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
Hello,
It sounds like it is working now, but that you are just missing some log messages at the beginning of main()?
Watch dog event handler is working now. But soft reset can't trigger to run main() again.
How do you determine that the program is not reaching main() after the reset? Are you sure it's not just that some log messages are being lost?
Also, _wdtReboot(); could have been replaced with a while(1) as the WD will trigger a reset after the timeout event.
I have added turning on LED in main(). But LED isn't turning on after soft reset.
It doesn't make sense why the program would not reach main following a reset. Can you place a breakpoint in main and see if it is reached after the reset, and if not, halt the CPU and see where the program actually hangs?
It doesn't make sense why the program would not reach main following a reset. Can you place a breakpoint in main and see if it is reached after the reset, and if not, halt the CPU and see where the program actually hangs?