Skip to content

PyPortal Titano not honoring RunMode.UF2 flag on_next_reset #8263

@bcr

Description

@bcr

CircuitPython version

Adafruit CircuitPython 8.2.1 on 2023-07-25; Adafruit PyPortal Titano with samd51j20

Code/REPL

>>> import microcontroller
>>> microcontroller.on_next_reset(microcontroller.RunMode.UF2)
>>> microcontroller.reset()

Behavior

Reboots to normal running CircuitPython

Description

When I run the provided code, it just goes back to normal user mode.

Additional information

If I use the older RunMode.BOOTLOADER it mounts the PORTALBOOT drive which is what I want.

I think the problem is here https://github.com/adafruit/circuitpython/blob/main/ports/atmel-samd/common-hal/microcontroller/__init__.c#L66

My suggested change is:

diff --git a/ports/atmel-samd/common-hal/microcontroller/__init__.c b/ports/atmel-samd/common-hal/microcontroller/__init__.c
index d1c02b360..054d7ee7f 100644
--- a/ports/atmel-samd/common-hal/microcontroller/__init__.c
+++ b/ports/atmel-samd/common-hal/microcontroller/__init__.c
@@ -63,7 +63,7 @@ void common_hal_mcu_enable_interrupts(void) {
 }
 
 void common_hal_mcu_on_next_reset(mcu_runmode_t runmode) {
-    if (runmode == RUNMODE_BOOTLOADER) {
+    if ((runmode == RUNMODE_BOOTLOADER) || (runmode == RUNMODE_UF2)) {
         if (!bootloader_available()) {
             mp_raise_ValueError(translate("Cannot reset into bootloader because no bootloader is present"));
         }

But this suggestion could be uninformed, dangerous, or just plain wrong. I don't know if there are some SAMD that have both a bootloader and a UF2 mode for instance.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions