Marmes
Member
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 core 1.62.0 where the overlapping FlexSPI2 MPU regions are long fixed. The stall is deterministic for a given binary, but different builds of nearly identical source behave completely differently: some run for hours without a single stall, some stall reproducibly at the same uptime. I can mitigate it but I have not found the cause. I would be grateful for any idea what can block a Cortex-M7 for exactly 2^30 cycles.
Hardware / software
Symptom
What the hardware does during the stall
I attached a high priority GPT2 interrupt (priority 0) as a probe. During a stall, the interrupt that is executing is the LPUART6 interrupt (IPSR = 41), and the PC sits in HardwareSerialIMXRT::IRQHandler on a strb into the receive buffer in DMAMEM (RAM2). The UART interrupt rate drops from about 46000/s to 2000-8000/s, i.e. each byte store into the RAM2 buffer takes roughly 100-300 microseconds. It looks like memory accesses through the cache/AXI path become extremely slow, rather than the CPU sitting in a loop.
It depends on the binary
What I tried
MPU
I read the MPU regions back from the running sketch (region, base address, SIZE field):
There is only one FlexSPI2 region, so the old overlapping 256M READONLY region is gone. The stock 1.62.0 startup.c uses SIZE_32M for 0x70000000 (r9, SIZE field 24); I assume it was raised from 16M to cover two 16 MB PSRAM chips. In the old thread Frank B reported (post #137) that a single FlexSPI2 region larger than 16M still froze. With my 16 MB of PSRAM that leaves 16 MB of cacheable read/write address space with nothing behind it.
I tested both: with SIZE_16M (r9 = 70000000/23) the build ran 6329 s without a stall. With SIZE_32M (the stock value) the same sketch object (only the core was recompiled) has passed the 1886 s mark so far without a stall; that run is still going. So I cannot show that the region size is the cause. I will update this post when the 103 minute mark has passed.
Questions
I can supply the full diagnostic log files (one row every 5 s, with the raw bad frames) and the sketch. It is large, so I have no minimal sketch yet, but the behaviour is reproducible per binary at the same uptime.
Thanks!
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 core 1.62.0 where the overlapping FlexSPI2 MPU regions are long fixed. The stall is deterministic for a given binary, but different builds of nearly identical source behave completely differently: some run for hours without a single stall, some stall reproducibly at the same uptime. I can mitigate it but I have not found the cause. I would be grateful for any idea what can block a Cortex-M7 for exactly 2^30 cycles.
Hardware / software
- Teensy 4.1, 720 MHz (also seen at 600 MHz), -O2, USB Type "Serial", Arduino IDE 2, "Teensy (for Arduino IDE 2.0.4 or later)" package 1.62.0
- PSRAM: 2x APS6404L (8 MB each), hand-soldered, 16 MB in total. The core detects psram=16MB and a memory test over the full 16 MB gives 0 errors
- u-blox ZED-F9P on Serial1 (LPUART6) at 921600 baud. At 5 Hz: RAWX + SFRBX + NAV-PVT + NAV-SAT + NMEA, about 30 KB/s. At 1 Hz about 6 KB/s
- Built-in microSD (SD library bundled with Teensyduino), HX8357D TFT on SPI, resistive touch. The sketch is about 6000 lines
- GPS RX: 32 KB hardware serial buffer, an IntervalTimer (5 ms, priority 144) drains it into a 1 MB ring buffer in PSRAM (EXTMEM). The main loop parses from the ring and writes to SD. A second small buffer lives in DMAMEM (RAM2)
Symptom
- All CPU activity stops for exactly 2^30 cycles: main loop, IntervalTimer, GPS parsing. The serial buffer overflows and the log contains garbage frames. millis()/micros() keep correct time afterwards. I measure it with DWT_CYCCNT in an ISR (isr=1491 ms)
- In affected builds it starts at about 1886 s uptime, as a series of several events a few seconds apart, and again at about 6183 s and 10476 s. The 4295 s spacing is suspiciously close to 2^32 microseconds
- Also happens with no SD card inserted, so SD and SdFat are not the cause (I tried the Adafruit SdFat fork, SdFat 2.3.0 and the bundled one)
- UART error counters (framing/noise) stay at 0 for the whole run; the overrun flag only shows up after the stall
What the hardware does during the stall
I attached a high priority GPT2 interrupt (priority 0) as a probe. During a stall, the interrupt that is executing is the LPUART6 interrupt (IPSR = 41), and the PC sits in HardwareSerialIMXRT::IRQHandler on a strb into the receive buffer in DMAMEM (RAM2). The UART interrupt rate drops from about 46000/s to 2000-8000/s, i.e. each byte store into the RAM2 buffer takes roughly 100-300 microseconds. It looks like memory accesses through the cache/AXI path become extremely slow, rather than the CPU sitting in a loop.
It depends on the binary
- Version 10.133 built on Oct 24 22:21: ran 8314 s and 1920 s with no stall at all (isr max 5 ms). It passed the 1886 s and 6181 s marks
- The same version number, rebuilt on Oct 25 11:11: stalls at 1885 s every time (isr = 1491 ms, 18-30 bad frames per run)
- An older build (10.89, 600 MHz): 12510 s with no stall
- The current build (10.153) has now run 6329 s at 5 Hz with the full load and touch input with no stall, passing both the 1886 s and 6181 s marks (isr max 5 ms, GPT2 probe gap constant 62 ms)
- Adding unrelated diagnostics changes the behaviour. This matches the old thread, where one extra character in a Serial.println made the freeze vanish
What I tried
- Without SD card, with different SD libraries, re-formatted card: no change
- Without PSRAM (ring buffers in the heap): worse, a stall every 6.3 s and finally a complete hang. So PSRAM is not simply the culprit
- USB Type "Serial" vs "Serial + MTP": MTP with a PC cable gives separate 1.8 s stalls (a different problem, avoided). The stall described here also happens with USB Type "Serial"
- Wiring: UART error counters stay 0; re-wired and soldered, no difference
- The probe (GPT2 priority 0, 62.5 ms tick, an arm_dcache_flush_delete of one RAM2 line on each tick, CCM_CCGR0 bits set, GPT2 reset) mitigates it (0-7 bad frames in a 6389 s run) but does not remove it: at one event (6185 s) the probe saw a 1428 ms hole in its own ticks while a lower priority timer slipped only 27 ms
- Module output rate: with the receiver set to 1 Hz the first mark passed. With the build dependency above I do not trust this as proof
MPU
I read the MPU regions back from the running sketch (region, base address, SIZE field):
Code:
r0=0/31 r1=0/18 r2=0/4 r3=200000/16 r4=20000000/18 r5=2002F8A0/4
r6=20200000/19 r7=40000000/25 r8=60000000/23 r9=70000000/24 r10=80000000/29
There is only one FlexSPI2 region, so the old overlapping 256M READONLY region is gone. The stock 1.62.0 startup.c uses SIZE_32M for 0x70000000 (r9, SIZE field 24); I assume it was raised from 16M to cover two 16 MB PSRAM chips. In the old thread Frank B reported (post #137) that a single FlexSPI2 region larger than 16M still froze. With my 16 MB of PSRAM that leaves 16 MB of cacheable read/write address space with nothing behind it.
I tested both: with SIZE_16M (r9 = 70000000/23) the build ran 6329 s without a stall. With SIZE_32M (the stock value) the same sketch object (only the core was recompiled) has passed the 1886 s mark so far without a stall; that run is still going. So I cannot show that the region size is the cause. I will update this post when the 103 minute mark has passed.
Questions
- Is there any known mechanism, other than the old FlexSPI2 MPU issue, that can block the M7 for exactly 2^30 CPU cycles (2^28 IPG cycles)? Is there a hardware timeout of that length (FlexSPI AHB, AIPS, OCRAM, SEMC, PXP)?
- Why does the stall depend on code layout? Could it be code or data alignment against cache lines, flash/ITCM placement, or something in the FlexSPI1 (QSPI flash) read path while the CPU executes from flash?
- Which registers would be worth dumping right after a stall to identify the blocked bus? I can add that to the logger; it is reproducible within about 30 minutes in an affected build
- Is there a recommended way to move the receive buffer out of DMAMEM/RAM2 (for example into TCM) just for testing, to see whether the stall follows the RAM2 accesses?
I can supply the full diagnostic log files (one row every 5 s, with the raw bad frames) and the sketch. It is large, so I have no minimal sketch yet, but the behaviour is reproducible per binary at the same uptime.
Thanks!