summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrobert-hh <robert@hammelrath.com>2022-08-11 11:22:58 +0200
committerDamien George <damien@micropython.org>2022-10-25 23:09:04 +1100
commitf0399d35e4f7ad4e48b22f02b80a7ee506c9ec64 (patch)
tree8226769fad3a495bfad3b17001b4f47b4c177606
parent03075a68399a6450fd0e238dd75314805f8365b7 (diff)
samd/modmachine: Get the bootloader magic address from the lib.
Instead of being hard-coded, and then it works for all MCUs. That fits except for a Sparkfun SAMD51 Thing Plus (known) bug, which uses 192k - 4 as magic address. Therefore, that address is set as well to avoid a problem when this bug is fixed by Sparkfun.
-rw-r--r--ports/samd/boards/SPARKFUN_SAMD51_THING_PLUS/mpconfigboard.h6
-rw-r--r--ports/samd/modmachine.c14
2 files changed, 17 insertions, 3 deletions
diff --git a/ports/samd/boards/SPARKFUN_SAMD51_THING_PLUS/mpconfigboard.h b/ports/samd/boards/SPARKFUN_SAMD51_THING_PLUS/mpconfigboard.h
index e797ccca9..a51b71c36 100644
--- a/ports/samd/boards/SPARKFUN_SAMD51_THING_PLUS/mpconfigboard.h
+++ b/ports/samd/boards/SPARKFUN_SAMD51_THING_PLUS/mpconfigboard.h
@@ -2,3 +2,9 @@
#define MICROPY_HW_MCU_NAME "SAMD51J20A"
#define MICROPY_HW_XOSC32K (1)
+
+// There seems to be an inconsistency in the SAMD51 Thing bootloader in that
+// the bootloader magic address is at the end of a 192k RAM area, instead of
+// 256k. Since the SAMD51x20A has 256k RAM, the loader symbol is at that address
+// and so there is a fix here using the previous definition.
+#define DBL_TAP_ADDR_ALT ((volatile uint32_t *)(HSRAM_ADDR + HSRAM_SIZE - 0x10000 - 4))
diff --git a/ports/samd/modmachine.c b/ports/samd/modmachine.c
index 2a8e34a96..ce5fef76f 100644
--- a/ports/samd/modmachine.c
+++ b/ports/samd/modmachine.c
@@ -41,21 +41,26 @@
#include "hpl_pm_base.h"
#if MICROPY_PY_MACHINE
-
#if defined(MCU_SAMD21)
-#define DBL_TAP_ADDR ((volatile uint32_t *)(0x20000000 + 32 * 1024 - 4))
+#define DBL_TAP_ADDR ((volatile uint32_t *)(HMCRAMC0_ADDR + HMCRAMC0_SIZE - 4))
#elif defined(MCU_SAMD51)
-#define DBL_TAP_ADDR ((volatile uint32_t *)(0x20000000 + 192 * 1024 - 4))
+#define DBL_TAP_ADDR ((volatile uint32_t *)(HSRAM_ADDR + HSRAM_SIZE - 4))
#endif
+// A board may define a DPL_TAP_ADDR_ALT, which will be set as well
+// Needed at the moment for Sparkfun SAMD51 Thing Plus
#define DBL_TAP_MAGIC_LOADER 0xf01669ef
#define DBL_TAP_MAGIC_RESET 0xf02669ef
#define LIGHTSLEEP_CPU_FREQ 200000
extern bool EIC_occured;
+extern uint32_t _dbl_tap_addr;
STATIC mp_obj_t machine_reset(void) {
*DBL_TAP_ADDR = DBL_TAP_MAGIC_RESET;
+ #ifdef DBL_TAP_ADDR_ALT
+ *DBL_TAP_ADDR_ALT = DBL_TAP_MAGIC_RESET;
+ #endif
NVIC_SystemReset();
return mp_const_none;
}
@@ -63,6 +68,9 @@ MP_DEFINE_CONST_FUN_OBJ_0(machine_reset_obj, machine_reset);
STATIC mp_obj_t machine_bootloader(void) {
*DBL_TAP_ADDR = DBL_TAP_MAGIC_LOADER;
+ #ifdef DBL_TAP_ADDR_ALT
+ *DBL_TAP_ADDR_ALT = DBL_TAP_MAGIC_LOADER;
+ #endif
NVIC_SystemReset();
return mp_const_none;
}