Could I trigger nRF52832 to do 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
}
}
But my question is why watchdog event handler _wdtEventHandler() is not called. Could you explain about this?
<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
Can I use NRF_LOG_WARNING() to check if watchdog event handler _wdtEventHandler() is called? Or I need to use LED to check if watchdog event handler _wdtEventHandler() is called?
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;
}
snowuyl said:0> <error> app: ERROR 4 [NRF_ERROR_NO_MEM] at ..\..\..\..\..\..\com<error> app: End of error report
Something is asserting in your program, a function is returning error code 4. The full error report should specify what function that is returning that code.
snowuyl said:But why main() isn't called after calling NVIC_SystemReset().
The CPU will do a reset when this function is called, the program will not return directly to the main loop but would rather start from the beginning again.
regards
Jared
snowuyl said:0> <error> app: ERROR 4 [NRF_ERROR_NO_MEM] at ..\..\..\..\..\..\com<error> app: End of error report
Something is asserting in your program, a function is returning error code 4. The full error report should specify what function that is returning that code.
snowuyl said:But why main() isn't called after calling NVIC_SystemReset().
The CPU will do a reset when this function is called, the program will not return directly to the main loop but would rather start from the beginning again.
regards
Jared
Does Nordic provide API for soft reset and return directly to the main loop?
Hi,
No every type of reset whether it's brownout reset, pin reset, soft reset, power-on-reset, watchdog reset, wake up from system off reset will reset the program.
regards
Jared