Skip to content

Commit 552f6cf

Browse files
committed
RP2040: add bootloader via double tap support
1 parent eae7dd1 commit 552f6cf

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#include "pico.h"
2+
#include "pico/time.h"
3+
#include "pico/bootrom.h"
4+
5+
// Allow user override of the LED mask
6+
#ifndef USB_BOOT_LED_ACTIVITY_MASK
7+
#define USB_BOOT_LED_ACTIVITY_MASK 1
8+
#endif
9+
10+
// Doesn't make any sense for a RAM only binary
11+
#if !PICO_NO_FLASH
12+
13+
static const uint32_t magic_token[] = {
14+
0xf01681de, 0xbd729b29, 0xd359be7a,
15+
};
16+
17+
static uint32_t __uninitialized_ram(magic_location)[count_of(magic_token)];
18+
19+
// run at initialization time
20+
static void __attribute__((constructor)) boot_double_tap_check() {
21+
for (uint i = 0; i < count_of(magic_token); i++) {
22+
if (magic_location[i] != magic_token[i]) {
23+
// Arm for 100 ms then disarm and continue booting
24+
for (i = 0; i < count_of(magic_token); i++) {
25+
magic_location[i] = magic_token[i];
26+
}
27+
busy_wait_us(100000);
28+
magic_location[0] = 0;
29+
return;
30+
}
31+
}
32+
33+
magic_location[0] = 0;
34+
reset_usb_boot(USB_BOOT_LED_ACTIVITY_MASK, 0);
35+
}
36+
37+
#endif

0 commit comments

Comments
 (0)