1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-07-31 02:48:44 +00:00

feat(core) add prodtest precharge test [no changelog]

This commit is contained in:
kopecdav 2025-05-09 14:03:31 +02:00 committed by kopecdav
parent 46272a854e
commit 0e228caac1

View File

@ -322,6 +322,72 @@ void prodtest_pm_event_monitor(cli_t* cli) {
cli_ok(cli, "");
}
void prodtest_pm_precharge(cli_t* cli) {
if (cli_arg_count(cli) > 0) {
cli_error_arg_count(cli);
return;
}
// This test consider that the device is connected with USB and placed in
// ambient temperature. Battery will be charged with constanst current
// and precharge voltage is statically taken from the battery chaging curve
//
// It is expected that battery voltage during the charging is being lifted
// due to effect of internal resistance of the battery. So battery voltage
// will drop a bit after the charging is stopped.
// voltage while charging is being lifted due to charging with quite high charging
// current. When the test terminate by reaching the given woltage. The current
// and
float precharge_voltage_V = 3.45f;
pm_charging_enable();
cli_trace(cli, "Precharging the device...");
while(true){
pm_report_t report;
pm_status_t status = pm_get_report(&report);
if (status != PM_OK) {
cli_error(cli, CLI_ERROR, "Failed to get power manager report");
return;
}
if (report.usb_connected == false) {
cli_error(cli, CLI_ERROR, "USB power source is not connected");
return;
}
cli_trace(cli, "Battery voltage: %d.%03d V -> taret %d.%03d V",
(int)report.battery_voltage_v,
(int)(report.battery_voltage_v * 1000) % 1000,
(int)precharge_voltage_V,
(int)(precharge_voltage_V * 1000) % 1000);
cli_progress(cli,"%d.%03d %d.%03d",
(int)report.battery_voltage_v,
(int)(report.battery_voltage_v * 1000) % 1000,
(int)precharge_voltage_V,
(int)(precharge_voltage_V * 1000) % 1000);
if (cli_aborted(cli)) {
cli_trace(cli, "aborted");
break;
}
// Check if the battery voltage is above the precharge voltag
if(report.battery_voltage_v >= precharge_voltage_V){
// Target achieved
cli_trace(cli, "Battery voltage reached the target voltage.");
break;
}
}
cli_ok(cli, "");
}
// clang-format off
PRODTEST_CLI_CMD(
@ -373,4 +439,11 @@ PRODTEST_CLI_CMD(
.args = ""
);
PRODTEST_CLI_CMD(
.name = "pm-precharge",
.func = prodtest_pm_precharge,
.info = "Precharge the device to specific voltage",
.args = ""
);
#endif /* USE POWER_MANAGER */