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.
This commit is contained in:
robert-hh 2022-08-11 11:22:58 +02:00 committed by Damien George
parent 03075a6839
commit f0399d35e4
2 changed files with 17 additions and 3 deletions

View File

@ -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))

View File

@ -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;
}