Today I'm running 4 tests on each of the 7 boards. Just to quickly document how I'm actually testing, these are the 4 programs:
MPU size test, code below
PSRAM memtest
Fault timing, msg #16
Preload instruction, msg #37 - slightly modified, code...
Here are the measurements you asked for, all on the same board: Teensy 4.1, 2 x APS6404L (8 MB + 8 MB = 16 MB), core 1.62.0 with your startup.c v2 installed (at boot FLSHA1CR0=0x2000, FLSHA2CR0=0x8000, MPU region 0x70000000 = 32 MB). F_CPU 720...
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...
After you've done plenty of testing with it as-is, please try deleting these last 6 lines from configure_external_ram(), so we can get some measurement of fix #2 without fix #1.
asm("dsb");
SCB_MPU_CTRL = 0;
SCB_MPU_RBAR...
Tested your new startup.c on core 1.62.0 (Teensy 4.1, 2 x 8 MB APS6404L = 16 MB, 720 MHz). No mpu_fix.h or any other workaround in the sketches.
Register state after boot (printed by the test sketch)
PSRAM 16 MB, FLSHA1CR0=0x2000 (8 MB)...
I ran jmarsh's alternating PLD test on my board (Teensy 4.1, 2 x 8 MB APS6404L = 16 MB, core 1.62.0, 720 MHz). It reproduces the 2^30-cycle stall with the stock core, and the three fixes remove it. The MPU variant does not fault.
Test
jmarsh's...
I think there is a misunderstanding, and I may have caused it with the sentence about faulting. Let me separate the two cases:
My large application, with the MPU region resized to 16 MB: NO faults at all. Two overnight runs (12 h 9 min and 8 h...
Understood, and thanks for doing something for 1.63. To separate what is certain from what is not:
Certain and reproducible in two minutes on any board with less than 32 MB PSRAM: a direct read behind the PSRAM stalls 2^28 cycles and BusFaults...
Thanks, that clarifies it. I agree the root cause is an MPU region larger than the installed memory. For sizes that are not a power of two (e.g. 24 MB) I use a 32 MB region with the upper sub-regions disabled (SRD); this is only tested for 16 MB...
Yes, those three are a fair summary, with one correction on #3: it is not an issue in practice, and I have data for that.
1. Correct. This is the case I hit: two PSRAM chips on A1/A2 (8 + 8 MB), the MPU region is 32 MB, so everything above A1 +...
I agree the "value in a register" explanation is not proven, and I could not reproduce speculation with a small program (mispredicted branch trained 200 times, worst case 14 cycles). What I can offer is what my logger data say about the "how far"...
Thanks, that makes sense. On my board both chips are PSRAM, so leaving A2CR0 at 64 MB works there (results above). For a flash on chip 2 where PSRAM + flash is below 32 MB, LittleFS rewriting A2CR0 would bring the hole back, so resizing the MPU...
Tested: leaving FLEXSPI2_FLSHA2CR0 at its 64 MB reset default works on my board (2 x APS6404L = 16 MB).
Method
Same test as before (sts1_test, stock core, MPU region still 32 MB). The core has already written FLSHA2CR0 = size2 << 10 (0x2000 = 8...
This actually makes me realize there may be a simple fix for this after all: just set FLEXSPI2_FLSHA2CR0 to 32MB, always.
- no PSRAM: no real change to what the current code does (leaves FLSHA1CR0 and FLSHA2CR0 at default values)
- 1x 8MB PSRAM...
Before I consider a simple fix to be merged into the official core library, given all this new info is there a reliable way to reproduce this problem? Can it be done with a relatively small program not depending on many libraries and external...
Paul, yes: a small reproduction exists. It needs only a Teensy 4.1 with less than 32 MB of PSRAM fitted, no libraries and no other hardware (attached below, about 40 lines). It reads 8 words behind the end of the PSRAM and times each read...
Good point about 24 MB (16 MB + 8 MB chips). An MPU region must be a power of two, so 24 MB can not be described exactly by one region. Two ways: a 32 MB region with the subregion-disable bits (SRD) set for the top 8 MB (32 MB / 8 = 4 MB per...
SEQTIMEOUT is bit 11 (not set), AHBBUSTIMEOUT is bit 10 (is set).
The max AHB burst size is 64 bits and the memory is marked cached so any speculative access should trigger 4x AHB bursts to fill a 256 bit cacheline. I can't explain why a...
Follow-up: corrections, the complete fix and the full reproduction
Thanks jmarsh, you are right about the INTR bits (AHBBUSTIMEOUT is bit 10 and it is the one that is set, SEQTIMEOUT is bit 11 and not set; I took the bit order from a generated...
Thanks Paul, and thanks jmarsh who explained the B1 behaviour. I ran a minimal reproduction on the stock core 1.62.0 (Teensy 4.1, 720 MHz, 2x APS6404L = 16 MB, psram=16MB detected). It reads the first address behind the PSRAM (0x70000000 + 16 MB)...
I doubt that would have any effect. The speculative accesses are causing FlexSPI to access the non-present B1 device (because the memory address is beyond the combined sizes of A1 and A2 as set in their CR0 registers). The B1 and B2 control...
Looking at the startup code I see the reason for this - when only one chip is present, the FLEXSPI2_FLSHA2CR0 register is never touched and keeps its default value (64MB). So in that case FlexSPI doesn't think the memory is "unbacked" and never...
Thanks. A string starting with 'q' (0x71) near a FLASHMEM function is a good thought, but in my case the stall windows line up with micros() being in 0x71000000..0x71FFFFFF (period 2^32 us = 4295 s), so I think the register is what triggers it. A...
Found it: it is the same speculative-read problem, and in my case the trigger is micros()
Thanks to everyone, in particular to the thread by SamiH (the AHBBUSWAIT explanation: 0xFFFF x 1024 cycles x 16 = 2^30 cycles) which made me look at the...
Thanks, and thanks for the pointers to the other two threads. I will test the same fix (resizing the region at startup, in my case from startup_middle_hook so I do not have to touch the core).
The instruction at the stalled PC...
It most likely is the PSRAM MPU region size. The trick is that it's being caused by speculative execution (rather than any actual memory read in your code), which can behave very unpredictably even between the same program runs.
Not quite sure...
Another test, and I have to take back my last conclusion
I repeated the test with the same build as in my previous post (10.153, stock SIZE_32M, MPU read-back at boot shows region 9 = 70000000/24, same compiled sketch, only a normal restart in...
Update: the MPU region size is not the cause.
I ran the same sketch object (the sketch was not recompiled, only the core) with the stock SIZE_32M and with SIZE_16M for the FlexSPI2 region. I confirmed the active setting by reading the MPU back...
Summary
I see a periodic stall of the whole CPU of exactly 2^30 CPU cycles (1491 ms at 720 MHz, 1790 ms at 600 MHz). It looks the same as the freeze in the 2021 thread "Teensy 4.1 Freeze (~1786ms)" by UdoZ (Paul: 2^28 IPG cycles), but I am on...