Read RP2040 flash directly at XIP_BASE plus an offset
Read RP2040 flash with a plain pointer at XIP_BASE plus an offset, no driver call, on Pico SDK 2.1.0. The flash is memory mapped, so reads are free.
The RP2040 maps its external QSPI flash into the address space through the XIP (execute in place) unit, so reading stored data needs no driver at all. Pico SDK 2.1.0 defines XIP_BASE as 0x10000000, and a pointer cast at that address plus an offset reads the flash like any other array. The secret is that this is also how your running code is fetched, so a block at the start of the chip holds your program. Offsets you want for data should start after __flash_binary_end, or at the last sector.
#include <stdio.h>
#include "pico/stdlib.h"
#include "hardware/regs/addressmap.h"
int main(void) {
stdio_init_all();
const uint8_t *flash = (const uint8_t *)XIP_BASE;
const uint32_t offset = 0x100; // second 256-byte page
printf("%02x %02x %02x %02x\n",
flash[offset], flash[offset + 1], flash[offset + 2], flash[offset + 3]);
return 0;
}00 b5 04 4bThe four bytes depend on what your image holds at that offset; the line above is a sample. Reads go through the 16 KB XIP cache, which the RP2040 datasheet describes in the XIP section. Do not use this while a flash erase or program is running, because the flash leaves XIP mode during those operations and a read in that window faults or returns garbage. Writing needs flash_range_program with interrupts and the second core held off.