Skip to content

reset_cause() is not implemented: MCUSR needs a startup-stub capture in the HAL #17

Description

@begeistert

What happens

machine.reset_cause() is absent from src/pymcu_micropython/machine.py. The module
already has the reset-cause constants (PWRON_RESET, HARD_RESET, WDT_RESET,
DEEPSLEEP_RESET, SOFT_RESET), and soft_reset() (a watchdog-triggered restart) is now
implemented -- this issue is left tracking only reset_cause().

The ATmega328P's MCUSR register records the previous reset's cause: PORF (power-on),
EXTRF (external/reset pin), BORF (brown-out) and WDRF (watchdog) bits. The compiler's
AVR startup stub does not currently touch MCUSR at all, so nothing captures it before
avrdude's bootloader (where one is in the flashing path) or any later code can clear it, and
the register is not spelled the same way across every AVR part in this HAL (some older parts
call it MCUCSR, not MCUSR).

What I'd expect

machine.reset_cause() reading a value the startup stub captured from MCUSR/MCUCSR
before anything else can touch it, with the right register name and address picked per chip
the way pymcu.hal.avr.watchdog already dispatches per chip.

Repo choice

The startup-stub capture and per-chip register naming belong in PyMCU's AVR HAL/runtime;
src/pymcu_micropython/machine.py only needs to read back whatever the HAL exposes.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions