refactor(core): remove auxiliary variable.
What changed, and why it matters
This is a small internal code cleanup in the power-management code for Trezor hardware wallets. It removes a redundant flag (`fuel_gauge_initialized`) and instead asks the battery fuel-gauge subsystem directly whether it is locked/initialized. There is no user-facing change, no obvious security bug being fixed, and no changelog entry.
No security action required. Treat as a normal code-quality refactor. If reviewing, confirm that `bat_fg_is_locked()` returns true in exactly the same conditions the old flag was considered set, to avoid any regression in backup-RAM data persistence.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit refactors the STM32U5 power manager to eliminate the fuel_gauge_initialized boolean in power_manager_internal.h. Initialization in power_manager.c no longer sets this flag; deinit now uses bat_fg_is_locked() to decide whether to save data to backup RAM. The PMIC data-ready callback in power_monitoring.c also switches from checking the removed flag to bat_fg_is_locked(). The behavior appears functionally equivalent because the flag was set unconditionally to true immediately after init, so the only observable difference is the source of truth for the same state.
Changed components
core/embed/io/power_manager/stm32u5/power_manager.ccore/embed/io/power_manager/stm32u5/power_manager_internal.hcore/embed/io/power_manager/stm32u5/power_monitoring.cInspect captured patch +3 / −9
diff --git a/core/embed/io/power_manager/stm32u5/power_manager.c b/core/embed/io/power_manager/stm32u5/power_manager.c
index abe115847..e8b89dea1 100644
--- a/core/embed/io/power_manager/stm32u5/power_manager.c
+++ b/core/embed/io/power_manager/stm32u5/power_manager.c
@@ -164,9 +164,6 @@ pm_status_t pm_init(bool inherit_state) {
drv->i_chg_temp_limit_ma = PM_BATTERY_CHARGING_CURRENT_MAX;
#endif
- // Fuel gauge SoC available, set fuel_gauge initialized.
- drv->fuel_gauge_initialized = true;
-
irq_unlock(irq_key);
// Wait to stabilize the state machine
@@ -196,7 +193,7 @@ void pm_deinit(void) {
drv->shutdown_timer = NULL;
}
- if (drv->fuel_gauge_initialized) {
+ if (bat_fg_is_locked()) {
pm_store_data_to_backup_ram();
}
diff --git a/core/embed/io/power_manager/stm32u5/power_manager_internal.h b/core/embed/io/power_manager/stm32u5/power_manager_internal.h
index 48ce426ca..c12f5868a 100644
--- a/core/embed/io/power_manager/stm32u5/power_manager_internal.h
+++ b/core/embed/io/power_manager/stm32u5/power_manager_internal.h
@@ -70,10 +70,7 @@ typedef struct {
// Set if the driver's background operations are suspended.
bool suspended;
- // Fuel gauge
- bool fuel_gauge_initialized;
uint8_t soc_ceiled;
-
uint8_t soc_target;
bool soc_target_reached;
float target_battery_ocv_v_tau;
diff --git a/core/embed/io/power_manager/stm32u5/power_monitoring.c b/core/embed/io/power_manager/stm32u5/power_monitoring.c
index 125152e62..93a1bc6ca 100644
--- a/core/embed/io/power_manager/stm32u5/power_monitoring.c
+++ b/core/embed/io/power_manager/stm32u5/power_monitoring.c
@@ -92,8 +92,8 @@ void pm_pmic_data_ready(void* context, pmic_report_t* report) {
drv->battery_ocv = bat_meas_to_ocv(drv->pmic_data.vbat, drv->pmic_data.ibat,
drv->pmic_data.ntc_temp);
- if (!drv->fuel_gauge_initialized) {
- // Fuel gauge not initialized yet, battery SoC not available, sample the
+ if (!bat_fg_is_locked()) {
+ // Fuel gauge not locked yet, battery SoC not available, just sample the
// battery data into the circular buffer.
bat_fg_feed_sample(drv->pmic_data.vbat, drv->pmic_data.ibat,
drv->pmic_data.ntc_temp);
Why this scored 12/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.