From c80edf7cf91b5a9aca16ef2e467a8124ecaa2a70 Mon Sep 17 00:00:00 2001
From: Oliver Schmidt
Date: Sun, 25 Oct 2026 18:25:00 +0100
Subject: [PATCH] Apply SDK PR#3017
This code is frequently used as a template. It therefore seems desirable to keep it up to date. See https://github.com/raspberrypi/pico-sdk/pull/3017
---
flash/program/flash_program.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/flash/program/flash_program.c b/flash/program/flash_program.c
index 69a0f4d2e..b7dc7a220 100644
--- a/flash/program/flash_program.c
+++ b/flash/program/flash_program.c
@@ -11,11 +11,17 @@
#include "pico/flash.h"
#include "hardware/flash.h"
+#if PICO_RP2040
+#define FLASH_TARGET_BASE XIP_BASE
+#else
+#define FLASH_TARGET_BASE XIP_NOCACHE_NOALLOC_NOTRANSLATE_BASE
+#endif
+
// We're going to erase and reprogram a region 256k from the start of flash.
-// Once done, we can access this at XIP_BASE + 256k.
+// Once done, we can access this at FLASH_TARGET_BASE + 256k.
#define FLASH_TARGET_OFFSET (256 * 1024)
-const uint8_t *flash_target_contents = (const uint8_t *) (XIP_BASE + FLASH_TARGET_OFFSET);
+const uint8_t *flash_target_contents = (const uint8_t *) (FLASH_TARGET_BASE + FLASH_TARGET_OFFSET);
void print_buf(const uint8_t *buf, size_t len) {
for (size_t i = 0; i < len; ++i) {