From 24869d5350786628a5661a2afc2c4ca45e7bd2a5 Mon Sep 17 00:00:00 2001 From: Peter Harper Date: Fri, 12 Dec 2025 12:58:51 +0000 Subject: [PATCH 1/2] Flash functions in PICO_NO_FLASH binaries We assume that PICO_NO_FLASH binaries means the device does not have a flash chip. But it's possible that you want a ram binary AND want to use the unique flash id functionality. Add PICO_INCLUDE_FLASH_ID_FUNCTIONS to force the inclusion of these flash functions in ram binaries. Fixes #2796 --- src/rp2_common/hardware_flash/flash.c | 2 +- src/rp2_common/hardware_flash/include/hardware/flash.h | 5 +++++ src/rp2_common/pico_unique_id/unique_id.c | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/rp2_common/hardware_flash/flash.c b/src/rp2_common/hardware_flash/flash.c index b5426f39a..3fbd61177 100644 --- a/src/rp2_common/hardware_flash/flash.c +++ b/src/rp2_common/hardware_flash/flash.c @@ -354,7 +354,7 @@ void __no_inline_not_in_flash_func(flash_do_cmd_cs)(const uint8_t *txbuf, uint8_ static_assert(FLASH_UNIQUE_ID_SIZE_BYTES == FLASH_RUID_DATA_BYTES, ""); void flash_get_unique_id(uint8_t *id_out) { -#if PICO_NO_FLASH +#if PICO_NO_FLASH && !PICO_INCLUDE_FLASH_ID_FUNCTIONS __unused uint8_t *ignore = id_out; panic_unsupported(); #else diff --git a/src/rp2_common/hardware_flash/include/hardware/flash.h b/src/rp2_common/hardware_flash/include/hardware/flash.h index 0c5b27a6c..05057bab5 100644 --- a/src/rp2_common/hardware_flash/include/hardware/flash.h +++ b/src/rp2_common/hardware_flash/include/hardware/flash.h @@ -52,6 +52,11 @@ // PICO_CONFIG: PICO_FLASH_SIZE_BYTES, size of primary flash in bytes, type=int, default=Usually provided via board header, group=hardware_flash +// PICO_CONFIG: PICO_INCLUDE_FLASH_ID_FUNCTIONS, Force inclusion of flash unique id functionality in PICO_NO_FLASH binaries, type=bool, default=0, group=hardware_flash +#ifndef PICO_INCLUDE_FLASH_ID_FUNCTIONS +#define PICO_INCLUDE_FLASH_ID_FUNCTIONS 0 +#endif + #ifdef __cplusplus extern "C" { #endif diff --git a/src/rp2_common/pico_unique_id/unique_id.c b/src/rp2_common/pico_unique_id/unique_id.c index 28204eda0..d186061da 100644 --- a/src/rp2_common/pico_unique_id/unique_id.c +++ b/src/rp2_common/pico_unique_id/unique_id.c @@ -20,7 +20,7 @@ static pico_unique_board_id_t retrieved_id; static void __attribute__((PICO_UNIQUE_BOARD_ID_INIT_ATTRIBUTES)) _retrieve_unique_id_on_boot(void) { #if PICO_RP2040 - #if PICO_NO_FLASH + #if PICO_NO_FLASH && !PICO_INCLUDE_FLASH_ID_FUNCTIONS // The hardware_flash call will panic() if called directly on a NO_FLASH // build. Since this constructor is pre-main it would be annoying to // debug, so just produce something well-defined and obviously wrong. From e763d624c531804d53e2423967435aa55e9c0442 Mon Sep 17 00:00:00 2001 From: Peter Harper Date: Mon, 22 Jun 2026 16:48:28 +0100 Subject: [PATCH 2/2] Change the name of the config To PICO_ALWAYS_INCLUDE_FLASH_ID_FUNCTIONS. --- src/rp2_common/hardware_flash/flash.c | 2 +- src/rp2_common/hardware_flash/include/hardware/flash.h | 6 +++--- src/rp2_common/pico_unique_id/unique_id.c | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/rp2_common/hardware_flash/flash.c b/src/rp2_common/hardware_flash/flash.c index 3fbd61177..2258f5143 100644 --- a/src/rp2_common/hardware_flash/flash.c +++ b/src/rp2_common/hardware_flash/flash.c @@ -354,7 +354,7 @@ void __no_inline_not_in_flash_func(flash_do_cmd_cs)(const uint8_t *txbuf, uint8_ static_assert(FLASH_UNIQUE_ID_SIZE_BYTES == FLASH_RUID_DATA_BYTES, ""); void flash_get_unique_id(uint8_t *id_out) { -#if PICO_NO_FLASH && !PICO_INCLUDE_FLASH_ID_FUNCTIONS +#if PICO_NO_FLASH && !PICO_ALWAYS_INCLUDE_FLASH_ID_FUNCTIONS __unused uint8_t *ignore = id_out; panic_unsupported(); #else diff --git a/src/rp2_common/hardware_flash/include/hardware/flash.h b/src/rp2_common/hardware_flash/include/hardware/flash.h index 05057bab5..137ab9f52 100644 --- a/src/rp2_common/hardware_flash/include/hardware/flash.h +++ b/src/rp2_common/hardware_flash/include/hardware/flash.h @@ -52,9 +52,9 @@ // PICO_CONFIG: PICO_FLASH_SIZE_BYTES, size of primary flash in bytes, type=int, default=Usually provided via board header, group=hardware_flash -// PICO_CONFIG: PICO_INCLUDE_FLASH_ID_FUNCTIONS, Force inclusion of flash unique id functionality in PICO_NO_FLASH binaries, type=bool, default=0, group=hardware_flash -#ifndef PICO_INCLUDE_FLASH_ID_FUNCTIONS -#define PICO_INCLUDE_FLASH_ID_FUNCTIONS 0 +// PICO_CONFIG: PICO_ALWAYS_INCLUDE_FLASH_ID_FUNCTIONS, Force inclusion of flash unique id functionality in PICO_NO_FLASH binaries, type=bool, default=0, group=hardware_flash +#ifndef PICO_ALWAYS_INCLUDE_FLASH_ID_FUNCTIONS +#define PICO_ALWAYS_INCLUDE_FLASH_ID_FUNCTIONS 0 #endif #ifdef __cplusplus diff --git a/src/rp2_common/pico_unique_id/unique_id.c b/src/rp2_common/pico_unique_id/unique_id.c index d186061da..11b921cea 100644 --- a/src/rp2_common/pico_unique_id/unique_id.c +++ b/src/rp2_common/pico_unique_id/unique_id.c @@ -20,7 +20,7 @@ static pico_unique_board_id_t retrieved_id; static void __attribute__((PICO_UNIQUE_BOARD_ID_INIT_ATTRIBUTES)) _retrieve_unique_id_on_boot(void) { #if PICO_RP2040 - #if PICO_NO_FLASH && !PICO_INCLUDE_FLASH_ID_FUNCTIONS + #if PICO_NO_FLASH && !PICO_ALWAYS_INCLUDE_FLASH_ID_FUNCTIONS // The hardware_flash call will panic() if called directly on a NO_FLASH // build. Since this constructor is pre-main it would be annoying to // debug, so just produce something well-defined and obviously wrong.