Skip to content

Commit 1c91ff4

Browse files
authored
Handle "mpos.main" errors and wait for 5 seconds (#109)
On a new, unsupported device, you may get a reboot loop. Because if the "mpos.main" can't detect the board it just continues and tries to init the display. In by case (on a CYD) it results in a hard crash -> a boot loop. This loop is short and avoids to be able to use "mpremote cp"... It looks like: ``` ... sys.version=3.4.0; LVGL (9.3.0) MicroPython (1.25.0) Binding compiled on 2026-04-01 sys.implementation=(name='micropython', version=(1, 25, 0, ''), _machine='Generic ESP32 module with SPIRAM with ESP32', _mpy=11014, _build='ESP32_GENERIC-SPIRAM') Free space on root filesystem: total_space=0 / used_space=0 / free_space=0 bytes RAM: 110656 free, 640 allocated, 111296 total Passing execution over to mpos.main MicroPythonOS 0.9.0 running lib/mpos/main.py unPhone ? odroid_go ? m5stack_core2 ? Try to I2C initialized on sda=21 scl=22 fail_save_i2c ok Attempt to write a single byte to I2C bus address 0x34... No device at this address: [Errno 116] ETIMEDOUT m5stack_fire ? Try to I2C initialized on sda=21 scl=22 fail_save_i2c ok Attempt to write a single byte to I2C bus address 0x68... No device at this address: [Errno 116] ETIMEDOUT Unknown board: couldn't detect known I2C devices or unique_id prefix A fatal error occurred. The crash dump printed below may be used to help determine what caused it. If you are not already running the most recent version of MicroPython, consider upgrading. New versions often fix bugs. To learn more about how to debug and/or report this crash visit the wiki page at: https://github.com/micropython/micropython/wiki/ESP32-debugging LVGL MicroPython IDF version : 67c1de1e Machine : Generic ESP32 module with SPIRAM with ESP32 Guru Meditation Error: Core 1 panic'ed (LoadProhibited). Exception was unhandled. ... ``` The interesting line is `Unknown board: couldn't detect known I2C devices or unique_id prefix` so that `detect_board()` returns `None` but the code just continues. This PR will raise and error, that will be captured in the `main.py` and we end in the REPL. This looks like: ``` ... sys.version=3.4.0; LVGL (9.3.0) MicroPython (1.25.0) Binding compiled on 2026-04-01 sys.implementation=(name='micropython', version=(1, 25, 0, ''), _machine='Generic ESP32 module with SPIRAM with ESP32', _mpy=11014, _build='ESP32_GENERIC-SPIRAM') Free space on root filesystem: total_space=0 / used_space=0 / free_space=0 bytes RAM: 110656 free, 640 allocated, 111296 total Passing execution over to mpos.main MicroPythonOS 0.9.0 running lib/mpos/main.py unPhone ? odroid_go ? m5stack_core2 ? Try to I2C initialized on sda=21 scl=22 fail_save_i2c ok Attempt to write a single byte to I2C bus address 0x34... No device at this address: [Errno 116] ETIMEDOUT m5stack_fire ? Try to I2C initialized on sda=21 scl=22 fail_save_i2c ok Attempt to write a single byte to I2C bus address 0x68... No device at this address: [Errno 116] ETIMEDOUT Unknown board: couldn't detect known I2C devices or unique_id prefix Traceback (most recent call last): File "main.py", line 32, in <module> File "mpos/main.py", line 253, in <module> RuntimeError: No board detected, exit initialization! Error in mpos.main, sleep for 5 seconds and end then... LVGL (9.3.0) MicroPython (1.25.0) Binding compiled on 2026-04-01; Generic ESP32 module with SPIRAM with ESP32 Type "help()" for more information. >>> ```
1 parent 70c3b87 commit 1c91ff4

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

internal_filesystem/lib/mpos/main.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,9 @@ def detect_board():
247247
print(f"Detected {board} system, importing mpos.board.{board}")
248248
DeviceInfo.set_hardware_id(board)
249249
__import__(f"mpos.board.{board}")
250+
else:
251+
# It makes no sense to continue, because we have no display etc...
252+
raise RuntimeError("No board detected, exit initialization!")
250253

251254
# Allow LVGL M:/path/to/file or M:relative/path/to/file to work for image set_src etc
252255
import mpos.fs_driver

internal_filesystem/main.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,11 @@
2828
)
2929

3030
print("Passing execution over to mpos.main")
31-
import mpos.main # noqa: F401
31+
try:
32+
import mpos.main # noqa: F401
33+
except Exception as e:
34+
sys.print_exception(e)
35+
import time
36+
print(f"Error in mpos.main, sleep for 5 seconds and end then...")
37+
time.sleep(5)
38+

0 commit comments

Comments
 (0)