Skip to content

Expose watchdog reset reason #939

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jackwilsdon
Copy link

This PR adds a reason() method to rp235x_hal::watchdog::Watchdog, returning the reset reason from the watchdog peripheral.

Screenshot from RP2350 datasheet showing watchdog REASON register

Both the force and timer bits could technically be set simultaneously, but I've not been able to reproduce this.

One thing to note is that some ways to reboot the RP2350 give unexpected reasons:

Method Reason
reboot(RebootKind::Normal, RebootArch::Normal) Timeout
explicit_buy Timeout

The official SDK avoids this confusion by not exposing the reason directly and instead providing watchdog_caused_reboot (which checks reason and boot type) and watchdog_enable_caused_reboot (which checks reason and a scratch register set by watchdog_enable).

@thejpster
Copy link
Member

I wonder if we should do it how the Pico SDK does it, to avoid the confusion.

@jackwilsdon
Copy link
Author

We can implement watchdog_caused_reboot quite easily but we'd need to set a value in the scratch register on enable to implement watchdog_enable_caused_reboot - is this something we'd want to do? Happy to implement it in this PR if so.

@thejpster
Copy link
Member

I think that would be good. I'd we use a scratch that someone else is using, they can switch to one of yes others easily enough - or just call a different reboot function that doesn't set the register.

@thejpster
Copy link
Member

I'm currently using a scratch register in my project to catch whether we've had a Core 0 restart (thanks to probe-rs) or a full system restart. If I detect the former, I use the watchdog to force the latter, so that Core 1 also gets reset. I'd have no problem changing that if required.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants