Skip to content

[Deferred] VGM battery-only update resets BQ27220 gauge state #131

Description

@squazaryu

Status

Deferred from the 089-038 stable release. The release baseline is the accepted t-dev-089-038-003 commit (66466151d); all later VGM/gauge recovery experiments are excluded.

Upstream context: DarkFlippers/unleashed-firmware#961 and draft PR DarkFlippers/unleashed-firmware#1041.

Confirmed behavior

Updating official VGM firmware with Video Game Module Tool while Flipper is powered only by its battery can leave the BQ27220 fuel gauge in INITCOMP=0.

Telemetry remains readable, but furi_hal_power_gauge_is_ok() reports the gauge as unavailable, so Desktop displays -. Rebooting runs the existing bq27220_init() reset/provisioning path and restores INITCOMP=1, but can replace accumulated SOC with an OCV-based estimate.

Hardware evidence

Battery-only VGM update

Before update:

charge.level:              98
capacity.remain:           2047 mAh
capacity.full:             2100 mAh
battery.voltage:           ~4075 mV
gauge.initcomp:            1

Immediately after the official VGM update, before reboot:

Desktop:                   -
charge.level:              98
capacity.remain:           2047 mAh
capacity.full:             2100 mAh
gauge.initcomp:            0
gauge.battpres:            1

After an ordinary reboot:

charge.level:              100
capacity.remain:           2100 mAh
capacity.full:             2100 mAh
battery.voltage:           ~4079 mV
gauge.initcomp:            1

A separate recovery experiment reproduced 97% -> 100%. Another near-full run produced 98% -> 98%, proving that the post-reset result is an OCV estimate rather than a deterministic forced 100%.

USB-powered VGM update

Before update, on the Video Game Module Updated screen, and after exiting the tool:

gauge.initcomp:            1
gauge.cfgupdate:           0
gauge.ocvfail:             0
charge.level:              100
capacity.remain/full:      2100/2100 mAh
battery.voltage:           4079 mV

No gauge-state loss occurred.

Negative control

Opening and closing Video Game Module Tool without flashing did not clear INITCOMP.

Current conclusion

The trigger is specific to the battery-only VGM flashing path. A simple app lifecycle or SWD probe/reset is insufficient. The strongest unproven hypothesis is a power-path/load disturbance while erasing/programming the RP2040 from the Flipper battery.

A generic runtime full reset of BQ27220 is not an acceptable fix: it removes the dash but can lose accumulated SOC and learned state.

Safe workaround

Until the root cause is fixed:

  • update VGM firmware only while Flipper itself is connected to USB;
  • do not run automatic BQ27220 full reset after VGM Tool exits;
  • if a dash appears, capture info power and info power_debug before reboot;
  • reboot restores the gauge but the resulting percentage must be treated as re-estimated.

Candidate future fix

Patch Video Game Module Tool rather than the generic power service:

  1. Detect whether Flipper has USB/VBUS before VGM flashing.
  2. On battery, request and verify 5 V OTG for the VGM power path, preserving the previous OTG state.
  3. If stable OTG cannot be established, abort with a clear Connect USB message.
  4. Validate with battery-only full VGM flashing while capturing INITCOMP, RM/FCC, voltage, and SOC before and after.
  5. Only after preserving gauge state, run a controlled BQ27220 learning cycle.

Acceptance criteria

  • Battery-only VGM update does not clear INITCOMP.
  • No Desktop dash after leaving VGM Tool.
  • RM/FCC/SOC continuity is preserved without gauge reset.
  • USB-powered VGM update remains unchanged.
  • Opening/closing VGM Tool without flashing remains harmless.
  • No full BQ27220 reset is introduced as runtime recovery.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingchannel:devDevelopment branch work: experimental features, architecture, and beta validationfirmware-architectureDeep firmware architecture work

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions