From 4672745a5b53d03f3b6e18d584ec4e5f43149f0c Mon Sep 17 00:00:00 2001 From: cepetr Date: Thu, 19 Jun 2025 10:22:59 +0200 Subject: [PATCH] feat(core/prodtest): improve pm-suspend command [no changelog] --- core/embed/projects/prodtest/README.md | 19 ++++++-- .../prodtest/cmd/prodtest_power_manager.c | 45 +++++++++++++++---- .../sys/power_manager/inc/sys/power_manager.h | 2 + .../sys/power_manager/stm32u5/power_manager.c | 2 +- 4 files changed, 55 insertions(+), 13 deletions(-) diff --git a/core/embed/projects/prodtest/README.md b/core/embed/projects/prodtest/README.md index d3c4929b9b..35b65cc9ff 100644 --- a/core/embed/projects/prodtest/README.md +++ b/core/embed/projects/prodtest/README.md @@ -833,19 +833,30 @@ OK Enters low-power mode. In low-power mode, the CPU retains its state, including SRAM content. -The device can be woken by pressing the power button and will continue -operation from the point where it was suspended. + +The following wake-up reasons are currently possible: +- BUTTON - the power button was pressed +- POWER - USB or WPC power was detected +- BLE - BLE communication was detected +- RTC - the RTC wake-up timer expired + +``` +pm-suspend [] +``` + +The command returns OK followed by a list of wake-up reasons, separated +by spaces. Example: ``` pm-suspend # Suspending the device to low-power mode... -# Press the POWER button to resume. +# Press a button button to resume. .... # Resumed to active mode. -OK +OK BUTTON ``` ### pm-hibernate diff --git a/core/embed/projects/prodtest/cmd/prodtest_power_manager.c b/core/embed/projects/prodtest/cmd/prodtest_power_manager.c index f814b469d2..93edcf0c00 100644 --- a/core/embed/projects/prodtest/cmd/prodtest_power_manager.c +++ b/core/embed/projects/prodtest/cmd/prodtest_power_manager.c @@ -19,17 +19,18 @@ #ifdef USE_POWER_MANAGER +#include + +#include + #include #include #include #include #include +#include #include -#include - -#include - #include "prodtest.h" void prodtest_pm_hibernate(cli_t* cli) { @@ -62,15 +63,43 @@ void prodtest_pm_suspend(cli_t* cli) { } cli_trace(cli, "Suspending the device to low-power mode..."); - cli_trace(cli, "Press the POWER button to resume."); + cli_trace(cli, "Press a button to resume."); systick_delay_ms(1000); - pm_suspend(NULL); + wakeup_flags_t wakeup_flags = 0; + + pm_suspend(&wakeup_flags); systick_delay_ms(1500); cli_trace(cli, "Resumed to active mode."); - cli_ok(cli, ""); + char flags_str[128] = ""; + + if (wakeup_flags & WAKEUP_FLAG_BUTTON) { + strcat(flags_str, "BUTTON "); + } + + if (wakeup_flags & WAKEUP_FLAG_POWER) { + strcat(flags_str, "POWER "); + } + + if (wakeup_flags & WAKEUP_FLAG_BLE) { + strcat(flags_str, "BLE "); + } + + if (wakeup_flags & WAKEUP_FLAG_NFC) { + strcat(flags_str, "NFC "); + } + + if (wakeup_flags & WAKEUP_FLAG_RTC) { + strcat(flags_str, "RTC "); + } + + if (wakeup_flags == 0) { + cli_trace(cli, "Woken up by unknown reason."); + } + + cli_ok(cli, "%s", flags_str); } void prodtest_pm_charge_disable(cli_t* cli) { @@ -387,7 +416,7 @@ PRODTEST_CLI_CMD( .name = "pm-suspend", .func = prodtest_pm_suspend, .info = "Suspend the device to low-power mode", - .args = "" + .args = "[]" ); PRODTEST_CLI_CMD( 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 a075bfe228..98a7950e4f 100644 --- a/core/embed/sys/power_manager/inc/sys/power_manager.h +++ b/core/embed/sys/power_manager/inc/sys/power_manager.h @@ -21,6 +21,8 @@ #include +#include + /* power manager status codes */ typedef enum { PM_OK = 0, diff --git a/core/embed/sys/power_manager/stm32u5/power_manager.c b/core/embed/sys/power_manager/stm32u5/power_manager.c index dc91c5ee3f..40bf21135d 100644 --- a/core/embed/sys/power_manager/stm32u5/power_manager.c +++ b/core/embed/sys/power_manager/stm32u5/power_manager.c @@ -242,7 +242,7 @@ pm_status_t pm_suspend(wakeup_flags_t* wakeup_reason) { wakeup_flags_t wakeup_flags = system_suspend(); // TODO: Handle wake-up flags - UNUSED(wakeup_flags); + // UNUSED(wakeup_flags); // Exit hibernation state if it was requested irq_key = irq_lock();