I agree, I don’t see a normal case where the MPU is disabled. The case I had in mind is code that reprograms MPU region 9 (a library or a sketch that widens it again or reuses the slot), where the FLSHA2CR0 coverage would be the only protection left. I’m testing fix #2 on its own only to get that measurement, by widening the region to 32 MB in a sketch, not because I expect the MPU to be off.Under what situation would the MPU be disabled? I think that would break all sorts of things.
row MPU A1+A2 (CR0) unbacked address result
1 32 MB 8 + 32 = 40 MB 0x71C00000 (28 MB) clean, INTR 0x40, worst PLD < 1000 cycles
2 64 MB 8 + 32 = 40 MB 0x72800000 (40 MB) STALL: 1.491 s, then 2.983 s per cache line, INTR 0x440
3 128 MB 8 + 32 = 40 MB 0x73000000 (48 MB) STALL: same 1.491 s / 2.983 s pattern, INTR 0x440
4 32 MB 8 + 24 = 32 MB 0x71C00000 (28 MB) clean, FLSHA2CR0=0x6000, INTR 0x40
5 32 MB 8 + 23 = 31 MB 0x71F00000 (31 MB) STALL: 1.491 s, then 2.983 s per cache line, INTR 0x440
extern "C" uint8_t external_psram_size;
void setup() {
Serial.begin(9600);
Serial.println("PSRAM settings");
Serial.printf("external_psram_size = %u\n", external_psram_size);
uint32_t a1 = FLEXSPI2_FLSHA1CR0;
uint32_t a2 = FLEXSPI2_FLSHA2CR0;
Serial.printf("A1 size = %04X (%uMB)\n", a1, a1 >> 10);
Serial.printf("A2 size = %04X (%uMB)\n", a2, a2 >> 10);
SCB_MPU_RNR = 9;
uint32_t rbar = SCB_MPU_RBAR;
uint32_t rasr = SCB_MPU_RASR;
Serial.printf("MPU: addr:%x, config:%x", rbar & 0xFFFFFFE0, rasr);
//uint32_t bytes = 2 << ((rasr >> 1) & 0x1E);
//Serial.printf(" (%u bytes)\n", bytes);
Serial.printf(" (%s)\n", mpu_size(rasr));
for (uint32_t addr = 0; addr <= 32; addr += 1) {
volatile uint32_t *ptr = (uint32_t *)(0x70000000 + addr * 1024 * 1024);
Serial.printf(" write at %uMB...", addr);
delay(250);
*ptr = 0;
delay(50);
Serial.println("OK");
}
}
const char *mpu_size(uint32_t r) {
if ((r & 1) == 0) return "disabled";
r &= 0xFF3E;
if (r == SCB_MPU_RASR_SIZE(22)) return "8MB";
if (r == SCB_MPU_RASR_SIZE(23)) return "16MB";
if (r == (SCB_MPU_RASR_SIZE(23) & SCB_MPU_RASR_SRD(0xC0))) return "24MB";
if (r == SCB_MPU_RASR_SIZE(24)) return "32MB";
return "unknown";
}
void loop() {
}
// Should blink at 1 Hz
// blinks every 3.58 second if preload instruction causes FlexIO stall
// from thread 78171 msg #37
// https://forum.pjrc.com/index.php?threads/78171/post-370932
elapsedMillis ticker;
uint32_t addr;
extern "C" uint8_t external_psram_size;
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
digitalWriteFast(LED_BUILTIN, LOW);
addr = 0x70000000 + external_psram_size * 1024 * 1024;
}
void loop() {
static uint16_t offset;
if (ticker > 500) {
digitalToggle(LED_BUILTIN);
ticker = 0;
}
asm volatile("pld [%0, %1]" :: "r"(addr), "r"(offset));
++offset;
}
Board MPU Memtest Fault Timing Preload
----- --- ------- ------------ -------
None + flash 0MB none 112 cycles 1 Hz
8MB + flash 8MB pass 112 cycles 1 Hz
8MB + 8MB 16MB pass 112 cycles 1 Hz
16MB + flash 16MB pass 112 cycles 1 Hz
8MB + 16MB 24MB pass 112 cycles 1 Hz
16MB + 8MB 24MB pass 112 cycles 1 Hz
16MB + 16MB 32MB pass 112 cycles 1 Hz