Skip to content

Commit 16c11e7

Browse files
fri3d_2026: workaround Fri3dCamp/badge_2026_fw/issues/3
Ignore the sporadic wrong version numer (0, 255, 15). This risks not updating the firmware when it should be updated, or not installing the firmware when it should be installed (if it also happens on empty CH32 chips). Perhaps resetting the board and trying again would avoid those risks, but auto resets, especially when the root cause isn't understood, come with their own risks. They might trigger a reset loop, if the issue keeps occurring. And they obfuscate the problem.
1 parent 7da32d9 commit 16c11e7

2 files changed

Lines changed: 49 additions & 24 deletions

File tree

internal_filesystem/lib/drivers/fri3d/expander.py

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,9 @@ def install_firmware_if_needed(
131131
latest_version: tuple[int, int, int],
132132
progress_cb=None,
133133
success_cb=None,
134-
) -> bool:
134+
warning_cb=None,
135+
failure_cb=None
136+
) -> bool: # Returns True if expander_i2c needs to be re-initialized
135137
# Check expander firmware version and if none or too low: install latest
136138
try:
137139
time.sleep_ms(10) # desparate attempt to try avoid sporadic version misreads like (0, 255, 15) maybe Fri3dCamp/badge_2026_fw/issues/2
@@ -140,21 +142,26 @@ def install_firmware_if_needed(
140142
except Exception as e:
141143
print("Could not check CH32 firmware version, assuming 0.0.0")
142144
current_version = (0, 0, 0)
143-
if latest_version > current_version:
144-
print(f"CH32 firmware is lower than latest {latest_version} so updating...")
145-
try:
146-
self.install_firmware(filename, progress_cb)
147-
if success_cb:
148-
success_cb()
149-
except Exception as e:
150-
print(f"CH32 firmware install got exception: {e}")
151-
import sys
152-
sys.print_exception(e)
153-
return False
154-
try:
155-
current_version = self.version
156-
print(f"After install, current_version of CH32 firmware: {current_version}")
157-
except Exception as e:
158-
print("Could not check CH32 firmware version after install, many things, including LCD RESET, won't work!")
159-
return True
160-
return False
145+
if current_version == (0, 255, 15): # basically 00FFF0
146+
if warning_cb:
147+
warning_cb("CH32 firmware version (0,255,15) bug - assuming latest version!")
148+
return False
149+
if latest_version <= current_version:
150+
print(f"CH32 firmware {latest_version} <= {current_version} so not updating it")
151+
return False
152+
print(f"CH32 firmware {latest_version} > {current_version} so updating it")
153+
try:
154+
self.install_firmware(filename, progress_cb)
155+
if success_cb:
156+
success_cb()
157+
except Exception as e:
158+
if failure_cb:
159+
failure_cb(e)
160+
return True # re-initialize expander_i2c, even if the install failed, just in case
161+
print("Firmware installed, checking new version")
162+
try:
163+
current_version = self.version
164+
print(f"After install, new current_version of CH32 firmware: {current_version}")
165+
except Exception as e:
166+
print("Could not check CH32 firmware version after install, many things, including LCD RESET, won't work!")
167+
return True

internal_filesystem/lib/mpos/board/fri3d_2026.py

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
LightsManager.init(neopixel_pin=12)
7171
LightsManager.set_led_num(5)
7272
# Set left LED red
73-
LightsManager.set_led(4, 255, 0, 0)
73+
LightsManager.set_led(4, 21, 96, 67)
7474
LightsManager.write()
7575

7676
# Avoid excessive prints here because it slows down if the serial connects during printing?!
@@ -85,15 +85,32 @@ def progress(msg, pct):
8585
LightsManager.set_led(lednr, *color)
8686
LightsManager.write()
8787

88+
def warning(msg):
89+
LightsManager.set_led(3, 96, 58, 21)
90+
LightsManager.write()
91+
time.sleep(2)
92+
if msg:
93+
print(msg)
94+
95+
def failure(e):
96+
LightsManager.set_led(2, 96, 21, 21)
97+
LightsManager.write()
98+
time.sleep(5)
99+
if e:
100+
print(f"CH32 firmware install failed because exception: {e}")
101+
import sys
102+
sys.print_exception(e)
103+
88104
# CH32 coprocessor / IO expander
89105
from drivers.fri3d.expander import Expander
90106
expander_i2c = I2C(1, sda=Pin(39), scl=Pin(42), freq=400000)
91107
expander = Expander(i2c_bus=expander_i2c)
92-
expander.wait_for_normal_mode(min_uptime_ms=1500) # 1000 should be enough but gets version (0, 255, 15) every so often...
108+
expander.wait_for_normal_mode(min_uptime_ms=1000)
93109
if expander.install_firmware_if_needed(
94110
"/builtin/firmware/fri3d_2026/coprocessor_1.2.1.fw", (1, 2, 1), progress_cb=progress,
95-
success_cb=lambda: (LightsManager.set_all(0, 255, 0), LightsManager.write())):
96-
print("Firmware was installed, re-initializing expander_i2c")
111+
success_cb=lambda: (LightsManager.set_all(21, 96, 67), LightsManager.write()),
112+
warning_cb=warning, failure_cb=failure):
113+
print("Re-initializing expander_i2c")
97114
expander_i2c = I2C(1, sda=Pin(39), scl=Pin(42), freq=400000)
98115
expander = Expander(i2c_bus=expander_i2c)
99116

@@ -356,8 +373,9 @@ def startup_wow_effect():
356373
time.sleep_ms(500)
357374

358375
fade_steps = 80
376+
max_brightness = 128 # instead of 255 because that's too bright
359377
for step in range(fade_steps):
360-
level = int(255 * (fade_steps - 1 - step) / (fade_steps - 1))
378+
level = int(max_brightness * (fade_steps - 1 - step) / (fade_steps - 1))
361379
LightsManager.set_all(level, level, level)
362380
LightsManager.write()
363381
time.sleep_ms(20)

0 commit comments

Comments
 (0)