diff options
| author | Dan Halbert <halbert@halwitz.org> | 2018-01-08 12:44:06 -0500 |
|---|---|---|
| committer | Scott Shawcroft <scott@tannewt.org> | 2018-01-08 09:44:06 -0800 |
| commit | 1805bcac76e7751493b6b3853279429ff4920cb9 (patch) | |
| tree | 2288796e086eb5f26f712b6075c299c5a24e7424 | |
| parent | b1b89c409e8d5265086f4b681f95d460794d5039 (diff) | |
enable use of CIRCUITPY_CANARY_WORD (needed for 2.2 merge) (#513)
enable use of CIRCUITPY_CANARY_WORD (needed for 2.2 merge)
RCAUSE (reset cause) is fetched differently in SAMD21 vs SAMD51
| -rw-r--r-- | ports/atmel-samd/supervisor/port.c | 59 |
1 files changed, 37 insertions, 22 deletions
diff --git a/ports/atmel-samd/supervisor/port.c b/ports/atmel-samd/supervisor/port.c index 1876a61e1..7d8c06822 100644 --- a/ports/atmel-samd/supervisor/port.c +++ b/ports/atmel-samd/supervisor/port.c @@ -36,6 +36,14 @@ #include "hpl/gclk/hpl_gclk_base.h" #include "hpl/pm/hpl_pm_base.h" +#ifdef SAMD21 +#include "hri/hri_pm_d21.h" +#endif +#ifdef SAMD51 +#include "hri/hri_rstc_d51.h" +#endif + + #include "common-hal/microcontroller/Pin.h" #include "tick.h" @@ -65,28 +73,35 @@ safe_mode_t port_init(void) { #endif #endif -// // On power on start or external reset, set _ezero to the canary word. If it -// // gets killed, we boot in safe mod. _ezero is the boundary between statically -// // allocated memory including the fixed MicroPython heap and the stack. If either -// // misbehaves, the canary will not be in tact after soft reset. -// #ifdef CIRCUITPY_CANARY_WORD -// if (PM->RCAUSE.bit.POR == 1 || PM->RCAUSE.bit.EXT == 1) { -// _ezero = CIRCUITPY_CANARY_WORD; -// } else if (PM->RCAUSE.bit.SYST == 1) { -// // If we're starting from a system reset we're likely coming from the -// // bootloader or hard fault handler. If we're coming from the handler -// // the canary will be CIRCUITPY_SAFE_RESTART_WORD and we don't want to -// // revive the canary so that a second hard fault won't restart. Resets -// // from anywhere else are ok. -// if (_ezero == CIRCUITPY_SAFE_RESTART_WORD) { -// _ezero = ~CIRCUITPY_CANARY_WORD; -// } else { -// _ezero = CIRCUITPY_CANARY_WORD; -// } -// } -// #endif -// -// load_serial_number(); + +// On power on start or external reset, set _ezero to the canary word. If it +// gets killed, we boot in safe mode. _ezero is the boundary between statically +// allocated memory including the fixed MicroPython heap and the stack. If either +// misbehaves, the canary will not be intact after soft reset. +#ifdef CIRCUITPY_CANARY_WORD +#ifdef SAMD21 + bool power_on_or_external_reset = hri_pm_get_RCAUSE_POR_bit(PM) || hri_pm_get_RCAUSE_EXT_bit(PM); + bool system_reset = hri_pm_get_RCAUSE_EXT_bit(PM); +#endif +#ifdef SAMD51 + bool power_on_or_external_reset = hri_rstc_get_RCAUSE_POR_bit(RSTC) || hri_rstc_get_RCAUSE_EXT_bit(RSTC); + bool system_reset = hri_rstc_get_RCAUSE_EXT_bit(RSTC); +#endif + if (power_on_or_external_reset) { + _ezero = CIRCUITPY_CANARY_WORD; + } else if (system_reset) { + // If we're starting from a system reset we're likely coming from the + // bootloader or hard fault handler. If we're coming from the handler + // the canary will be CIRCUITPY_SAFE_RESTART_WORD and we don't want to + // revive the canary so that a second hard fault won't restart. Resets + // from anywhere else are ok. + if (_ezero == CIRCUITPY_SAFE_RESTART_WORD) { + _ezero = ~CIRCUITPY_CANARY_WORD; + } else { + _ezero = CIRCUITPY_CANARY_WORD; + } + } +#endif init_mcu(); |
