From 39f30aeec699944da096107cc930c783f61f7712 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Wed, 20 Dec 2017 15:17:06 -0800 Subject: [PATCH] Fix 1200 baud reset. Fixes #494 --- atmel-samd/common-hal/microcontroller/__init__.c | 3 +-- atmel-samd/mphalport.c | 2 +- atmel-samd/reset.c | 5 +++++ atmel-samd/reset.h | 1 + 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/atmel-samd/common-hal/microcontroller/__init__.c b/atmel-samd/common-hal/microcontroller/__init__.c index b90c38b604..26f09a8ade 100644 --- a/atmel-samd/common-hal/microcontroller/__init__.c +++ b/atmel-samd/common-hal/microcontroller/__init__.c @@ -55,7 +55,6 @@ void common_hal_mcu_enable_interrupts(void) { } extern uint32_t _ezero; -extern uint32_t _srelocate; void common_hal_mcu_on_next_reset(mcu_runmode_t runmode) { // Set up the defaults. @@ -63,7 +62,7 @@ void common_hal_mcu_on_next_reset(mcu_runmode_t runmode) { _ezero = CIRCUITPY_CANARY_WORD; if (runmode == RUNMODE_BOOTLOADER) { - if (&_bootloader_dbl_tap < &_srelocate) { + if (!bootloader_available()) { mp_raise_ValueError("Cannot reset into bootloader because no bootloader is present."); } // Pretend to be the first of the two reset presses needed to enter the diff --git a/atmel-samd/mphalport.c b/atmel-samd/mphalport.c index 4d597be6b2..24126b1e81 100644 --- a/atmel-samd/mphalport.c +++ b/atmel-samd/mphalport.c @@ -62,7 +62,7 @@ volatile bool reset_on_disconnect = false; void usb_dtr_notify(uint8_t port, bool set) { mp_cdc_enabled = set; - if (!set && reset_on_disconnect && _bootloader_dbl_tap != 0) { + if (!set && reset_on_disconnect && bootloader_available()) { reset_to_bootloader(); } } diff --git a/atmel-samd/reset.c b/atmel-samd/reset.c index 822789b472..8fb7696974 100644 --- a/atmel-samd/reset.c +++ b/atmel-samd/reset.c @@ -38,3 +38,8 @@ void reset_to_bootloader(void) { _bootloader_dbl_tap = DBL_TAP_MAGIC; reset(); } + +extern uint32_t _srelocate; +bool bootloader_available(void) { + return &_bootloader_dbl_tap >= &_srelocate; +} diff --git a/atmel-samd/reset.h b/atmel-samd/reset.h index 00b2312bb7..4d04c11ce2 100644 --- a/atmel-samd/reset.h +++ b/atmel-samd/reset.h @@ -33,5 +33,6 @@ extern uint32_t _bootloader_dbl_tap; void reset_to_bootloader(void); void reset(void); +bool bootloader_available(void); #endif // MICROPY_INCLUDED_ATMEL_SAMD_RESET_H