Skip to content

Commit d5df8c0

Browse files
committed
bootloader: bootloader start is triggered by magic number
To improve stability if the sketch overwrite the last SRAM location (in this case the double tap doesn't work but at least the sketch starts without problems)
1 parent 2c0b856 commit d5df8c0

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

bootloaders/zero/main.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,27 +98,33 @@ static void check_start_application(void)
9898
led_port->OUTCLR.reg = (1<<30);
9999

100100
#if defined(BOOT_DOUBLE_TAP_ADDRESS)
101+
#define DOUBLE_TAP_MAGIC 0x07738135
101102
if (PM->RCAUSE.bit.POR)
102103
{
103104
/* On power-on initialize double-tap */
104105
BOOT_DOUBLE_TAP_DATA = 0;
105106
}
106107
else
107108
{
108-
if (BOOT_DOUBLE_TAP_DATA == 0) {
109+
switch (BOOT_DOUBLE_TAP_DATA) {
110+
case 0:
109111
/* First tap */
110-
BOOT_DOUBLE_TAP_DATA = 1;
112+
BOOT_DOUBLE_TAP_DATA = DOUBLE_TAP_MAGIC;
111113

112114
for (uint32_t i=0; i<50000; i++) /* 200ms */
113115
/* force compiler to not optimize this... */
114116
__asm__ __volatile__("");
115117

116118
/* Timeout happened, continue boot... */
117119
BOOT_DOUBLE_TAP_DATA = 0;
118-
} else {
120+
break;
121+
case DOUBLE_TAP_MAGIC:
119122
/* Second tap, stay in bootloader */
120123
BOOT_DOUBLE_TAP_DATA = 0;
121124
return;
125+
default:
126+
/* Fallback... reset counter and continue boot */
127+
BOOT_DOUBLE_TAP_DATA = 0;
122128
}
123129
}
124130
#endif

bootloaders/zero/samd21_sam_ba.bin

12 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)