mimxrt/modmachine: Fix reset_cause and add HARD/DEEPSLEEP constants. - #19619
mimxrt/modmachine: Fix reset_cause and add HARD/DEEPSLEEP constants.#19619dpgeorge wants to merge 1 commit into
Conversation
|
@robert-hh would appreciate if you could take a look at this change, see if it makes sense to you. Thanks! |
|
Code size report: |
|
Thank you! |
|
Will do. |
|
Tested with MIMXRT1011 (Adafruit Metro M7), MIMXRT1020 (MIMXRT1020-EVK), MIMXRT1062 (Teensy 4.1 and OpenMV RT1060), MIMXRT1176 (MIMXRT1170-EVK). PWRON_RESET, WDT_RESET, DEEPSLEEP_RESET and SOFT_RESET are reliably detected. HARD_RESET is reported only immediately after firmware upload by the Adafruit and MIMXRT1020-EVK board. The MIMXRT MCUs do not have a dedicated hard reset Pin. Some board have a reset button, but that causes a power cycle. There is an irregularity with the MIMXRT1170-EVK board.
|
|
Thanks for testing!
I tested this by issuing
OK. That seems unrelated to this PR.
I pushed a commit which should resolve that issue: clearing the LPTA bit if it's set. Could you please retest on that board? |
Octoprobe PR report
FailuresGroup: run-mpremote-tests.sh
|
It is a different issue- Deepsleep seem generally strange.
No change. Maybe one should fix the deepsleep() behavior first. |
|
At least, replacing
|
| reset_cause = MP_DEEPSLEEP_RESET; | ||
| } else if (SNVS->LPSR & SNVS_LPSR_LPTA_MASK) { | ||
| // Device was reset due to low-power timer alarm. | ||
| SNVS->LPSR &= ~SNVS_LPSR_LPTA_MASK; |
There was a problem hiding this comment.
Better call instead machine_rtc_irq_deinit();. That fixes the sticky DEEPSLEEP_RESET state.
There was a problem hiding this comment.
You can call as well machine_rtc_alarm_off(true), which is called by machine_rtc_irq_deinit(), but it requires a declaration in modmachine.c, and an extra push of the argument.
There was a problem hiding this comment.
OK, thanks for that. I've now applied your suggestion to call machine_rtc_alarm_off(true) (that function is independent of the Python bindings/state, so a better fit).
Tested on TEENSY40 and it still works.
The `machine.reset_cause()` function was only partially working on mimxrt. This commit fixes it so that all five reset causes now work correctly: - SOFT_RESET is now set only after a soft reset at the REPL. - HARD_RESET is now set correctly (previously it used SOFT_RESET), and this constant is exposed to Python. - DEEPSLEEP_RESET is now set when the timer alarm wakes the device, and this constant is exposed to Python. Signed-off-by: Damien George <damien@micropython.org>
7456a79 to
a056c59
Compare
What argument are you using? I'm calling But regardless, that needs to be fixed in a separate PR. |
|
using
For RT117x, using rtc.alarm() fails as well. The respective IRQ is simply not configured. I got to that because |
Summary
The
machine.reset_cause()function was only partially working on mimxrt. This commit fixes it so that all five reset causes now work correctly:Testing
Tested on TEENSY40, using this helper script:
Run that via
mpremote resume run cause.pyto check the reset cause.Tested all 5 cases, using
machine.reset(),machine.deepsleep(1000)andmachine.WDT(timeout=1000)to trigger the cases.Generative AI
I did not use generative AI tools when creating this PR.