metronome/rust/pm-grid/memory.x
Me Here 394ae65eaf pm-grid: USB Mass Storage (composite MIDI + 1MB flash-backed drive)
Adapt the usbd-storage rp2040 example into pm-grid as a composite MIDI+MSC
device:
- Host sees a 1MB removable drive backed by the upper 1MB of flash (a
  .filesystem region, NOLOAD so it stays out of the UF2 and survives reflashes).
- scsi_command handles the SCSI set (Inquiry / ReadCapacity10/16 /
  ReadFormatCapacities / Read / Write / ModeSense / RequestSense / TestUnitReady).
  Reads come from flash via raw pointer; writes accumulate a 4KB block then
  erase+program the sector with rp2040-flash (wrapped in interrupt::free).
- Host owns the FAT format (formats on first use). Unblocks on-device persistence.
- Composite poll: usb_dev.poll([&mut midi, &mut scsi]); scsi.poll services commands.

Build fixes required by adding rp2040-flash:
- rp2040-hal 0.10 -> 0.11 (0.10 + rp2040-flash 0.6 both export the __aeabi_*/
  __addsf3 ROM intrinsics -> duplicate symbols). No HAL API breakage.
- lto = false + codegen-units = 1 (fat-LTO tripped the same duplicate intrinsic).

UF2 stays ~257KB thanks to NOLOAD. defmt logs on block writes + unknown commands.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-03 16:25:51 -05:00

32 lines
1.2 KiB
Text

/* RP2040 (plain Raspberry Pi Pico) memory layout for rp2040-hal + cortex-m-rt.
The RP2040 boots from a 256-byte second-stage bootloader at the start of flash
(BOOT2), which then maps the rest of XIP flash and jumps to .text.
The 2 MB flash is split: 1 MB for the app, 1 MB for the USB Mass Storage
filesystem (a FAT volume the host reads/writes; written on-device via rp2040-flash). */
MEMORY {
BOOT2 : ORIGIN = 0x10000000, LENGTH = 0x100
FLASH : ORIGIN = 0x10000100, LENGTH = 0x100000 - 0x100
FILESYSTEM : ORIGIN = 0x10100000, LENGTH = 1M
RAM : ORIGIN = 0x20000000, LENGTH = 264K
}
EXTERN(BOOT2_FIRMWARE)
SECTIONS {
/* The second-stage bootloader blob (rp2040_boot2::BOOT_LOADER_W25Q080) lives here. */
.boot2 ORIGIN(BOOT2) :
{
KEEP(*(.boot2));
} > BOOT2
} INSERT BEFORE .text;
SECTIONS {
/* The Mass Storage filesystem region. NOLOAD: not part of the flashed image (so the UF2 stays
small and a reflash doesn't wipe the user's files) — the host formats it on first use, and
the device reads/writes it at runtime via raw-pointer reads + rp2040-flash erase/program. */
.filesystem (NOLOAD) : ALIGN(4096)
{
KEEP(*(.filesystem));
} > FILESYSTEM
} INSERT AFTER .text;