Skip to content

Commit 7a23f8d

Browse files
committed
Check sketch vectors before waiting for double tap
Speeds up booting when sketch erases application flash on 1200bps touch reset.
1 parent f9fc82d commit 7a23f8d

File tree

1 file changed

+31
-31
lines changed

1 file changed

+31
-31
lines changed

bootloaders/zero/main.c

+31-31
Original file line numberDiff line numberDiff line change
@@ -44,37 +44,6 @@ static void check_start_application(void)
4444
// LED_init();
4545
// LED_off();
4646

47-
#if defined(BOOT_DOUBLE_TAP_ADDRESS)
48-
#define DOUBLE_TAP_MAGIC 0x07738135
49-
if (PM->RCAUSE.bit.POR)
50-
{
51-
/* On power-on initialize double-tap */
52-
BOOT_DOUBLE_TAP_DATA = 0;
53-
}
54-
else
55-
{
56-
if (BOOT_DOUBLE_TAP_DATA == DOUBLE_TAP_MAGIC)
57-
{
58-
/* Second tap, stay in bootloader */
59-
BOOT_DOUBLE_TAP_DATA = 0;
60-
return;
61-
}
62-
63-
/* First tap */
64-
BOOT_DOUBLE_TAP_DATA = DOUBLE_TAP_MAGIC;
65-
66-
/* Wait 0.5sec to see if the user tap reset again.
67-
* The loop value is based on SAMD21 default 1MHz clock @ reset.
68-
*/
69-
for (uint32_t i=0; i<125000; i++) /* 500ms */
70-
/* force compiler to not optimize this... */
71-
__asm__ __volatile__("");
72-
73-
/* Timeout happened, continue boot... */
74-
BOOT_DOUBLE_TAP_DATA = 0;
75-
}
76-
#endif
77-
7847
#if (!defined DEBUG) || ((defined DEBUG) && (DEBUG == 0))
7948
uint32_t* pulSketch_Start_Address;
8049
#endif
@@ -108,6 +77,37 @@ uint32_t* pulSketch_Start_Address;
10877
return;
10978
}
11079

80+
#if defined(BOOT_DOUBLE_TAP_ADDRESS)
81+
#define DOUBLE_TAP_MAGIC 0x07738135
82+
if (PM->RCAUSE.bit.POR)
83+
{
84+
/* On power-on initialize double-tap */
85+
BOOT_DOUBLE_TAP_DATA = 0;
86+
}
87+
else
88+
{
89+
if (BOOT_DOUBLE_TAP_DATA == DOUBLE_TAP_MAGIC)
90+
{
91+
/* Second tap, stay in bootloader */
92+
BOOT_DOUBLE_TAP_DATA = 0;
93+
return;
94+
}
95+
96+
/* First tap */
97+
BOOT_DOUBLE_TAP_DATA = DOUBLE_TAP_MAGIC;
98+
99+
/* Wait 0.5sec to see if the user tap reset again.
100+
* The loop value is based on SAMD21 default 1MHz clock @ reset.
101+
*/
102+
for (uint32_t i=0; i<125000; i++) /* 500ms */
103+
/* force compiler to not optimize this... */
104+
__asm__ __volatile__("");
105+
106+
/* Timeout happened, continue boot... */
107+
BOOT_DOUBLE_TAP_DATA = 0;
108+
}
109+
#endif
110+
111111
/*
112112
#if defined(BOOT_LOAD_PIN)
113113
volatile PortGroup *boot_port = (volatile PortGroup *)(&(PORT->Group[BOOT_LOAD_PIN / 32]));

0 commit comments

Comments
 (0)