Skip to content

Commit d3802b5

Browse files
committed
Added "double-tap" feature to bootloader
Bootloader is activated by quickly double tapping to the reset button
1 parent 5a6dafa commit d3802b5

File tree

5 files changed

+39
-3
lines changed

5 files changed

+39
-3
lines changed

bootloaders/zero/main.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,32 @@ static void check_start_application(void)
9797
led_port->DIRSET.reg = (1<<30);
9898
led_port->OUTCLR.reg = (1<<30);
9999

100+
#if defined(BOOT_DOUBLE_TAP_ADDRESS)
101+
if (PM->RCAUSE.bit.POR)
102+
{
103+
/* On power-on initialize double-tap */
104+
BOOT_DOUBLE_TAP_DATA = 0;
105+
}
106+
else
107+
{
108+
if (BOOT_DOUBLE_TAP_DATA == 0) {
109+
/* First tap */
110+
BOOT_DOUBLE_TAP_DATA = 1;
111+
112+
for (uint32_t i=0; i<50000; i++) /* 200ms */
113+
/* force compiler to not optimize this... */
114+
__asm__ __volatile__("");
115+
116+
/* Timeout happened, continue boot... */
117+
BOOT_DOUBLE_TAP_DATA = 0;
118+
} else {
119+
/* Second tap, stay in bootloader */
120+
BOOT_DOUBLE_TAP_DATA = 0;
121+
return;
122+
}
123+
}
124+
#endif
125+
100126
uint32_t app_start_address;
101127

102128
/* Load the Reset Handler address of the application */

bootloaders/zero/main.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,16 @@
3434
#define CPU_FREQUENCY 8000000
3535

3636
#define APP_START_ADDRESS 0x00002000
37+
38+
/*
39+
* If BOOT_DOUBLE_TAP_ADDRESS is defined the bootloader is started by
40+
* quickly tapping two times on the reset button.
41+
* BOOT_DOUBLE_TAP_ADDRESS must point to a free SRAM cell that must not
42+
* be touched from the loaded application.
43+
*/
44+
#define BOOT_DOUBLE_TAP_ADDRESS 0x20007FFC
45+
#define BOOT_DOUBLE_TAP_DATA (*((volatile uint32_t *) BOOT_DOUBLE_TAP_ADDRESS))
46+
3747
#define BOOT_LOAD_PIN PIN_PA21 //Pin 7
3848
//#define BOOT_LOAD_PIN PIN_PA15 //Pin 5
3949
#define BOOT_PIN_MASK (1U << (BOOT_LOAD_PIN & 0x1f))

bootloaders/zero/samd21_sam_ba.bin

56 Bytes
Binary file not shown.

bootloaders/zero/samd21j18a_flash.ld

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ SEARCH_DIR(.)
5050
MEMORY
5151
{
5252
rom (rx) : ORIGIN = 0x00000000, LENGTH = 0x00040000
53-
ram (rwx) : ORIGIN = 0x20000000, LENGTH = 0x00008000
53+
ram (rwx) : ORIGIN = 0x20000000, LENGTH = 0x00008000-0x0004 /* 4 bytes used by bootloader to keep data between resets */
5454
}
5555

5656
/* The stack size used by the application. NOTE: you need to adjust according to your application. */

variants/arduino_zero/linker_scripts/gcc/flash_with_bootloader.ld

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
*/
2626
MEMORY
2727
{
28-
FLASH (rx) : ORIGIN = 0x00000000+0x2000, LENGTH = 0x00040000-0x2000
29-
RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x00008000
28+
FLASH (rx) : ORIGIN = 0x00000000+0x2000, LENGTH = 0x00040000-0x2000 /* First 8KB used by bootloader */
29+
RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x00008000-0x0004 /* Last 4B used by bootloader */
3030
}
3131

3232
/* Linker script to place sections and symbol values. Should be used together

0 commit comments

Comments
 (0)