Re: [Fire with UIFlow2](/topic/6685/fire```
code_text
# /flash/mem_fire_check.py
# check_psram_status.py - M5Stack Fire PSRAM Detection Script
import gc
import os
import sys
import machine
def check_psram_status():
print("M5Stack Fire PSRAM Detection Status")
print("=" * 50)
# 1. System information
print("1. System Information:")
print(f" - MicroPython version : {sys.implementation.version}")
print(f" - Platform : {sys.platform}")
print(f" - Machine : {os.uname().machine}")
# 2. Official esp32 PSRAM API check
print("\n2. Official PSRAM API Check:")
try:
import esp32
if hasattr(esp32, 'PSRAM'):
size = esp32.PSRAM.size()
print(f" esp32.PSRAM available: {size:,} bytes "
f"({size / 1024 / 1024:.1f} MB)")
else:
print(" esp32.PSRAM attribute NOT found")
except Exception as e:
print(f" Failed to access esp32.PSRAM โ {e}")
# 3. Current heap status
print("\n3. Heap Memory Status:")
gc.collect()
total_heap = gc.mem_alloc() + gc.mem_free()
print(f" - Total heap : {total_heap:,} bytes ({total_heap / 1024 / 1024:.2f} MB)")
print(f" - Allocated : {gc.mem_alloc():,} bytes")
print(f" - Free : {gc.mem_free():,} bytes")
# 4. PSRAM allocation stress test
print("\n4. PSRAM Allocation Test (512KB chunks):")
test_psram_allocation()
print("=" * 50)
def test_psram_allocation():
gc.collect()
start_free = gc.mem_free()
buffers = []
chunk_size = 512 * 1024 # 512KB
try:
for i in range(1, 17): # Try up to ~8MB
buf = bytearray(chunk_size)
buffers.append(buf)
allocated = len(buffers) * chunk_size
current_free = gc.mem_free()
print(f" {allocated / 1024 / 1024:.1f} MB allocated โ "
f"{current_free / 1024 / 1024:.2f} MB free")
# If free memory drops too fast โ we're NOT using PSRAM
if start_free - current_free > (start_free * 0.8):
print(" Sudden heap drop detected โ Running WITHOUT PSRAM")
break
except MemoryError:
print(f" MemoryError at {allocated / 1024 / 1024:.1f} MB โ "
"PSRAM is NOT enabled in firmware")
except Exception as e:
print(f" Unexpected error: {e}")
finally:
del buffers[:]
gc.collect()
print(f" Cleanup complete โ Free memory: "
f"{gc.mem_free() / 1024 / 1024:.2f} MB")
def check_firmware_psram_support():
print("\n5. Firmware PSRAM Support Summary:")
print(" Testing different detection methods...")
results = []
# Method 1: esp32.PSRAM
try:
import esp32
if hasattr(esp32, 'PSRAM') and esp32.PSRAM.size() > 0:
results.append("esp32.PSRAM API โ Supported "
f"({esp32.PSRAM.size() / 1024 / 1024:.1f} MB)")
else:
results.append("esp32.PSRAM API โ Not available")
except:
results.append("esp32.PSRAM API โ Failed to import")
# Method 2: Large allocation test
gc.collect()
try:
_ = bytearray(6 * 1024 * 1024) # 6MB
results.append("Large allocation (6MB+) โ SUCCESS (PSRAM likely enabled)")
del _
except MemoryError:
results.append("Large allocation (6MB+) โ FAILED (NO PSRAM)")
gc.collect()
# Final verdict
for r in results:
print(f" โข {r}")
print("\n Verdict:")
if any("SUCCESS" in r or "Supported" in r for r in results):
print(" PSRAM is ENABLED and working!")
else:
print(" PSRAM is DISABLED โ Flash a PSRAM-enabled firmware!")
# Main execution
if __name__ == "__main__":
check_psram_status()
check_firmware_psram_support()
------------- Result =============
MicroPython v1.25.0-dirty on 2025-10-24; M5STACK Fire with ESP32(SPIRAM)
Type "help()" for more information.
>>>
>>>
>>> import check_psram_status as pp
>>> pp.check_psram_status
<function check_psram_status at 0x3f8034c0>
>>> pp.check_psram_status()
M5Stack Fire PSRAM Detection Status
==================================================
1. System Information:
- MicroPython version : (1, 25, 0, '')
- Platform : esp32
- Machine : M5STACK Fire with ESP32(SPIRAM)
2. Official PSRAM API Check:
esp32.PSRAM attribute NOT found
3. Heap Memory Status:
- Total heap : 4,184,768 bytes (3.99 MB)
- Allocated : 7,856 bytes
- Free : 4,176,864 bytes
4. PSRAM Allocation Test (512KB chunks):
0.5 MB allocated โ 3.42 MB free
1.0 MB allocated โ 2.91 MB free
1.5 MB allocated โ 2.40 MB free
2.0 MB allocated โ 1.90 MB free
2.5 MB allocated โ 1.46 MB free
3.0 MB allocated โ 0.96 MB free
3.5 MB allocated โ 0.46 MB free
Sudden heap drop detected โ Running WITHOUT PSRAM
Cleanup complete โ Free memory: 3.44 MB
==================================================
>>>