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

Commit 2551fa5

Browse files
authored
Merge pull request #1 from ianrrees/fixed-dbl-tap-addr
Make the magic "double tap" address constant
2 parents 397bb55 + 02661fc commit 2551fa5

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,12 @@ The USBCRM mode should be universal, as it doesn't depend on optional external c
4848

4949
Pre-compiled images are already available via this project's Releases tab.
5050

51-
[Rowley Crossworks for ARM](http://www.rowley.co.uk/arm/) is presently suggested to compile this code, as it includes support for Clang; at this time, I am not aware of any other ready-to-use (and multi-OS to boot) Clang ARM cross-compiler package that I can readily point users to. With Crossworks for ARM v4.6.1, compiling v1.05 using the Clang 9.0.1 compiler produces a 1003 byte image. The more mainstream GCC lags behind Clang, although more recent GCC versions produce code that is less overweight than in years past.
51+
[Rowley Crossworks for ARM](http://www.rowley.co.uk/arm/) is presently suggested to compile this code, as it includes support for Clang; at this time, I am not aware of any other ready-to-use (and multi-OS to boot) Clang ARM cross-compiler package that I can readily point users to. With Crossworks for ARM v4.8.1, compiling v1.06 using the Clang 11.1.0 compiler produces a 995 byte image. The more mainstream GCC lags behind Clang, although more recent GCC versions produce code that is less overweight than in years past.
5252

53-
|bootloader variant|Clang 9.0.1 (-O1) |GNU Arm 2018-q3 (-Os) |GNU Arm 2019-q4 (-Os) |
54-
|------------------|------------------|----------------------|----------------------|
55-
| USE_DBL_TAP | 1003 bytes | 1044 bytes (too big!)| 1041 bytes (too big!)|
56-
| GPIO input | 979 bytes | 1008 bytes | 1006 bytes |
53+
|bootloader variant|Clang 9.0.1 (-O1) |Clang 11.1.0 (-O1) |GNU Arm 2018-q3 (-Os) |GNU Arm 2019-q4 (-Os) |
54+
|------------------|------------------|-------------------|----------------------|----------------------|
55+
| USE_DBL_TAP | 1003 bytes | 995 bytes | 1044 bytes (too big!)| 1041 bytes (too big!)|
56+
| GPIO input | 979 bytes | 975 bytes | 1008 bytes | 1006 bytes |
5757

5858
A Makefile supporting GCC is provided, but even if you have the latest GCC, it may not be able to output a version within the 1024 bytes available. The latest GCC for ARM can be here: [GNU Arm Embedded Toolchain](https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-rm). Note that if you are adapting the Makefile for use with clang, try replacing the "-Os" argument in CFLAGS with something like "-O1" if the output size is larger than expected.
5959

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(".vectors_ram"))) 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+
*(.vectors_ram)
73+
}
74+
7075
.data : ALIGN(4)
7176
{
7277
FILL(0xff)

0 commit comments

Comments
 (0)