-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
ESP32/machine_wdt.c: Add WDT.deinit() method. #6631
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
ESP32/machine_wdt.c: Add WDT.deinit() method. #6631
Conversation
Test code:
|
Is this wise? A WDT is supposed to force a reset even in the event that the code runs wild. To guarantee this, there should be no way to disable the WDT in code. |
I can see the usefulness in deinitializing a wdt. Sometimes you might just want to debug something remotely during runtime, so you have to interrupt your program to check variables etc.. But if you have a WDT active, after a few seconds you'll be "thrown out" and debugging could become a nuisance. |
@kevinkk525 Yes, yes, yes. WDT.deinit () is only needed in debug mode, not in product release. |
I suppose one approach would be to make it a compile-time option. I will be interested to see the views of the maintainers. |
Let's take a look at a standalone MicroPython device which is only connected to a W-iFi router. Now you can connect to device via WebREPL, see print() messages, but you can't upload files to device when your program stay in an infinite working loop. You need to exit from the loop. When you connect to the REPL(via USB-UART)(if it possible), you can break boot.py or main.py by Keyboard Interrupt before starting WDT, but you don't have a time to press Ctrl-C in WebREPL. |
Dear @dpgeorge and other maintainers. Are there any chances of a code review? Thanks. P.S. Is the maintainer's group exist? How is the right way to request a code review? |
0aba85e
to
3b5b300
Compare
@xorbit @jimmo @jonathanhogg @karfas @toybuilder |
Better to build a debug and production version w/ or w/o watchdog. If the watchdog is enabled there should be NO WAY to disable it again. In almost all cases micro-controllers will run with watchdog (when enabled) until hell_freezes_over or reset. |
@rolandvs Is there another way to update the software over the network with WDT enabled? |
A simpler approach to the specific use case described would be to just reinitialise the watchdog with a longer timeout – like an hour or something. You can just call You get the same practical effect as turning it off, but retain both the ideological purity of the watchdog being unstoppable and the safety mechanism of an eventual automatic reboot if you cock up the REPL. Of course, you still run the risk of a bodged OTA update, but that's a whole different problem. My last solution to this involved retaining multiple versioned copies of the Python code with checksums and a fallback to the previous version in the event of a watchdog reset. |
@jonathanhogg Thank you very much.
That is solution |
+1 and not all hardware WDT support timeouts of an hour. Pyboard-D is only a few minutes iirc |
I have really no idea why I'm subscribed to this topic, but here are my 2 cents: A programming language used in the embedded area needs to give the user as much control as possible about the hardware. If the language/runtime allows to switch on a function like the WDT it should also allow the opposite. @peterhinch: While I also think that the WDT should remain active forever once enabled, it is also my opinion this should be MY decision as a developer, not some language/runtime restriction "because ugly/bad design/whatever". It looks like there is some need for a function like this. |
So I'm not against adding a That said, I'd argue that the Generally, I'd say the docs need a bit of work and I note that this PR also introduces a new reset reason code without mention or documentation. |
On further thought my point about it being desirable to have no way to disable a WDT, while theoretically correct, doesn't actually work in this case. The fact that it is possible to write code which implements A real WDT is a piece of hardware attached to the reset pin. |
I believe that the ESP32 watchdog is actually a per-thread watchdog implemented at the RTOS level. |
Abstracting the interface to a generic piece of hardware (chosen by the user, initialized by a combination of I/O pins, a string sent from the UART, whatever) is most likely not micropython's Are there any ports or boards out there without a watchdog of some kind? |
A watchdog module is present in the ports for STM32, ESP32, ESP8266, RP2 and CC3200. |
My point is that a real, grown-up, mission critical WDT is implemented in hardware (either on-chip or externally). Such a WDT is designed so it cannot be disabled at a hardware level. If it is possible to disable it in code, then a processor that has run wild might conceivably disable it. If the hardware design is such that the WDT can be disabled in code then all bets are off. My initial objection is therefore invalid. Adding a Python method doesn't make any difference: the problem is in hardware and cannot be altered in code. |
I agree with Peter and Jonathan. There should be no way to disable a Watchdog and increasing the timeout is a safer way to debug. You can only increase it to 32 sec on STM32, but that's probably manageable.
Not quite, the STM32 requires a write sequence to unlock and disable the WDT. As long as that code sequence doesn't exist it's unlikely a corrupt program counter would find random code to execute the sequence required. But if the disable code is built into the codebase, even if it is never called then a corrupt program counter may find it. |
Good point, but I don't think we've quite got to the end of this rabbit hole. |
This reverts commit 3b5b300.
The discussion has moved away from the main issue. Try to update this:
The solution is to reinitialize the watchdog with a longer timeout or WDT.deinit(). |
PR is closed in favor of |
isn't there NVIC_SystemReset() ? |
@mrx23dot: |
it's CMSIS, every ARM and riscV, maybe they also implemented. |
The WDT.deinit() method allows you to execute sys.exit() to enter to REPL(WebREPL) manual mode without reboot caused by the WDT.
This function may be interested in ESP8266, WiPy, RP2, and other ports.