I’ve been getting stack overflow errors when running the Particle Electron. I’m using the watchdog timer and have increased its stack size to 4kb with the following code:
// this is where we initialize the watchdog
ApplicationWatchdog wd(1000, wd_reset, 4096);
// this is the function that we call when the watchdog timer is set off
void wd_reset() {
int ret = Cellular.command(30000, "AT+CFUN=16\r\n");
if (ret == RESP_OK) System.reset(5);
else System.reset(1005);
}
Is it possible that I need to increase the watchdog timer stack size even more? If not, how do I go about looking for the code segments that induce the stack overflow?
I can’t see any instruction in that snippet that would increase the stack size for the watchdog thread. Update: After OP was updated the comment was rendered irrelevant
@Adam42, calling Cellular.command() may be the issue. You may want to try and comment it out to see if you still get the error. The stack overflow may be in the system thread and not the wd_reset() thread.
@peekay123: I will definitely try commenting the Cellular.command out. If the stack overflow is on the system thread, do you have any suggestions on how to figure out what exactly is the biggest contributor?
However, you should not do what the original poster did. Cellular.command is almost certain to fail if you’ve hit the application watchdog timer, and it will require too much stack space. The way around that is to only call System.reset() from your application watchdog callback, then if you fail to connect after reset, then AT+CFUN=16 from the working state.