1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-07-23 15:08:19 +00:00

feat(core/prodtest): improve pm-suspend command

[no changelog]
This commit is contained in:
cepetr 2025-06-19 10:22:59 +02:00 committed by cepetr
parent efa64647f4
commit 4672745a5b
4 changed files with 55 additions and 13 deletions

View File

@ -833,19 +833,30 @@ OK
Enters low-power mode. Enters low-power mode.
In low-power mode, the CPU retains its state, including SRAM content. 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 [<wakeup-time>]
```
The command returns OK followed by a list of wake-up reasons, separated
by spaces.
Example: Example:
``` ```
pm-suspend pm-suspend
# Suspending the device to low-power mode... # Suspending the device to low-power mode...
# Press the POWER button to resume. # Press a button button to resume.
.... ....
# Resumed to active mode. # Resumed to active mode.
OK OK BUTTON
``` ```
### pm-hibernate ### pm-hibernate

View File

@ -19,17 +19,18 @@
#ifdef USE_POWER_MANAGER #ifdef USE_POWER_MANAGER
#include <trezor_rtl.h>
#include <stdlib.h>
#include <rtl/cli.h> #include <rtl/cli.h>
#include <rtl/mini_printf.h> #include <rtl/mini_printf.h>
#include <rtl/unit_test.h> #include <rtl/unit_test.h>
#include <rust_ui_prodtest.h> #include <rust_ui_prodtest.h>
#include <sys/power_manager.h> #include <sys/power_manager.h>
#include <sys/rtc.h>
#include <sys/systick.h> #include <sys/systick.h>
#include <trezor_rtl.h>
#include <stdlib.h>
#include "prodtest.h" #include "prodtest.h"
void prodtest_pm_hibernate(cli_t* cli) { 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, "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); systick_delay_ms(1000);
pm_suspend(NULL); wakeup_flags_t wakeup_flags = 0;
pm_suspend(&wakeup_flags);
systick_delay_ms(1500); systick_delay_ms(1500);
cli_trace(cli, "Resumed to active mode."); 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) { void prodtest_pm_charge_disable(cli_t* cli) {
@ -387,7 +416,7 @@ PRODTEST_CLI_CMD(
.name = "pm-suspend", .name = "pm-suspend",
.func = prodtest_pm_suspend, .func = prodtest_pm_suspend,
.info = "Suspend the device to low-power mode", .info = "Suspend the device to low-power mode",
.args = "" .args = "[<wakeup-time>]"
); );
PRODTEST_CLI_CMD( PRODTEST_CLI_CMD(

View File

@ -21,6 +21,8 @@
#include <trezor_types.h> #include <trezor_types.h>
#include <sys/suspend.h>
/* power manager status codes */ /* power manager status codes */
typedef enum { typedef enum {
PM_OK = 0, PM_OK = 0,

View File

@ -242,7 +242,7 @@ pm_status_t pm_suspend(wakeup_flags_t* wakeup_reason) {
wakeup_flags_t wakeup_flags = system_suspend(); wakeup_flags_t wakeup_flags = system_suspend();
// TODO: Handle wake-up flags // TODO: Handle wake-up flags
UNUSED(wakeup_flags); // UNUSED(wakeup_flags);
// Exit hibernation state if it was requested // Exit hibernation state if it was requested
irq_key = irq_lock(); irq_key = irq_lock();