Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions atmel-samd/common-hal/microcontroller/__init__.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,14 @@ 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.
_bootloader_dbl_tap = DBL_TAP_MAGIC;
_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
Expand Down
2 changes: 1 addition & 1 deletion atmel-samd/mphalport.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Expand Down
5 changes: 5 additions & 0 deletions atmel-samd/reset.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
1 change: 1 addition & 0 deletions atmel-samd/reset.h
Original file line number Diff line number Diff line change
Expand Up @@ -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