diff --git a/README.md b/README.md index d1231a8d6..240984835 100644 --- a/README.md +++ b/README.md @@ -156,7 +156,7 @@ App|Description App|Description ---|--- -[hello_double_tap](system/hello_double_tap) | On dev boards with a reset button (but no BOOTSEL), a magic number in RAM can be used to enter the USB bootloader, when the reset button is pressed twice quickly. +[hello_double_tap](system/hello_double_tap) | An LED blink with the `pico_bootsel_via_double_reset` library linked. This enters the USB bootloader when it detects the system being reset twice in quick succession, which is useful for boards with a reset button but no BOOTSEL button. [narrow_io_write](system/narrow_io_write) | Demonstrate the effects of 8-bit and 16-bit writes on a 32-bit IO register. [unique_board_id](system/unique_board_id) | Read the 64 bit unique ID from external flash, which serves as a unique identifier for the board. ### Timer diff --git a/system/CMakeLists.txt b/system/CMakeLists.txt index 05bc089f7..514c984c1 100644 --- a/system/CMakeLists.txt +++ b/system/CMakeLists.txt @@ -1,5 +1,4 @@ if (NOT PICO_NO_HARDWARE) - add_subdirectory(double_tap_usb_boot) add_subdirectory(narrow_io_write) add_subdirectory(hello_double_tap) add_subdirectory(unique_board_id) diff --git a/system/double_tap_usb_boot/CMakeLists.txt b/system/double_tap_usb_boot/CMakeLists.txt deleted file mode 100644 index 2d72a2743..000000000 --- a/system/double_tap_usb_boot/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -add_library(double_tap_usb_boot INTERFACE) - -# inclusion of this library will allow you to double tap reset within 100ms to launch into bootrom USB bootloader -if (PICO_ON_DEVICE) - target_sources(double_tap_usb_boot INTERFACE - ${CMAKE_CURRENT_LIST_DIR}/double_tap_usb_boot.c - ) - - target_link_libraries(double_tap_usb_boot INTERFACE - pico_bootrom - pico_time - ) -endif () \ No newline at end of file diff --git a/system/double_tap_usb_boot/double_tap_usb_boot.c b/system/double_tap_usb_boot/double_tap_usb_boot.c deleted file mode 100644 index 72afe7b6e..000000000 --- a/system/double_tap_usb_boot/double_tap_usb_boot.c +++ /dev/null @@ -1,36 +0,0 @@ -#include "pico.h" -#include "pico/time.h" -#include "pico/bootrom.h" - -// Allow user override of the LED mask -#ifndef USB_BOOT_LED_ACTIVITY_MASK -#define USB_BOOT_LED_ACTIVITY_MASK 0 -#endif - -// Doesn't make any sense for a RAM only binary -#if !PICO_NO_FLASH -static const uint32_t magic_token[] = { - 0xf01681de, 0xbd729b29, 0xd359be7a, -}; - -static uint32_t __uninitialized_ram(magic_location)[count_of(magic_token)]; - -// run at initialization time -static void __attribute__((constructor)) boot_double_tap_check() { - for (uint i = 0; i < count_of(magic_token); i++) { - if (magic_location[i] != magic_token[i]) { - // Arm for 100 ms then disarm and continue booting - for (i = 0; i < count_of(magic_token); i++) { - magic_location[i] = magic_token[i]; - } - busy_wait_us(100000); - magic_location[0] = 0; - return; - } - } - - magic_location[0] = 0; - reset_usb_boot(USB_BOOT_LED_ACTIVITY_MASK, 0); -} - -#endif \ No newline at end of file diff --git a/system/hello_double_tap/CMakeLists.txt b/system/hello_double_tap/CMakeLists.txt index a4344aeb9..30a9e12f7 100644 --- a/system/hello_double_tap/CMakeLists.txt +++ b/system/hello_double_tap/CMakeLists.txt @@ -2,12 +2,19 @@ add_executable(hello_double_tap hello_double_tap.c ) -# Double tap reset into bootrom is injected by linking with the double_tap_usb_boot library +# Double tap reset into bootrom is injected by linking with the +# pico_bootsel_via_double_reset library target_link_libraries(hello_double_tap pico_stdlib - double_tap_usb_boot + pico_bootsel_via_double_reset ) +# Entering the bootloader in this way also lets us specify a GPIO to be used +# as a bootloader activity LED: +target_compile_definitions(hello_double_tap PRIVATE + PICO_BOOTSEL_VIA_DOUBLE_RESET_ACTIVITY_LED=25 + ) + pico_add_extra_outputs(hello_double_tap) # add url via pico_set_program_url diff --git a/system/hello_double_tap/hello_double_tap.c b/system/hello_double_tap/hello_double_tap.c index 6d0ba7fdb..e64e8ae99 100644 --- a/system/hello_double_tap/hello_double_tap.c +++ b/system/hello_double_tap/hello_double_tap.c @@ -6,10 +6,14 @@ #include "pico/stdlib.h" -// This is a regular old LED blinking example, however it is linked with double_tap_usb_boot -// so pressing reset quickly twice, will reset into USB bootloader +// This is a regular old LED blinking example, however it is linked with the +// `pico_bootsel_via_double_reset` library, so resetting the board twice +// quickly will enter the USB bootloader. This is useful for boards which have +// a reset button but no BOOTSEL, as long as you remember to always link the +// `pico_bootsel_via_double_reset` library! + int main() { - const uint LED_PIN = 21; + const uint LED_PIN = PICO_DEFAULT_LED_PIN; gpio_init(LED_PIN); gpio_set_dir(LED_PIN, GPIO_OUT); while (true) {