pico_unique_id

Unique device ID access API. More...

Data Structures

struct  pico_unique_board_id_t
 Unique board identifier. More...
 

Functions

void pico_get_unique_board_id (pico_unique_board_id_t *id_out)
 Get unique ID. More...
 
void pico_get_unique_board_id_string (char *id_out, uint len)
 Get unique ID in string format. More...
 

Detailed Description

Unique device ID access API.

RP2040 does not have an on-board unique identifier (all instances of RP2040 silicon are identical and have no persistent state). However, RP2040 boots from serial NOR flash devices which have a 64-bit unique ID as a standard feature, and there is a 1:1 association between RP2040 and flash, so this is suitable for use as a unique identifier for an RP2040-based board.

This library injects a call to the flash_get_unique_id function from the hardware_flash library, to run before main, and stores the result in a static location which can safely be accessed at any time via pico_get_unique_id().

This avoids some pitfalls of the hardware_flash API, which requires any flash-resident interrupt routines to be disabled when called into.

Function Documentation

◆ pico_get_unique_board_id()

void pico_get_unique_board_id ( pico_unique_board_id_t id_out)

Get unique ID.

Get the unique 64-bit device identifier which was retrieved from the external NOR flash device at boot.

On PICO_NO_FLASH builds the unique identifier is set to all 0xEE.

Parameters
id_outa pointer to a pico_unique_board_id_t struct, to which the identifier will be written

◆ pico_get_unique_board_id_string()

void pico_get_unique_board_id_string ( char *  id_out,
uint  len 
)

Get unique ID in string format.

Get the unique 64-bit device identifier which was retrieved from the external NOR flash device at boot, formatted as an ASCII hex string. Will always 0-terminate.

On PICO_NO_FLASH builds the unique identifier is set to all 0xEE.

Parameters
id_outa pointer to a char buffer of size len, to which the identifier will be written
lenthe size of id_out. For full serial, len >= 2 * PICO_UNIQUE_BOARD_ID_SIZE_BYTES + 1