Skip to content
This repository was archived by the owner on Jan 29, 2024. It is now read-only.

Commit 2f78bb9

Browse files
committed
Make the magic "enter bootloader" address constant
To enter the bootloader, app sets *0x20000000=0xf02669ef and reboots
1 parent 397bb55 commit 2f78bb9

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

bootloader.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -226,9 +226,8 @@ static void USB_Service(void)
226226
}
227227

228228
#ifdef USE_DBL_TAP
229-
extern int __RAM_segment_used_end__;
230-
static volatile uint32_t *DBL_TAP_PTR = (volatile uint32_t *)(&__RAM_segment_used_end__);
231229
#define DBL_TAP_MAGIC 0xf02669ef
230+
static volatile uint32_t __attribute__((section(".dont_move"))) double_tap;
232231
#endif
233232

234233
void bootloader(void)
@@ -259,20 +258,20 @@ void bootloader(void)
259258
return; /* we've checked everything and there is no reason to run the bootloader */
260259
#else
261260
if (PM->RCAUSE.reg & PM_RCAUSE_POR)
262-
*DBL_TAP_PTR = 0; /* a power up event should never be considered a 'double tap' */
261+
double_tap = 0; /* a power up event should never be considered a 'double tap' */
263262

264-
if (*DBL_TAP_PTR == DBL_TAP_MAGIC)
263+
if (double_tap == DBL_TAP_MAGIC)
265264
{
266265
/* a 'double tap' has happened, so run bootloader */
267-
*DBL_TAP_PTR = 0;
266+
double_tap = 0;
268267
goto run_bootloader;
269268
}
270269

271270
/* postpone boot for a short period of time; if a second reset happens during this window, the "magic" value will remain */
272-
*DBL_TAP_PTR = DBL_TAP_MAGIC;
271+
double_tap = DBL_TAP_MAGIC;
273272
volatile int wait = 65536; while (wait--);
274273
/* however, if execution reaches this point, the window of opportunity has closed and the "magic" disappears */
275-
*DBL_TAP_PTR = 0;
274+
double_tap = 0;
276275
return;
277276
#endif
278277

linker/samd11d14.ld

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ SECTIONS
6767
KEEP(*(.bss.$RESERVED*))
6868
} > ram
6969

70+
.dont_move_block (NOLOAD): ALIGN(4)
71+
{
72+
*(.dont_move)
73+
}
74+
7075
.data : ALIGN(4)
7176
{
7277
FILL(0xff)

0 commit comments

Comments
 (0)