diff --git a/README.md b/README.md index 1c88458..d1231a8 100644 --- a/README.md +++ b/README.md @@ -158,7 +158,7 @@ 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. [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 App|Description diff --git a/system/CMakeLists.txt b/system/CMakeLists.txt index b11455b..05bc089 100644 --- a/system/CMakeLists.txt +++ b/system/CMakeLists.txt @@ -2,4 +2,5 @@ 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) endif () diff --git a/system/unique_board_id/CMakeLists.txt b/system/unique_board_id/CMakeLists.txt new file mode 100644 index 0000000..1a5b1f9 --- /dev/null +++ b/system/unique_board_id/CMakeLists.txt @@ -0,0 +1,14 @@ +add_executable(unique_board_id + unique_board_id.c + ) + +target_link_libraries(unique_board_id + pico_stdlib + pico_unique_id + ) + +# create map/bin/hex file etc. +pico_add_extra_outputs(unique_board_id) + +# add url via pico_set_program_url +example_auto_set_url(unique_board_id) diff --git a/system/unique_board_id/unique_board_id.c b/system/unique_board_id/unique_board_id.c new file mode 100644 index 0000000..6fb06c7 --- /dev/null +++ b/system/unique_board_id/unique_board_id.c @@ -0,0 +1,32 @@ +/** + * Copyright (c) 2021 Raspberry Pi (Trading) Ltd. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include + +#include "pico/stdlib.h" +#include "pico/unique_id.h" + +// RP2040 does not have a unique on-board ID, but this is a standard feature +// on the NOR flash it boots from. There is a 1:1 association between RP2040 +// and the flash, so this can be used to get a 64 bit globally unique board ID +// for an RP2040-based board, including Pico. +// +// The pico_unique_id library retrieves this unique identifier during boot and +// stores it in memory, where it can be accessed at any time without +// disturbing the flash XIP hardware. + +int main() { + stdio_init_all(); + + pico_unique_board_id_t board_id; + pico_get_unique_board_id(&board_id); + + printf("Unique identifier:"); + for (int i = 0; i < PICO_UNIQUE_BOARD_ID_SIZE_BYTES; ++i) { + printf(" %02x", board_id.id[i]); + } + printf("\n"); +}