Skip to content

Commit

Permalink
samd/modmachine: Get the bootloader magic address from the lib.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
robert-hh authored and dpgeorge committed Oct 25, 2022
1 parent 03075a6 commit f0399d3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
6 changes: 6 additions & 0 deletions ports/samd/boards/SPARKFUN_SAMD51_THING_PLUS/mpconfigboard.h
Expand Up @@ -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))
14 changes: 11 additions & 3 deletions ports/samd/modmachine.c
Expand Up @@ -41,28 +41,36 @@
#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;
}
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;
}
Expand Down

0 comments on commit f0399d3

Please sign in to comment.