RP2040: How to determine we are coming back from a WDT reset?

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
martincho
Posts: 96
Joined: Mon May 16, 2022 9:59 pm

RP2040: How to determine we are coming back from a WDT reset?

Post by martincho » Fri Jul 08, 2022 6:56 pm

The SDK has a way to do this:

https://raspberrypi.github.io/pico-sdk- ... chdog.html

Code: Select all

watchdog_caused_reboot(void)
MicroPython does not seem to implement this function:

https://docs.micropython.org/en/v1.19/l ... e.WDT.html

Unless there's a memory location I can write data into that will survive a WDT reset, the only option I think I have left is to attempt to use a power supply sense input I have going into one of the ADC's.

Sounds good, but, the transient response looks something like this:

Image

On a WDT reboot this input will retain its voltage. You'd think you could use this to distinguish between a normal power-up reset and a WDT reset. Not so simple.

The problem is that this circuit, while having a capacitor, was not designed for this purpose. It comes-up very quickly from zero. This gives me about less than 4 ms on power-up to understand that this is a power-up reset vs. a WDT event. Much beyond that point and everything looks the same.

This is complicated by the fact that I need to have a delay on initialization in order to allow for MicroPython to set things up properly. Not sure I can actually do anything (or enough) within 4 ms of power-up.

And then there's the scenario of when my code actually resets the board (firmware update). Once again, using this power sense input isn't likely to give me enough time to sort things out.

I am about to experiment with the idea of placing a value in, perhaps, the I2C or SPI registers and seeing what might survive reset (if anything). I am not using those ports at the moment (although I will have to on this board at some point).

I have another pin connected to a thermistor with a resistor in series (divider) into an ADC. No capacitor. We could manually add a small capacitor I suppose. Doing that to 1000 boards isn't something anyone would look forward to at all, particularly when there are no pads for the cap to solder to.

A software solution would definitely be best. The C API seems to be there. Any quick hacks to access it? At this stage getting into recompiling MicroPython becomes risky (almost anything is when you are talking about 1000 boards).

Thanks.

davef
Posts: 811
Joined: Thu Apr 30, 2020 1:03 am
Location: Christchurch, NZ

Re: RP2040: How to determine we are coming back from a WDT reset?

Post by davef » Fri Jul 08, 2022 7:07 pm

https://docs.micropython.org/en/latest/ ... chine.html

Does the RP2040 not have:
machine.WDT_RESET

martincho
Posts: 96
Joined: Mon May 16, 2022 9:59 pm

Re: RP2040: How to determine we are coming back from a WDT reset?

Post by martincho » Fri Jul 08, 2022 8:21 pm

davef wrote:
Fri Jul 08, 2022 7:07 pm
https://docs.micropython.org/en/latest/ ... chine.html

Does the RP2040 not have:
machine.WDT_RESET
Ah. Completely missed that one. Thanks!

I'll have to test and see if it covers all scenarios I need.

Documentation note: There should be a link to this in the WDT documentation. At least a mention. My head is so deep into what I am doing that I didn't even think about looking for it in the machine module. I did search for "reset" and the first few results refer to machine.reset() so I moved on and never looked in there.

Thanks again.

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: RP2040: How to determine we are coming back from a WDT reset?

Post by jimmo » Sat Jul 09, 2022 12:14 am

martincho wrote:
Fri Jul 08, 2022 8:21 pm
Documentation note: There should be a link to this in the WDT documentation. At least a mention.
I've been working on docs this week and this is one of the changes I've made, including bringing more of the port specific information into the machine docs.

(Basically your point about having to read multiple different pages spanning one concept is exactly what I've been trying to improve).

martincho
Posts: 96
Joined: Mon May 16, 2022 9:59 pm

Re: RP2040: How to determine we are coming back from a WDT reset?

Post by martincho » Sat Jul 09, 2022 12:39 am

jimmo wrote:
Sat Jul 09, 2022 12:14 am
martincho wrote:
Fri Jul 08, 2022 8:21 pm
Documentation note: There should be a link to this in the WDT documentation. At least a mention.
I've been working on docs this week and this is one of the changes I've made, including bringing more of the port specific information into the machine docs.

(Basically your point about having to read multiple different pages spanning one concept is exactly what I've been trying to improve).
Maybe I can help with some documentation (perhaps in the form of example code?) starting in a few weeks. It might be easier to get started with that than to dive into coding (which would require far more time and effort).

Jibun no kage
Posts: 144
Joined: Mon Jul 25, 2022 9:45 pm

Re: RP2040: How to determine we are coming back from a WDT reset?

Post by Jibun no kage » Tue Aug 02, 2022 1:36 am

I would definitely help review documentation... I wrote complex engineering policy guides and procedural manuals for a Fortune 10 firm for many years, while doing enterprise virtualization design. So if you want someone to read and provide feedback, let me know!

Post Reply