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