Skip to content

Commit 7b4ee3f

Browse files
committed
fix(rp2040): XIP flashes aliases (noalloc / nocache)
close #139
1 parent 9375d52 commit 7b4ee3f

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/rp2040.ts

+9-5
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import { RPSIO } from './sio.js';
2929
import { ConsoleLogger, LogLevel, Logger } from './utils/logging.js';
3030

3131
export const FLASH_START_ADDRESS = 0x10000000;
32+
export const FLASH_END_ADDRESS = 0x14000000;
3233
export const RAM_START_ADDRESS = 0x20000000;
3334
export const APB_START_ADDRESS = 0x40000000;
3435
export const DPRAM_START_ADDRESS = 0x50100000;
@@ -208,11 +209,14 @@ export class RP2040 {
208209
const { bootrom } = this;
209210
if (address < bootrom.length * 4) {
210211
return bootrom[address / 4];
211-
} else if (
212-
address >= FLASH_START_ADDRESS &&
213-
address < FLASH_START_ADDRESS + this.flash.length
214-
) {
215-
return this.flashView.getUint32(address - FLASH_START_ADDRESS, true);
212+
} else if (address >= FLASH_START_ADDRESS && address < FLASH_END_ADDRESS) {
213+
// Flash is mirrored four times:
214+
// - 0x10000000 XIP
215+
// - 0x11000000 XIP_NOALLOC
216+
// - 0x12000000 XIP_NOCACHE
217+
// - 0x13000000 XIP_NOCACHE_NOALLOC
218+
const offset = address & 0x00ff_ffff;
219+
return this.flashView.getUint32(offset, true);
216220
} else if (address >= RAM_START_ADDRESS && address < RAM_START_ADDRESS + this.sram.length) {
217221
return this.sramView.getUint32(address - RAM_START_ADDRESS, true);
218222
} else if (

0 commit comments

Comments
 (0)