@@ -53,6 +53,53 @@ SYS_INIT(disable_bootloader_mpu, PRE_KERNEL_1, CONFIG_KERNEL_INIT_PRIORITY_DEFAU
5353SYS_INIT (disable_mpu_rasr_xn , PRE_KERNEL_1 , CONFIG_KERNEL_INIT_PRIORITY_DEFAULT );
5454#endif
5555
56+ #if defined(CONFIG_BOARD_ARDUINO_NANO_RP2040_CONNECT )
57+ #include <zephyr/kernel.h>
58+ #include <zephyr/drivers/gpio.h>
59+ #include <pico/bootrom.h>
60+
61+ /*
62+ * Double-tap reset detection: if the board is reset twice within 500ms,
63+ * enter USB bootloader (BOOTSEL) mode. This mirrors the original
64+ * ArduinoCore-mbed NANO_RP2040_CONNECT behavior.
65+ *
66+ * A magic token is stored in uninitialized RAM (.noinit), which survives
67+ * a warm reset but is lost on power cycle. On boot:
68+ * - If the token is present: a second reset happened quickly, so we
69+ * clear the token and enter USB boot mode (never returns).
70+ * - If not: write the token, wait 500ms, then clear it and boot normally.
71+ */
72+ static const uint32_t magic_token [] = {
73+ 0xf01681de ,
74+ 0xbd729b29 ,
75+ 0xd359be7a ,
76+ };
77+
78+ static uint32_t magic_location [3 ] __attribute__((section (".noinit.double_tap" )));
79+
80+ #define NANO_RP2040_LED_PIN 6
81+
82+ int double_tap_check (void ) {
83+ if (magic_location [0 ] == magic_token [0 ] && magic_location [1 ] == magic_token [1 ] &&
84+ magic_location [2 ] == magic_token [2 ]) {
85+ magic_location [0 ] = 0 ;
86+ reset_usb_boot (1 << NANO_RP2040_LED_PIN , 0 );
87+ /* never returns */
88+ }
89+
90+ for (int i = 0 ; i < 3 ; i ++ ) {
91+ magic_location [i ] = magic_token [i ];
92+ }
93+
94+ k_busy_wait (500000 );
95+
96+ magic_location [0 ] = 0 ;
97+ return 0 ;
98+ }
99+
100+ SYS_INIT (double_tap_check , POST_KERNEL , 0 );
101+ #endif
102+
56103#if defined(CONFIG_INPUT )
57104#include <zephyr/kernel.h>
58105#include <zephyr/device.h>
0 commit comments