Debugging when I crash my controller

While working on my version of the firmware, certain kinds of bugs will just cause my controller to silently reboot, with no indication in the serial monitor. Of course, I’ve tried adding lots of println to figure out what’s going on before reboot, but it’s tricky and takes some guesswork to figure out what happened.

Is there any way to get more information when the controller crashes, something like a stack trace or whatever? anything I can uncomment in the code or enable in the IDE to provide more info on a crash?

Hi @mike!

This line will print the cause for the last reset of the microcontroller.

You can place it after the “wait for serial” here and uncomment this line(waits for the serial port to be opened) to see it printed

The datasheet for the samd21 will tell you which is the cause that corresponds to the number that you see. Most usually the watchdog timer will cause the reset unless you’re having power issues.

You can see if commenting this section (the whole if statement) makes the reboots stop

Thanks. I tried these but haven’t gotten to see if it works yet.

At the moment, hachi’s doing a new weird thing: when I go into kilomux and load updated firmware, it just doesn’t reboot into the new firmware. it then gets stuck – I can’t select kilomux from the firmware loader and the controller isn’t responsive. But if I unplug it and plug it back in, it comes up in my firmware and is fine. Also, the serial monitor can’t connect. This just started happening today, as far as I can tell. Any ideas?

UPDATE: looks like these issues were fixed by restarting the Arduino IDE :roll_eyes:

1 Like