feat(core): add pm_is_charging function to power manager api.
What changed, and why it matters
This commit adds a new helper function that reports whether the Trezor device is currently charging. It also refactors one existing suspend/resume check to use that helper. There is no indication of a security bug being fixed; it appears to be a routine feature/refactoring change.
No security action required. Treat as normal firmware development.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch introduces pm_is_charging() to the power-manager API and implements it on STM32U5 by checking driver state: charging enabled, not fully charged, SOC target not reached, and a USB or wireless power source connected. It adds a fully_charged field to the internal driver state and sets it based on the PMIC charge-status bit. The only consumer change is in system_suspend(), which now uses pm_is_charging() instead of directly inspecting pm_state.usb_connected || pm_state.wireless_connected to decide whether to show the charging LED effect.
Changed components
core/embed/sys/power_manager (STM32U5 power manager)core/embed/sys/suspend (STM32U5 suspend)Inspect captured patch +33 / −5
diff --git a/core/embed/sys/power_manager/inc/sys/power_manager.h b/core/embed/sys/power_manager/inc/sys/power_manager.h
index 25af1ccc3..d81e5c96c 100644
--- a/core/embed/sys/power_manager/inc/sys/power_manager.h
+++ b/core/embed/sys/power_manager/inc/sys/power_manager.h
@@ -209,6 +209,13 @@ pm_status_t pm_charging_set_max_current(uint16_t current_ma);
*/
pm_status_t pm_set_soc_target(uint8_t target);
+/**
+ * @brief Check if the device is currently charging the battery
+ *
+ * @return true if the device is charging, false otherwise
+ */
+bool pm_is_charging(void);
+
/**
* @brief Suspends driver activity so the CPU can enter low-power mode.
*
diff --git a/core/embed/sys/power_manager/stm32u5/power_manager.c b/core/embed/sys/power_manager/stm32u5/power_manager.c
index 5eb077468..4176dcfb7 100644
--- a/core/embed/sys/power_manager/stm32u5/power_manager.c
+++ b/core/embed/sys/power_manager/stm32u5/power_manager.c
@@ -628,6 +628,26 @@ bool pm_schedule_rtc_wakeup(void) {
return true;
}
+bool pm_is_charging(void) {
+ pm_driver_t* drv = &g_pm;
+
+ if (!drv->initialized) {
+ return false;
+ }
+
+ bool is_charging = false;
+
+ irq_key_t irq_key = irq_lock();
+ if (drv->charging_enabled &&
+ (!drv->fully_charged && !drv->soc_target_reached) &&
+ (drv->usb_connected || drv->wireless_connected)) {
+ is_charging = true;
+ }
+ irq_unlock(irq_key);
+
+ return is_charging;
+}
+
bool pm_driver_resume(void) {
pm_driver_t* drv = &g_pm;
diff --git a/core/embed/sys/power_manager/stm32u5/power_manager_internal.h b/core/embed/sys/power_manager/stm32u5/power_manager_internal.h
index 8a27e0bd9..c3057f19c 100644
--- a/core/embed/sys/power_manager/stm32u5/power_manager_internal.h
+++ b/core/embed/sys/power_manager/stm32u5/power_manager_internal.h
@@ -117,6 +117,7 @@ typedef struct {
// Power source logical state
bool usb_connected;
bool wireless_connected;
+ bool fully_charged;
bool battery_low;
bool battery_critical;
diff --git a/core/embed/sys/power_manager/stm32u5/power_monitoring.c b/core/embed/sys/power_manager/stm32u5/power_monitoring.c
index 5af15b51e..2c3bfb176 100644
--- a/core/embed/sys/power_manager/stm32u5/power_monitoring.c
+++ b/core/embed/sys/power_manager/stm32u5/power_monitoring.c
@@ -120,10 +120,13 @@ void pm_pmic_data_ready(void* context, pmic_report_t* report) {
drv->pmic_data.ntc_temp);
}
- // Charging completed
+ // Charging completed flag from PMIC controller
if (drv->pmic_data.charge_status & 0x2) {
// Force fuel gauge to 100%, keep the covariance
+ drv->fully_charged = true;
fuel_gauge_set_soc(&drv->fuel_gauge, 1.0f, drv->fuel_gauge.P);
+ } else {
+ drv->fully_charged = false;
}
// Ceil the float soc to user-friendly integer
diff --git a/core/embed/sys/suspend/stm32u5/suspend.c b/core/embed/sys/suspend/stm32u5/suspend.c
index b29b40726..f5492c4cb 100644
--- a/core/embed/sys/suspend/stm32u5/suspend.c
+++ b/core/embed/sys/suspend/stm32u5/suspend.c
@@ -76,10 +76,7 @@ wakeup_flags_t system_suspend(void) {
// device is woke up. This state is signaled with RGB LED charging effect
bool charging_in_suspend;
do {
- pm_state_t pm_state;
- pm_get_state(&pm_state);
-
- if (pm_state.usb_connected || pm_state.wireless_connected) {
+ if (pm_is_charging()) {
charging_in_suspend = true;
#ifdef USE_RGB_LED
Why this scored 13/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.