Tutorials

Budget a Flash Log on the Original Pico Without Overlapping Firmware

Published · Updated

A 2 MiB board flash is not a 2 MiB log partition. Boot code, the linked firmware image and any settings share that part. Define the address range first and work out how much history fits afterward.

Reserve an erase-aligned region in the linker layout

Component side of the original Raspberry Pi Pico. U1 contains the RP2040 peripherals discussed in this example.
Component side of the original Raspberry Pi Pico. U1 contains the RP2040 peripherals discussed in this example. Phiarc, Raspberry Pi Pico top (Wikimedia Commons), CC BY-SA 4.0. WebP adaptation.

For an original Pico with its documented 2 MiB device, suppose a project reserves the top 128 KiB for a diagnostic log. The start offset relative to flash is then 0x1E0000, with 0x200000 as the exclusive end. Enforce the boundary in the build and check the map for the release image.

The SDK flash interface uses sector-aligned erase ranges and page-aligned program operations. RP2040 executes ordinary firmware from external flash through XIP, so follow the SDK’s multicore and interrupt rules around flash operations.

Check flash offsets against a memory map · Review the image release checklist

Derive retention from the record format actually written

One program page / 256 bytes / 8 × 32-byte records; One erase sector / 4 KiB / 128 records; Reserved region / 128 KiB / 4,096 records before overhead
Layout item / Example value / Capacity.

Using 32-byte records gives eight records per 256-byte page and 128 records per 4 KiB sector. An ideal 128 KiB region holds 4,096 records. At one record every ten seconds, that is about 11 hours 23 minutes before reuse.

Headers, commit markers, spare sectors and bad or interrupted records reduce it. Exercise recovery on expendable test data by interrupting a write and verifying that the scanner can locate the last complete record without accepting a partial one.

What should block the release build?

Reject any image whose linked flash content overlaps the log start. Confirm the board's fitted flash capacity and test recovery with the production record format before using its retention estimate.

Read the example one step at a timeOne program page / 256 bytes / 8 × 32-byte records; One erase sector / 4 KiB / 128 records; Reserved region / 128 KiB / 4,096 records before overhead
  1. One program page · 256 bytes · 8 × 32-byte records
  2. One erase sector · 4 KiB · 128 records
  3. Reserved region · 128 KiB · 4,096 records before overhead

Bound queue growth during a storage stall · Check the storage allocation

Compare ring and ping-pong buffering.

Raspberry Pi Pico SDK 2.2.0, flash programming API.

Photograph credit and licence

Phiarc, Raspberry Pi Pico top (Wikimedia Commons), CC BY-SA 4.0. WebP adaptation.

Original photograph https://commons.wikimedia.org/wiki/File:Raspberry_Pi_Pico_top.jpg

Licence https://creativecommons.org/licenses/by-sa/4.0/

Back to Tutorials

Related evidence and next tasks

Continue the task with the relevant source scope. These reading paths do not establish interchangeability or current supply.

Source addresses and citation trail

Full source addresses are retained below. Read each citation with its document revision, page, table and applicability conditions above.

  1. https://github.com/raspberrypi/pico-sdk/blob/2.2.0/src/rp2_common/hardware_flash/include/hardware/flash.h