Skip to content

Commit e3779f5

Browse files
committed
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 mess about with flash, e.g. for flash nuke or something that uses the unique flash id. Add PICO_INCLUDE_FLASH_UTILS which forces some flash functions to be included.
1 parent a76f241 commit e3779f5

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

src/rp2_common/hardware_flash/flash.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ void __no_inline_not_in_flash_func(flash_range_program)(uint32_t flash_offs, con
248248
//-----------------------------------------------------------------------------
249249
// Lower-level flash access functions
250250

251-
#if !PICO_NO_FLASH
251+
#if !PICO_NO_FLASH || PICO_INCLUDE_FLASH_UTILS
252252
// Bitbanging the chip select using IO overrides, in case RAM-resident IRQs
253253
// are still running, and the FIFO bottoms out. (the bootrom does the same)
254254
static void __no_inline_not_in_flash_func(flash_cs_force)(bool high) {
@@ -334,7 +334,7 @@ void __no_inline_not_in_flash_func(flash_do_cmd)(const uint8_t *txbuf, uint8_t *
334334
static_assert(FLASH_UNIQUE_ID_SIZE_BYTES == FLASH_RUID_DATA_BYTES, "");
335335

336336
void flash_get_unique_id(uint8_t *id_out) {
337-
#if PICO_NO_FLASH
337+
#if PICO_NO_FLASH && !PICO_INCLUDE_FLASH_UTILS
338338
__unused uint8_t *ignore = id_out;
339339
panic_unsupported();
340340
#else

src/rp2_common/hardware_flash/include/hardware/flash.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@
5252

5353
// PICO_CONFIG: PICO_FLASH_SIZE_BYTES, size of primary flash in bytes, type=int, default=Usually provided via board header, group=hardware_flash
5454

55+
// PICO_CONFIG: PICO_INCLUDE_FLASH_UTILS, Force inclusion of flash functions in PICO_NO_FLASH binaries. Has no effect in flash binaries, type=bool, default=false, group=hardware_flash
56+
#ifndef PICO_INCLUDE_FLASH_UTILS
57+
#define PICO_INCLUDE_FLASH_UTILS 0
58+
#endif
59+
5560
#ifdef __cplusplus
5661
extern "C" {
5762
#endif

src/rp2_common/pico_unique_id/unique_id.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ static pico_unique_board_id_t retrieved_id;
2020

2121
static void __attribute__((PICO_UNIQUE_BOARD_ID_INIT_ATTRIBUTES)) _retrieve_unique_id_on_boot(void) {
2222
#if PICO_RP2040
23-
#if PICO_NO_FLASH
23+
#if PICO_NO_FLASH && !PICO_INCLUDE_FLASH_UTILS
2424
// The hardware_flash call will panic() if called directly on a NO_FLASH
2525
// build. Since this constructor is pre-main it would be annoying to
2626
// debug, so just produce something well-defined and obviously wrong.

0 commit comments

Comments
 (0)